mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-14 20:47:30 +08:00
feat: add MCP tool and web UI management
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user