* 连接到单个服务器
(config: MCPConnectionConfig)
| 161 | * 连接到单个服务器 |
| 162 | */ |
| 163 | async connectToServer(config: MCPConnectionConfig): Promise<MCPSession> { |
| 164 | if (!this.client) { |
| 165 | throw new Error('MCP 客户端未初始化'); |
| 166 | } |
| 167 | |
| 168 | this.log(`连接到 MCP 服务器: ${config.name}`); |
| 169 | const session = await this.client.connect(config); |
| 170 | |
| 171 | // 获取服务器资源和工具 |
| 172 | await this.loadServerResources(session.id); |
| 173 | await this.loadServerTools(session.id); |
| 174 | |
| 175 | return session; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * 断开服务器连接 |
no test coverage detected