Improve MCP loading process by verifying directory existence before file operations

- Added a check to confirm the existence of the 'mcps' directory prior to loading MCP files, enhancing error handling and preventing unnecessary attempts to load from a non-existent directory.
- Updated error handling to ensure that any issues encountered during the loading process are logged appropriately.
This commit is contained in:
Max 2025-11-28 19:56:16 +08:00
parent 36e3334058
commit 125c32a0b5

View file

@ -19,9 +19,13 @@ import (
func Load(cfg config.Config) error {
messages := []string{}
// Load filesystem MCP clients
// Check if mcps directory exists
exists, err := application.App.Exists("mcps")
// Load filesystem MCP clients if directory exists
if err == nil && exists {
exts := []string{"*.mcp.yao", "*.mcp.json", "*.mcp.jsonc"}
err := application.App.Walk("mcps", func(root, file string, isdir bool) error {
err = application.App.Walk("mcps", func(root, file string, isdir bool) error {
if isdir {
return nil
}
@ -38,6 +42,7 @@ func Load(cfg config.Config) error {
}
return fmt.Errorf("%s", strings.Join(messages, ";\n"))
}
}
// Load database MCP clients (ignore error)
errs := loadDatabaseMCPs()