Refactor MCP client handling for improved categorization and information display
- Updated the `printMCPs` function to enhance the separation of agent and standard MCPs by utilizing the Type field for better clarity. - Improved error handling and client information retrieval, ensuring accurate display of transport types and labels for each MCP. - Modified the MCP loading process to specifically load agent clients, streamlining the management of different client types. - Enhanced output formatting to include tools count only for process transport, improving the readability of MCP information.
This commit is contained in:
parent
cd5b4df503
commit
a50f43a8bb
2 changed files with 58 additions and 15 deletions
71
cmd/start.go
71
cmd/start.go
|
|
@ -514,11 +514,18 @@ func printMCPs(silent bool) {
|
|||
return
|
||||
}
|
||||
|
||||
// Separate agent MCPs from standard MCPs
|
||||
// Separate agent MCPs from standard MCPs by Type field
|
||||
agentClients := []string{}
|
||||
standardClients := []string{}
|
||||
for _, clientID := range clients {
|
||||
if len(clientID) >= 7 && clientID[:7] == "agents." {
|
||||
client, err := mcp.Select(clientID)
|
||||
if err != nil {
|
||||
standardClients = append(standardClients, clientID)
|
||||
continue
|
||||
}
|
||||
|
||||
info := client.Info()
|
||||
if info != nil && info.Type == "agent" {
|
||||
agentClients = append(agentClients, clientID)
|
||||
} else {
|
||||
standardClients = append(standardClients, clientID)
|
||||
|
|
@ -533,20 +540,38 @@ func printMCPs(silent bool) {
|
|||
fmt.Println(color.WhiteString("\n%s (%d)", "Standard MCPs", len(standardClients)))
|
||||
fmt.Println(color.WhiteString("--------------------------"))
|
||||
for _, clientID := range standardClients {
|
||||
mapping, err := mcp.GetClientMapping(clientID)
|
||||
client, err := mcp.Select(clientID)
|
||||
if err != nil {
|
||||
fmt.Print(color.CyanString("[MCP] %s", clientID))
|
||||
fmt.Print(color.WhiteString("\tloaded\n"))
|
||||
continue
|
||||
}
|
||||
|
||||
toolsCount := 0
|
||||
if mapping.Tools != nil {
|
||||
toolsCount = len(mapping.Tools)
|
||||
info := client.Info()
|
||||
transport := "unknown"
|
||||
label := clientID
|
||||
if info != nil {
|
||||
if info.Transport != "" {
|
||||
transport = string(info.Transport)
|
||||
}
|
||||
if info.Label != "" {
|
||||
label = info.Label
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print(color.CyanString("[MCP] %s", clientID))
|
||||
fmt.Print(color.WhiteString("\ttools: %d\n", toolsCount))
|
||||
fmt.Print(color.CyanString("[MCP] %s", label))
|
||||
fmt.Print(color.WhiteString("\t%s\tid: %s", transport, clientID))
|
||||
|
||||
// Only show tools count for process transport
|
||||
if transport == "process" {
|
||||
toolsCount := 0
|
||||
mapping, err := mcp.GetClientMapping(clientID)
|
||||
if err == nil && mapping.Tools != nil {
|
||||
toolsCount = len(mapping.Tools)
|
||||
}
|
||||
fmt.Print(color.WhiteString("\ttools: %d", toolsCount))
|
||||
}
|
||||
fmt.Print("\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -554,20 +579,38 @@ func printMCPs(silent bool) {
|
|||
fmt.Println(color.WhiteString("\n%s (%d)", "Agent MCPs", len(agentClients)))
|
||||
fmt.Println(color.WhiteString("--------------------------"))
|
||||
for _, clientID := range agentClients {
|
||||
mapping, err := mcp.GetClientMapping(clientID)
|
||||
client, err := mcp.Select(clientID)
|
||||
if err != nil {
|
||||
fmt.Print(color.CyanString("[MCP] %s", clientID))
|
||||
fmt.Print(color.WhiteString("\tloaded\n"))
|
||||
continue
|
||||
}
|
||||
|
||||
toolsCount := 0
|
||||
if mapping.Tools != nil {
|
||||
toolsCount = len(mapping.Tools)
|
||||
info := client.Info()
|
||||
transport := "unknown"
|
||||
label := clientID
|
||||
if info != nil {
|
||||
if info.Transport != "" {
|
||||
transport = string(info.Transport)
|
||||
}
|
||||
if info.Label != "" {
|
||||
label = info.Label
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print(color.CyanString("[MCP] %s", clientID))
|
||||
fmt.Print(color.WhiteString("\ttools: %d\n", toolsCount))
|
||||
fmt.Print(color.CyanString("[MCP] %s", label))
|
||||
fmt.Print(color.WhiteString("\t%s\tid: %s", transport, clientID))
|
||||
|
||||
// Only show tools count for process transport
|
||||
if transport == "process" {
|
||||
toolsCount := 0
|
||||
mapping, err := mcp.GetClientMapping(clientID)
|
||||
if err == nil && mapping.Tools != nil {
|
||||
toolsCount = len(mapping.Tools)
|
||||
}
|
||||
fmt.Print(color.WhiteString("\ttools: %d", toolsCount))
|
||||
}
|
||||
fmt.Print("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ func loadAssistantMCPs() []error {
|
|||
|
||||
log.Trace("Loading MCP client %s from file %s", clientID, mcpFile)
|
||||
|
||||
_, err := mcp.LoadClient(mcpFile, clientID)
|
||||
_, err := mcp.LoadClientWithType(mcpFile, clientID, "agent")
|
||||
if err != nil {
|
||||
log.Error("Failed to load MCP client %s from assistant %s: %s", clientID, assistantID, err.Error())
|
||||
errs = append(errs, fmt.Errorf("failed to load MCP client %s: %w", clientID, err))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue