diff --git a/src/inProcessClient.ts b/src/inProcessClient.ts index 448e1ac..df5483c 100644 --- a/src/inProcessClient.ts +++ b/src/inProcessClient.ts @@ -20,10 +20,10 @@ import { BrowserContextFactory } from './browserContextFactory.js'; import { BrowserServerBackend } from './browserServerBackend.js'; import { InProcessTransport } from './mcp/inProcessTransport.js'; import * as mcpServer from './mcp/server.js'; -import { packageJSON } from './package.js'; import type { FullConfig } from './config.js'; import type { ClientFactory } from './mcp/proxyBackend.js'; +import type { Implementation } from '@modelcontextprotocol/sdk/types.js'; export class InProcessClientFactory implements ClientFactory { name: string; @@ -39,11 +39,8 @@ export class InProcessClientFactory implements ClientFactory { this._config = config; } - async create(): Promise { - const client = new Client({ - name: this.name, - version: packageJSON.version - }); + async create(clientVersion: Implementation): Promise { + const client = new Client(clientVersion); const server = mcpServer.createServer(new BrowserServerBackend(this._config, this._contextFactory), false); await client.connect(new InProcessTransport(server)); await client.ping(); diff --git a/src/mcp/proxyBackend.ts b/src/mcp/proxyBackend.ts index 2372627..4c40431 100644 --- a/src/mcp/proxyBackend.ts +++ b/src/mcp/proxyBackend.ts @@ -23,13 +23,14 @@ import { packageJSON } from '../package.js'; import { logUnhandledError } from '../log.js'; import type { Client } from '@modelcontextprotocol/sdk/client/index.js'; +import type { Implementation } from '@modelcontextprotocol/sdk/types.js'; type NonEmptyArray = [T, ...T[]]; export type ClientFactory = { name: string; description: string; - create(options: any): Promise; + create(clientVersion: Implementation, options: any): Promise; }; export type ClientFactoryList = NonEmptyArray; @@ -42,6 +43,7 @@ export class ProxyBackend implements ServerBackend { private _currentClient: Client | undefined; private _contextSwitchTool: Tool; private _tools: ToolSchema[] = []; + private _server?: Server; constructor(clientFactories: ClientFactoryList) { this._clientFactories = clientFactories; @@ -49,6 +51,7 @@ export class ProxyBackend implements ServerBackend { } async initialize(server: Server): Promise { + this._server = server; await this._setCurrentClient(this._clientFactories[0], undefined); } @@ -120,7 +123,7 @@ export class ProxyBackend implements ServerBackend { private async _setCurrentClient(factory: ClientFactory, options: any) { await this._currentClient?.close(); - this._currentClient = await factory.create(options); + this._currentClient = await factory.create(this._server!.getClientVersion()!, options); const tools = await this._currentClient.listTools(); this._tools = tools.tools.map(tool => ({ name: tool.name, diff --git a/src/mcp/server.ts b/src/mcp/server.ts index 023e7fd..26ea68e 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -77,7 +77,7 @@ export function createServer(backend: ServerBackend, runHeartbeat: boolean): Ser name: tool.name, description: tool.description, // TODO: we expect inputSchema to be a zod schema, but in the out-of-process case it's already a json schema. - // we should probably move the "zodToJsonSchema" call into defineTool. + // we should move the "zodToJsonSchema" call into defineTool. inputSchema: tool.inputSchema.$schema ? tool.inputSchema : zodToJsonSchema(tool.inputSchema), annotations: { title: tool.title, diff --git a/src/vscode/host.ts b/src/vscode/host.ts index 14b2b25..0a41632 100644 --- a/src/vscode/host.ts +++ b/src/vscode/host.ts @@ -17,7 +17,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; import { FullConfig } from '../config.js'; import { ClientFactory } from '../mcp/proxyBackend.js'; -import { packageJSON } from '../package.js'; +import type { Implementation } from '@modelcontextprotocol/sdk/types.js'; class VSCodeClientFactory implements ClientFactory { name = 'vscode'; @@ -25,16 +25,13 @@ class VSCodeClientFactory implements ClientFactory { constructor(private readonly _config: FullConfig) {} - async create(options: any): Promise { + async create(clientVersion: Implementation, options: any): Promise { if (typeof options.connectionString !== 'string') throw new Error('Missing options.connectionString'); if (typeof options.lib !== 'string') throw new Error('Missing options.library'); - const client = new Client({ - name: this.name, - version: packageJSON.version - }); + const client = new Client(clientVersion); await client.connect(new StdioClientTransport({ command: process.execPath, cwd: process.cwd(),