(serverConfig: MCPServerConfig)
| 237 | } |
| 238 | |
| 239 | private async connectServer(serverConfig: MCPServerConfig) { |
| 240 | const connection: ServerConnection = { |
| 241 | config: serverConfig, |
| 242 | client: null, |
| 243 | prompts: [], |
| 244 | tools: [], |
| 245 | status: "connecting", |
| 246 | warnings: [], |
| 247 | }; |
| 248 | const serverName = serverConfig.name; |
| 249 | this.connections.set(serverName, connection); |
| 250 | this.updateState(); |
| 251 | |
| 252 | const vars = getTemplateVariables(JSON.stringify(serverConfig)); |
| 253 | const secretVars = vars.filter((v) => v.startsWith("secrets.")); |
| 254 | const unrendered = secretVars.map((v) => { |
| 255 | return decodeFQSN(v.replace("secrets.", "")).secretName; |
| 256 | }); |
| 257 | |
| 258 | try { |
| 259 | if (unrendered.length > 0) { |
| 260 | const message = `${serverConfig.name} MCP Server has unresolved secrets: ${unrendered.join(", ")} |
| 261 | For personal use you can set the secret in the hub at https://continue.dev/settings/secrets or pass it to the CLI environment. |
| 262 | Org-level secrets can only be used for MCP by Background Agents (https://docs.continue.dev/hub/agents/overview) when \"Include in Env\" is enabled for the secret.`; |
| 263 | if (this.isHeadless) { |
| 264 | throw new Error(message); |
| 265 | } else { |
| 266 | connection.warnings.push(message); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | const client = await this.getConnectedClient(serverConfig, connection); |
| 271 | |
| 272 | connection.client = client; |
| 273 | connection.status = "connected"; |
| 274 | this.updateState(); |
| 275 | |
| 276 | const capabilities = client.getServerCapabilities(); |
| 277 | |
| 278 | if (capabilities?.prompts) { |
| 279 | try { |
| 280 | connection.prompts = await this.withTokenRefresh( |
| 281 | serverName, |
| 282 | async () => { |
| 283 | const conn = this.connections.get(serverName); |
| 284 | if (!conn?.client) { |
| 285 | throw new Error(`Client for ${serverName} not available`); |
| 286 | } |
| 287 | return (await conn.client.listPrompts()).prompts; |
| 288 | }, |
| 289 | ); |
| 290 | } catch (error) { |
| 291 | const errorMessage = getErrorString(error); |
| 292 | connection.warnings.push(`Failed to load prompts: ${errorMessage}`); |
| 293 | logger.warn("Failed to load MCP prompts", { |
| 294 | name: serverName, |
| 295 | error: errorMessage, |
| 296 | }); |
no test coverage detected