diff --git a/web/src/components/Chat/ChatLayout.vue b/web/src/components/Chat/ChatLayout.vue index 8bb81ab..e829ec1 100644 --- a/web/src/components/Chat/ChatLayout.vue +++ b/web/src/components/Chat/ChatLayout.vue @@ -114,16 +114,6 @@ - - - - 添加服务器... - - - -
+
- | + | + +
diff --git a/web/src/services/MCPClientService.ts b/web/src/services/MCPClientService.ts index e38d510..bd74b90 100644 --- a/web/src/services/MCPClientService.ts +++ b/web/src/services/MCPClientService.ts @@ -307,12 +307,23 @@ export class MCPClientService { * 获取服务器的工具列表 */ getTools(serverId: string): Tool[] { + console.log('🔍 [MCPClientService.getTools] 请求获取工具:', serverId); + console.log('🔍 [MCPClientService.getTools] 当前连接的服务器:', Array.from(this.clients.keys())); + const serverInfo = this.clients.get(serverId); if (!serverInfo) { - console.warn(`服务器 ${serverId} 未连接`); + console.warn(`❌ [MCPClientService.getTools] 服务器 ${serverId} 未连接`); return []; } - return serverInfo.capabilities?.tools || []; + + console.log('✅ [MCPClientService.getTools] 找到服务器信息'); + console.log('🔍 [MCPClientService.getTools] capabilities:', serverInfo.capabilities); + console.log('🔍 [MCPClientService.getTools] tools:', serverInfo.capabilities?.tools); + + const tools = serverInfo.capabilities?.tools || []; + console.log(`📋 [MCPClientService.getTools] 返回 ${tools.length} 个工具`); + + return tools; } /** diff --git a/web/src/services/chatService.ts b/web/src/services/chatService.ts index 10a8293..f3b7c94 100644 --- a/web/src/services/chatService.ts +++ b/web/src/services/chatService.ts @@ -7,13 +7,13 @@ import type { TopicFilter } from '../types/chat' import { modelServiceManager } from './modelServiceManager' -import { MCPClientService } from './MCPClientService' +import { mcpClientService } from './MCPClientService' class ChatService { private static instance: ChatService private topics: Map = new Map() private conversations: Map = new Map() - private mcpClient: MCPClientService = new MCPClientService() + private mcpClient = mcpClientService // 使用单例实例 static getInstance(): ChatService { if (!ChatService.instance) { @@ -593,8 +593,11 @@ class ChatService { if (mcpServerId) { console.log('🔧 [callModelStream] 获取 MCP 服务器工具:', mcpServerId) const mcpTools = this.mcpClient.getTools(mcpServerId) + console.log('🔧 [callModelStream] MCP 原始工具列表:', mcpTools) tools = this.convertToolsToOpenAIFormat(mcpTools) - console.log('🔧 [callModelStream] 转换后的工具:', tools.length, '个') + console.log('🔧 [callModelStream] 转换后的工具:', tools.length, '个', tools) + } else { + console.log('⚠️ [callModelStream] 未选择 MCP 服务器,不注入工具') } // 准备消息历史