feat: Enhance MCP tools registration and management with context support

- Updated RegisterMCPTools and GetMCPToolsInfo functions to accept a context parameter, improving control over timeouts and cancellations.
- Implemented timeout handling for ListTools operations to prevent hanging during long-running requests.
- Enhanced GetFunctionDefinitions to include all MCP tools regardless of the allowed tools list, ensuring comprehensive tool access.
- Improved MCP service management by adding checks for service enabled state and critical configuration changes, ensuring robust client connection handling.
- Refactored session handling to utilize AgentModeEnabled for better session configuration management.
This commit is contained in:
wizardchen
2025-11-11 02:47:38 +08:00
parent 244aaab328
commit 2d9d930824
8 changed files with 101 additions and 25 deletions
@@ -119,7 +119,7 @@ func (s *agentService) CreateAgentEngine(
// Register MCP tools
if len(enabledServices) > 0 {
if err := tools.RegisterMCPTools(toolRegistry, enabledServices, s.mcpManager); err != nil {
if err := tools.RegisterMCPTools(ctx, toolRegistry, enabledServices, s.mcpManager); err != nil {
logger.Warnf(ctx, "Failed to register MCP tools: %v", err)
} else {
logger.Infof(ctx, "Registered MCP tools from %d enabled services", len(enabledServices))