add tips for mcp
This commit is contained in:
parent
4ccea5eb93
commit
084112e8e1
2 changed files with 27 additions and 1 deletions
|
|
@ -63,6 +63,22 @@ func (al *AgentLoop) ensureMCPInitialized(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if al.cfg.Tools.MCP.Servers == nil || len(al.cfg.Tools.MCP.Servers) == 0 {
|
||||||
|
logger.WarnCF("agent", "MCP is enabled but no servers are configured, skipping MCP initialization", nil)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
findValidServer := false
|
||||||
|
for _, serverCfg := range al.cfg.Tools.MCP.Servers {
|
||||||
|
if serverCfg.Enabled {
|
||||||
|
findValidServer = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !findValidServer {
|
||||||
|
logger.WarnCF("agent", "MCP is enabled but no valid servers are configured, skipping MCP initialization", nil)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
al.mcp.initOnce.Do(func() {
|
al.mcp.initOnce.Do(func() {
|
||||||
mcpManager := mcp.NewManager()
|
mcpManager := mcp.NewManager()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -770,13 +770,18 @@ func TestAgentLoop_ContextExhaustionRetry(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessDirectWithChannel_InitializesMCPInAgentMode(t *testing.T) {
|
// TestProcessDirectWithChannel_TriggersMCPInitialization verifies that
|
||||||
|
// ProcessDirectWithChannel triggers MCP initialization when MCP is enabled.
|
||||||
|
// Note: Manager is only initialized when at least one MCP server is configured
|
||||||
|
// and successfully connected.
|
||||||
|
func TestProcessDirectWithChannel_TriggersMCPInitialization(t *testing.T) {
|
||||||
tmpDir, err := os.MkdirTemp("", "agent-test-*")
|
tmpDir, err := os.MkdirTemp("", "agent-test-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create temp dir: %v", err)
|
t.Fatalf("Failed to create temp dir: %v", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
// Test with MCP enabled but no servers - should not initialize manager
|
||||||
cfg := &config.Config{
|
cfg := &config.Config{
|
||||||
Agents: config.AgentsConfig{
|
Agents: config.AgentsConfig{
|
||||||
Defaults: config.AgentDefaults{
|
Defaults: config.AgentDefaults{
|
||||||
|
|
@ -791,6 +796,11 @@ func TestProcessDirectWithChannel_InitializesMCPInAgentMode(t *testing.T) {
|
||||||
ToolConfig: config.ToolConfig{
|
ToolConfig: config.ToolConfig{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
},
|
},
|
||||||
|
Servers: map[string]config.MCPServerConfig{
|
||||||
|
"test-server": {
|
||||||
|
Enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue