Skip to content

feat!: keep engine shapes out of the public api - #422

Open
HugoRCD wants to merge 1 commit into
v1-09-oauth-challengesfrom
v1-10-engine-seams
Open

HugoRCD wants to merge 1 commit into
v1-09-oauth-challengesfrom
v1-10-engine-seams

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Written by an AI agent on behalf of @HugoRCD. @HugoRCD has reviewed it.

The beta's public types still followed h3-mcp's shapes even after #420 renamed them, so moving to another engine after 1.0 would break users. Each definition carried a public build(identity, into, notify) whose buckets are typed from h3-mcp's HandlerOptions. McpRequestContext and the auth, origin, session and limits options were aliases of h3-mcp types. McpOAuth exposed values computed from an absolute resource fixed at startup, which would get in the way of deriving resource from the request later. This PR makes the definition shape data-only, writes those types out as toolkit interfaces with the same fields, trims McpOAuth to fields that don't depend on the request, and documents extension plugins as experimental because they are h3-mcp's plugin contract.

To try it in a Nitro or Nuxt app, install the PR build:

npm i https://pkg.pr.new/nitro-mcp-toolkit@422 https://pkg.pr.new/@nuxtjs/mcp-toolkit@422

Before and after

The same script on #421 (v1-09-oauth-challenges) and on this branch. It defines a tool and an OAuth resource server, prints their public keys, and serves a spread copy of the tool under a new name:

--- base
definition keys: kind, name, title, description, group, tags, scopes, _meta, build
McpOAuth keys:   resource, metadataPath, resourceMetadataUrl, metadata, auth, metadataHandler
spread definition served as: hello
exit 0
--- head
definition keys: kind, name, title, description, group, tags, scopes, _meta
McpOAuth keys:   metadataPath, auth, metadataHandler
spread definition served as: hello
exit 0

Registration now sits under a symbol the package does not export. Spreading a definition and Object.assign keep it, which the generated registry and the provider adapters rely on. To serve the metadata document from your own route, call the handler; it now also accepts a Nitro 2 event:

// server/routes/.well-known/oauth-protected-resource/private-mcp.ts
export default defineEventHandler(event => oauth.metadataHandler(event))

Breaking changes

  • Definitions no longer have a build method.
  • McpOAuth drops resource, resourceMetadataUrl, metadata and challengeScope. The challenge URL remains at oauth.auth.resourceMetadataUrl.

The rewritten interfaces keep the same fields. log and logLevel stay on McpRequestContext because the docs, playground and tests use them; whether to drop protocol logging before stable is a separate decision. Type tests now pin the public keys of McpTool and McpOAuth. The tsconfig also maps nitro-mcp-toolkit/oauth/* and /testing to source, so typecheck no longer depends on a built dist.

Left out on purpose:

  • A request-derived resource. Taking the audience from the Host header would accept tokens issued for another origin's /mcp, so it needs a trusted origin source first.
  • The per-request cost of X-MCP-Tools support. createMcpHandler passes h3-mcp an options function, and h3-mcp's _resolveLazyArray then runs Promise.all over every definition on each request. Serving header-less requests from a second engine would split legacy sessions, task plugin state and cancellation, so the fix belongs upstream. On a patched copy of h3-mcp 0.2.0, 1,000-tool tools/call with options from a function went from 2,253 to 8,230 req/s (static options: 7,051 to 7,593). That was a local measurement and is not part of this PR.

Checks I ran myself, beyond CI: pnpm test:package passed (packed Nitro 2/3 consumers and the Better Auth fixture on both protocol eras), and a throwaway Nuxt route showed oauth.metadataHandler(event) now typechecks with a Nitro 2 event. Nobody has tried this with a real MCP client or on nuxt.com yet.

ELI5

The toolkit sits on top of an engine that speaks MCP. Some of the toolkit's public pieces were really the engine's pieces wearing a toolkit label, so swapping engines would have broken people's code. This PR keeps those pieces private or describes them in the toolkit's own words, so the engine can change later without breaking anyone.

@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nuxt-mcp-toolkit-docs Ready Ready Preview Nov 25, 2026 1:53pm UTC

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/nitro-mcp-toolkit@422
npm i https://pkg.pr.new/@nuxtjs/mcp-toolkit@422

commit: 9a2a836

Definitions register through a non-exported symbol instead of a public
`build` method. The request context and the auth, origin, session and
limits options are toolkit interfaces rather than h3-mcp aliases.
`McpOAuth` drops the fields derived from an absolute `resource`, and its
metadata handler accepts a Nitro 2 event. Extension plugins are
documented as experimental.

Amp-Thread-ID: https://ampcode.com/threads/T-01a212c1-2657-766d-9319-d6a1eada641c
Co-authored-by: Amp <amp@ampcode.com>

This branch was successfully deployed

1 active deployment
Preview — 9a2a836c Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant