diff --git a/core/context/mcp/MCPConnection.ts b/core/context/mcp/MCPConnection.ts index afbb4ae99..65749acb3 100644 --- a/core/context/mcp/MCPConnection.ts +++ b/core/context/mcp/MCPConnection.ts @@ -189,6 +189,7 @@ class MCPConnection { ); try { await this.client.connect(transport, {}); + this.transport = transport; } catch (error) { // Allow the case where for whatever reason is already connected if ( @@ -209,14 +210,17 @@ class MCPConnection { if (this.options.type === "sse") { const transport = this.constructSseTransport(this.options); await this.client.connect(transport, {}); + this.transport = transport; } else if (this.options.type === "streamable-http") { const transport = this.constructHttpTransport(this.options); await this.client.connect(transport, {}); + this.transport = transport; } else if (this.options.type === "websocket") { const transport = this.constructWebsocketTransport( this.options, ); await this.client.connect(transport, {}); + this.transport = transport; } else { try { const transport = this.constructHttpTransport({ @@ -235,7 +239,7 @@ class MCPConnection { this.transport = transport; } catch (e) { throw new Error( - `MCP config with no URL and type specified failed both sse and http connection: ${e instanceof Error ? e.message : String(e)}`, + `MCP config with URL and no type specified failed both SSE and HTTP connection: ${e instanceof Error ? e.message : String(e)}`, ); } } diff --git a/core/context/mcp/MCPOauth.vitest.ts b/core/context/mcp/MCPOauth.vitest.ts index a8c38c97d..3ba7bc190 100644 --- a/core/context/mcp/MCPOauth.vitest.ts +++ b/core/context/mcp/MCPOauth.vitest.ts @@ -142,7 +142,7 @@ describe("MCPOauth", () => { }, }); - removeMCPAuth(mockMcpServerId, mockIde); + removeMCPAuth(mockMcpServerUrl, mockIde); const updatedStorage = globalContext.get("mcpOauthStorage"); expect(updatedStorage).toEqual({ diff --git a/core/context/mcp/json/loadJsonMcpConfigs.ts b/core/context/mcp/json/loadJsonMcpConfigs.ts index c259b3fb9..5b9887823 100644 --- a/core/context/mcp/json/loadJsonMcpConfigs.ts +++ b/core/context/mcp/json/loadJsonMcpConfigs.ts @@ -19,8 +19,7 @@ import { localPathToUri } from "../../../util/pathToUri"; import { getUriPathBasename, joinPathsToUri } from "../../../util/uri"; /** - * This method searches in both ~/.continue and workspace .continue - * for all YAML/Markdown files in the specified subdirectory, for example .continue/assistants or .continue/prompts + * Loads MCP configs from JSON files in ~/.continue/mcpServers and workspace .continue/mcpServers */ export async function loadJsonMcpConfigs( ide: IDE, @@ -129,9 +128,15 @@ export async function loadJsonMcpConfigs( const yamlConfigs = validJsonConfigs.map((c) => convertJsonMcpConfigToYamlMcpConfig(c.name, c.mcpJson), ); - const mcpServers = yamlConfigs.map((c) => - convertYamlMcpConfigToInternalMcpOptions(c.yamlConfig), - ); + const mcpServers = yamlConfigs.map((c) => { + errors.push( + ...c.warnings.map((warning) => ({ + fatal: false, + message: warning, + })), + ); + return convertYamlMcpConfigToInternalMcpOptions(c.yamlConfig); + }); // Parse and convert files return { mcpServers, diff --git a/extensions/cli/src/services/MCPService.ts b/extensions/cli/src/services/MCPService.ts index 048f1ef03..5df661e8c 100644 --- a/extensions/cli/src/services/MCPService.ts +++ b/extensions/cli/src/services/MCPService.ts @@ -3,15 +3,15 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"; - -import { getErrorString } from "../util/error.js"; -import { logger } from "../util/logger.js"; - import { HttpMcpServer, SseMcpServer, StdioMcpServer, } from "node_modules/@continuedev/config-yaml/dist/schemas/mcp/index.js"; + +import { getErrorString } from "../util/error.js"; +import { logger } from "../util/logger.js"; + import { BaseService, ServiceWithDependencies } from "./BaseService.js"; import { serviceContainer } from "./ServiceContainer.js"; import { @@ -376,7 +376,7 @@ export class MCPService try { const transport = this.constructHttpTransport(serverConfig); await client.connect(transport, {}); - } catch (e) { + } catch { logger.debug( "MCP Connection: http connection failed, falling back to sse connection", { @@ -388,7 +388,7 @@ export class MCPService await client.connect(transport, {}); } catch (e) { throw new Error( - `MCP config with no URL and type specified failed both sse and http connection: ${e instanceof Error ? e.message : String(e)}`, + `MCP config with URL and no type specified failed both SSE and HTTP connection: ${e instanceof Error ? e.message : String(e)}`, ); } } diff --git a/packages/config-yaml/src/schemas/index.ts b/packages/config-yaml/src/schemas/index.ts index ffcda8b94..e130e01fb 100644 --- a/packages/config-yaml/src/schemas/index.ts +++ b/packages/config-yaml/src/schemas/index.ts @@ -132,7 +132,7 @@ export const configYamlSchema = baseConfigYamlSchema.extend({ z.object({ uses: defaultUsesSchema, with: z.record(z.string()).optional(), - override: partialMcpServerSchema, + override: partialMcpServerSchema.optional(), }), ]), ) diff --git a/packages/config-yaml/src/schemas/mcp/index.ts b/packages/config-yaml/src/schemas/mcp/index.ts index 2202f4f3f..3882d3530 100644 --- a/packages/config-yaml/src/schemas/mcp/index.ts +++ b/packages/config-yaml/src/schemas/mcp/index.ts @@ -18,7 +18,7 @@ const stdioMcpServerSchema = baseMcpServerSchema.extend({ export type StdioMcpServer = z.infer; const sseOrHttpMcpServerSchema = baseMcpServerSchema.extend({ - url: z.string(), + url: z.string(), // .url() fails with e.g. IP addresses type: z.union([z.literal("sse"), z.literal("streamable-http")]).optional(), requestOptions: requestOptionsSchema.optional(), }); diff --git a/packages/config-yaml/src/schemas/mcp/json.ts b/packages/config-yaml/src/schemas/mcp/json.ts index 5afd6d70b..20a283350 100644 --- a/packages/config-yaml/src/schemas/mcp/json.ts +++ b/packages/config-yaml/src/schemas/mcp/json.ts @@ -3,7 +3,7 @@ import z from "zod"; // This is the schema for an entry in e.g. Claude Desktop, Claude code mcp config const httpOrSseMcpJsonSchema = z.object({ type: z.union([z.literal("sse"), z.literal("http")]).optional(), - url: z.string().url(), + url: z.string(), // .url() fails with e.g. IP addresses headers: z.record(z.string(), z.string()).optional(), }); export type HttpMcpJsonConfig = z.infer;