Skip to content

fix(server): preserve RequestMetaEnvelope keys in published typings - #3172

Open
gentil93 wants to merge 1 commit into
modelcontextprotocol:mainfrom
gentil93:fix/3171-preserve-request-meta-envelope-keys
Open

gentil93 wants to merge 1 commit into
modelcontextprotocol:mainfrom
gentil93:fix/3171-preserve-request-meta-envelope-keys

Conversation

@gentil93

Copy link
Copy Markdown

Summary

Fixes #3171.

In @modelcontextprotocol/server 2.4.0, RequestMetaEnvelope is published as {} (see dist/mcp-DbUPMDd5.d.cts and dist/mcp-BCJHyo7l.d.mts). The source type is keyed by the public meta-key constants ([CLIENT_CAPABILITIES_META_KEY], …). The tsdown declaration bundler dropped those computed keys, so a handler cannot read the envelope without a cast:

error TS7053: Element implicitly has an 'any' type because expression of type '"io.modelcontextprotocol/clientCapabilities"' can't be used to index type 'Partial<RequestMetaEnvelope>'.

The v2.4.0 source of this type is the same as current main. A local tsdown 0.18.4 build happens to keep the computed key names, but that still depends on the bundler not dropping them again.

This change writes the envelope keys as the wire string literals (the type stays a type alias, not an interface, so it remains assignable to _meta's string-indexed slot). After pnpm build:all, the published .d.ts contains:

type RequestMetaEnvelope = {
  'io.modelcontextprotocol/protocolVersion': string;
  'io.modelcontextprotocol/clientInfo'?: Implementation;
  'io.modelcontextprotocol/clientCapabilities': ClientCapabilities;
  'io.modelcontextprotocol/logLevel'?: LoggingLevel;
};

So ctx.mcpReq.envelope?.[CLIENT_CAPABILITIES_META_KEY] is typed as ClientCapabilities | undefined.

Tests

  • packages/core-internal/test/types/requestMetaEnvelope.test.ts pins the literal keys to the public meta-key constants, so the two cannot drift.
  • scripts/smoke-dist-types.mjs (run in CI after build:all) now compiles the issue's consumer pattern against the built declarations, for both the ESM and CommonJS consumers. The same check fails with TS7053 against the published 2.4.0 typings.

How I verified

  • pnpm build:all
  • Inspected packages/server/dist/mcp-*.d.mts and *.d.cts for the keyed RequestMetaEnvelope (not {})
  • node scripts/smoke-dist-types.mjs
  • pnpm typecheck:all
  • pnpm lint:all
  • pnpm test:all

The tsdown declaration bundler dropped computed keys on RequestMetaEnvelope
in the 2.4.0 publish, so the type shipped as {} and indexing
ctx.mcpReq.envelope with CLIENT_CAPABILITIES_META_KEY failed with TS7053.

Write the envelope keys as string literals (still a type alias) so the
published .d.ts keeps the wire shape, pin the keys to the public constants
in a type test, and cover the consumer pattern in smoke-dist-types.

Fixes modelcontextprotocol#3171
@gentil93
gentil93 requested a review from a team as a code owner November 10, 2026 20:35
@changeset-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 613276e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/core-internal Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/client Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@3172

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@3172

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@3172

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@3172

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@3172

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@3172

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@3172

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@3172

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@3172

commit: 613276e

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Nov 11, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v2] RequestMetaEnvelope is published as {}, so ctx.mcpReq.envelope keys are untyped

1 participant