diff --git a/CHANGELOG.md b/CHANGELOG.md index 606ed94..7477939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - **Testing:** the tool tests call `run()` directly and never touch the SDK, so there's a new test that installs every tool and resource on a real v2 `McpServer` and goes through `tools/list`, `tools/call`, `resources/list` and `resources/read`. Also checked the built server over stdio, including a live search and document fetch. - **Tests are typechecked in CI now:** `npm run typecheck` checks `src` and `test` together. The tests weren't typechecked before, and `SearchDocsTool.test.ts` had 7 errors on main (the v2 types fix those). `tsconfig.test.json` gets `noEmit` so a plain `tsc` run can't write `.js` files next to the sources. - chore: harden document fetching. **Breaking for some URLs:** `get_document_tool` and `batch_get_documents_tool` now accept only `https://docs.mapbox.com` URLs (plus `MAPBOX_DOCS_HOST_OVERRIDE` when set); bare `mapbox.com` and `docs.tilestream.net` (without the override) are rejected. The shared HTTP pipeline no longer follows redirects; document fetches follow up to 3 redirects, each only to an allowed docs URL. `access_token` detection is now case-insensitive (#45) +- fix: the CommonJS build works again. `require('@mapbox/mcp-docs-server/tools')` (and `/resources`, `/utils`) threw "Cannot use 'import.meta' outside a module", since `src/utils/versionUtils.ts` uses `import.meta.url` and tshy compiled it into `dist/commonjs` as is. There's now a `versionUtils-cjs.cts` that tshy uses for the CommonJS build instead, reading `version.json` from `__dirname`, same as mcp-server does. ESM was never affected, and hosted-mcp-server uses ESM. (#47) - docs: fix two stale tool descriptions left over from the Algolia-to-`llms.txt` search migration. `search_mapbox_docs_tool`'s README entry still said it used "Algolia full-text search" — that was removed a while back (see the "Replace Algolia search with self-contained llms.txt search" entry below) and it now searches the self-hosted `llms.txt` index. Separately, `get_document_tool`'s own description (the text shown to the LLM, not just docs) referenced a tool named `get_latest_mapbox_docs_tool`, which doesn't exist — it should have said `search_mapbox_docs_tool`, and was actively misdirecting tool-chaining behavior. - fix: startup/shutdown/error logging messages now actually reach clients. The `McpServer` never declared the `logging` capability, so every `sendLoggingMessage` call (including the existing "server started"/"shutting down"/"Fatal error" messages) was a silent no-op regardless of when it was sent. Declared `logging: {}` in the server's capabilities. - feat: the server now identifies which MCP client connected to it. `server.server.getClientVersion()` (populated from the `clientInfo` sent in the client's `initialize` request) is now logged on connect, e.g. `Client identified as: claude-ai v1.0.0`. Reading it required moving the read to a `server.server.oninitialized` callback rather than right after `server.connect()`, since `getClientVersion()` is only populated once the client's `initialize` request has actually been processed, which is not guaranteed by the time `connect()`'s promise resolves. Also recorded as `mcp.client.name`/`mcp.client.version` on every subsequent tool-execution trace span (`withToolSpan`), so OTel-backed traces can be filtered or grouped by client. Matches the equivalent changes landing in `@mapbox/mcp-server` and `@mapbox/mcp-devkit-server`. diff --git a/src/utils/versionUtils-cjs.cts b/src/utils/versionUtils-cjs.cts new file mode 100644 index 0000000..77a149e --- /dev/null +++ b/src/utils/versionUtils-cjs.cts @@ -0,0 +1,35 @@ +// Copyright (c) Mapbox, Inc. +// Licensed under the MIT License. + +// CommonJS build of versionUtils.ts. tshy uses this file in place of +// versionUtils.ts for dist/commonjs, since import.meta doesn't exist there. + +import { readFileSync } from 'node:fs'; +import path from 'node:path'; + +export interface VersionInfo { + name: string; + version: string; + sha: string; + tag: string; + branch: string; +} + +export function getVersionInfo(): VersionInfo { + const name = 'Mapbox Documentation MCP Server'; + try { + const filePath = path.resolve(__dirname, '..', 'version.json'); + const data = readFileSync(filePath, 'utf-8'); + const info = JSON.parse(data) as VersionInfo; + info.name = name; + return info; + } catch { + return { + name: name, + version: '0.0.0', + sha: 'unknown', + tag: 'unknown', + branch: 'unknown' + }; + } +}