feat: add MCP tool and web UI management

This commit is contained in:
lpf
2026-03-07 22:09:52 +08:00
parent cff379809c
commit fb5a228e7d
16 changed files with 1836 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"sort"
"strings"
"sync"
"time"
@@ -165,6 +166,15 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers
webFetchTool := tools.NewWebFetchTool(50000)
toolsRegistry.Register(webFetchTool)
toolsRegistry.Register(tools.NewParallelFetchTool(webFetchTool, maxParallelCalls, parallelSafe))
if cfg.Tools.MCP.Enabled {
mcpTool := tools.NewMCPTool(workspace, cfg.Tools.MCP)
toolsRegistry.Register(mcpTool)
discoveryCtx, cancel := context.WithTimeout(context.Background(), time.Duration(cfg.Tools.MCP.RequestTimeoutSec)*time.Second)
for _, remoteTool := range mcpTool.DiscoverTools(discoveryCtx) {
toolsRegistry.Register(remoteTool)
}
cancel()
}
// Register message tool
messageTool := tools.NewMessageTool()
@@ -1680,6 +1690,22 @@ func (al *AgentLoop) GetStartupInfo() map[string]interface{} {
return info
}
func (al *AgentLoop) GetToolCatalog() []map[string]interface{} {
if al == nil || al.tools == nil {
return nil
}
items := al.tools.Catalog()
sort.Slice(items, func(i, j int) bool {
return fmt.Sprint(items[i]["name"]) < fmt.Sprint(items[j]["name"])
})
for _, item := range items {
if fmt.Sprint(item["source"]) != "mcp" {
item["source"] = "local"
}
}
return items
}
// formatMessagesForLog formats messages for logging
func formatMessagesForLog(messages []providers.Message) string {
if len(messages) == 0 {