diff --git a/src/mcp/server.ts b/src/mcp/server.ts index 804b0791..eeddd5e6 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -6,6 +6,19 @@ import { checkPaidCallTarget, parsePaidCallAllowlist, type PaidCallAllowRule } f import { fetchWithTimeout } from '../fetch.js'; import { config } from '../config.js'; import { ssrfSafeFetch, SsrfError, type SsrfFetchOptions } from '../net/ssrf.js'; +import { readFileSync } from 'fs'; +import { fileURLToPath } from 'url'; +import { join, dirname } from 'path'; + +// Read the version from package.json at startup so it is never out of step +// with the published package. Renamed from 'bazaar-mcp-server' to +// 'lens-mcp-server' to reflect the containing project (client-affecting change). +const _pkgPath = join(dirname(fileURLToPath(import.meta.url)), '../../package.json'); +const _pkg = JSON.parse(readFileSync(_pkgPath, 'utf8')) as { version: string }; +/** The version string advertised to MCP clients — sourced from package.json. */ +export const SERVER_VERSION: string = _pkg.version; +/** The canonical MCP server name advertised to clients. */ +export const SERVER_NAME = 'lens-mcp-server'; export interface McpServerConfig { fetchWithPayment: typeof fetch; @@ -49,8 +62,8 @@ export class BazaarMcpServer { }; this.server = new Server( { - name: 'bazaar-mcp-server', - version: '1.0.0', + name: SERVER_NAME, + version: SERVER_VERSION, }, { capabilities: { diff --git a/tests/mcp.test.ts b/tests/mcp.test.ts index 7d71be0d..833146f3 100644 --- a/tests/mcp.test.ts +++ b/tests/mcp.test.ts @@ -1,6 +1,20 @@ import { describe, it, expect, vi } from 'vitest'; -import { BazaarMcpServer } from '../src/mcp/server'; +import { BazaarMcpServer, SERVER_VERSION, SERVER_NAME } from '../src/mcp/server'; import { CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js'; +import { readFileSync } from 'fs'; +import { join } from 'path'; + +const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8')) as { version: string }; + +describe('BazaarMcpServer — server identity', () => { + it('advertises the version from package.json (never a hard-coded string)', () => { + expect(SERVER_VERSION).toBe(pkg.version); + }); + + it('uses the canonical server name lens-mcp-server (client-affecting rename from bazaar-mcp-server)', () => { + expect(SERVER_NAME).toBe('lens-mcp-server'); + }); +}); describe('BazaarMcpServer', () => { it('should map signature expiration ledger error to ERR_EXPIRED_AUTHORISATION', async () => {