Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/engine-neutral-shapes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"nitro-mcp-toolkit": major
"@nuxtjs/mcp-toolkit": major
---

Public types no longer follow the protocol engine's shapes. `McpRequestContext`, `McpAuthOptions`, `McpAuthCredentials`, `McpOriginOptions`, `McpSessionOptions` and `McpLimitsOptions` are now the toolkit's own interfaces, with the same fields as before, and `McpLogLevel` types the request's log level.

Definitions returned by `defineMcpTool`, `defineMcpResource` and `defineMcpPrompt` no longer have a `build` method. Spreading a definition still works.

`McpOAuth` no longer exposes `resource`, `resourceMetadataUrl`, `metadata` or `challengeScope`. Serve the metadata document with `oauth.metadataHandler(event)`, which now also accepts a Nitro 2 event, and read the challenge URL from `oauth.auth.resourceMetadataUrl`.

Extension plugins (`McpExtensionPlugin`, `defineMcpPlugins`, `<dir>/plugins.ts` and the `{ extensionPlugins }` argument) are now documented as experimental. They expose the engine's plugin contract and may change in any release.
18 changes: 11 additions & 7 deletions .github/V1_ROLLOUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ Open the foundation PR first. Later PRs target the preceding branch while it is

| Order | Branch | Review scope |
| --- | --- | --- |
| 1 | `v1-01-release-rails` | CI for the integration branch and stack, release-channel checks, beta activation for both packages |
| 2 | `v1-02-nitro2` | Nitro 2 adapter, H3 version isolation, transport/context/cancellation tests |
| 3 | `v1-03-shared-api` | Definition metadata, directory overlays, generated imports, shared request APIs |
| 4 | `v1-04-no-mcp-apps` | Remove built-in MCP Apps, their Vue bundler and host bridge, and update migration guidance |
| 5 | `v1-05-nuxt` | Nuxt adapter, retirement of the old runtime and APIs, migrated fixtures and example applications |
| 6 | `v1-06-docs` | Complete migration guide, docs site, READMEs, published agent skill |
| 7 | `v1-07-beta` | Beta consumer validation and release readiness |
| 1 | `v1-01-release-rails` | CI for the integration branch and stack, release-channel checks, beta activation for both packages (merged, #398) |
| 2 | `v1-02-nitro2` | Nitro 2 adapter, H3 version isolation, transport/context/cancellation tests (merged, #399) |
| 3 | `v1-03-shared-api` | Definition metadata, directory overlays, generated imports, shared request APIs (#402) |
| 4 | `v1-04-no-mcp-apps` | Remove built-in MCP Apps, their Vue bundler and host bridge, and update migration guidance (#403) |
| 5 | `v1-05-nuxt` | Nuxt adapter, retirement of the old runtime and APIs, migrated fixtures and example applications (#405) |
| 6 | `v1-06-docs` | Migration guide, docs site, READMEs, published agent skill, server configuration DX (#406) |
| 7 | `v1-07-auth-dx` | Runtime OAuth provider adapters (#415) |
| 8 | `v1-08-toolkit-types` | Toolkit-owned names for exported engine types (#420) |
| 9 | `v1-09-oauth-challenges` | OAuth scope challenges and service tokens (#421) |
| 10 | `v1-10-engine-seams` | Engine-neutral public shapes, experimental plugins |
| 11 | not opened | Beta consumer validation and release readiness |

Keep each step buildable and tested. Public changes carry their own changesets and enough documentation to use them; the docs step completes the migration material. Example application code moves with the API changes it consumes so CI previews remain usable.

Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ Windows is covered by a dedicated `test-windows` CI job that runs this package's

The runtime is written against a pinned `h3-mcp` (currently 0.2.0). That release dropped the `Mcp` prefix on types, owns MRTR helpers and RFC 9728 `resourceMetadataUrl`, and requires URI templates to pass through `defineResourceTemplate` so RFC 6570 matching is in the bundle — `defineMcpResource` already does that. Re-export the engine's elicitation kit (`inputRequired`, `mcpElicit`, `mcpElicitUrl`, `getElicitedContent`, `getInputResponses`, `getMissingInputs`, `canRequestInput`, `getSupportedInputs`, `defineRequestState`) and `McpJsonRpcError`; do not reimplement them. `createMcpHandler`'s second argument is h3-mcp's `{ extensionPlugins }`, typed as `McpHandlerSetup`.

**The public API names only toolkit types.** Engine concepts are exported under `Mcp`-prefixed names (`McpAuthOptions`, `McpEra`, `McpExtensionPlugin`, `McpRequestContext`, …), and MCP spec types keep their spec names; never re-export an h3-mcp type under its own name. `McpHandlerOptions` lists each option it maps onto the engine instead of extending h3-mcp's `HandlerOptions` — `test/types.test.ts` pins the set, so a new option is a deliberate change. h3-mcp's own `H3EventContext.mcp` augmentation still widens `McpEvent.context.mcp` to the engine's full context; that leak goes away only with the engine. `nitro` and `nitropack` are optional peers used by their module entrypoints; H3 v2 is an internal dependency.
**The public API names only toolkit types.** Engine concepts are exported under `Mcp`-prefixed names (`McpAuthOptions`, `McpEra`, `McpExtensionPlugin`, `McpRequestContext`, …), and MCP spec types keep their spec names; never re-export an h3-mcp type under its own name. `McpHandlerOptions` lists each option it maps onto the engine instead of extending h3-mcp's `HandlerOptions` — `test/types.test.ts` pins the set, so a new option is a deliberate change. h3-mcp's own `H3EventContext.mcp` augmentation still widens `McpEvent.context.mcp` to the engine's full context; that leak goes away only with the engine. `McpRequestContext`, `McpAuthOptions`, `McpOriginOptions`, `McpSessionOptions` and `McpLimitsOptions` are written out as toolkit interfaces rather than aliases, so an engine upgrade cannot silently change them. A definition's engine registration lives under a non-exported symbol (`buildDefinition` in `src/runtime/definition.ts`), and so does what an `McpOAuth` needs for its challenges (`oauthChallenge`), so neither is part of the public shape; symbol keys survive spreading and `Object.assign`, which the generated registry and the provider adapters rely on. Extension plugins are documented as experimental: they are h3-mcp's plugin contract. `nitro` and `nitropack` are optional peers used by their module entrypoints; H3 v2 is an internal dependency.

**`X-MCP-Tools` is the same kind of gate** (`src/runtime/tools-header.ts`): allowlist of tool names, HTTP 400 on unknowns. Unknown names run a separate engine with no application definitions or plugins on the original event, so authentication sees middleware context and the original body. `handler.definitions` stays the full catalog. Tool names and registration positions are indexed once; the last header selection is retained per handler to avoid repeated parsing and sorting. The cache holds only catalog membership, never authentication or request state. Different selections replace it, and every request still runs auth and scope checks.

**`scopes` gates invocation and application callbacks; static definition metadata stays listed.** Resource-template enumeration/completion and prompt completion check scopes before calling application code; unauthorized enumeration fails `resources/list`, rather than returning a partial list. `requireScopes` (`src/runtime/scopes.ts`) wraps the handler each of the three `build()` methods pushes, reads `event.context.oauth`, and throws `McpJsonRpcError(-32003, …, { status: 403 })`; `settle()` relays that without turning it into an `isError` result. That `status` only reaches the wire on the modern revision — a legacy request gets the same JSON-RPC error inside a `200` stream, as it does for every error — so assert on the code, not the status, unless the test pins an era. It fails closed — scopes on an endpoint with no OAuth refuse every call. With OAuth, `createMcpHandler` turns that modern `403` into RFC 6750's `insufficient_scope` challenge (granted plus required scopes, `resource_metadata`) from the scopes `requireScopes` records per event, and adds `scope` from `scopesSupported` to h3-mcp's `401` challenge; an `authorize` denial stays a bare `403`. Filtering `tools/list` instead is not available: h3-mcp resolves the handler's options (where the `X-MCP-Tools` filter lives) **before** `checkAuth` populates `event.context.oauth`, and that resolution is synchronous, so no JWT check fits there. The `decorate` plugin hook does run after auth, but only from `handleModernPost`, so it would leave legacy requests ungated while `era` is `dual`. Hiding listings needs a post-auth hook covering both eras upstream in h3-mcp; do not grow a local workaround. Read scopes from `scope` (space-delimited, RFC 6749) and `scp` (string or array, Okta/Entra ID) only — `permissions` is Auth0-specific and was left out on purpose.
**`scopes` gates invocation and application callbacks; static definition metadata stays listed.** Resource-template enumeration/completion and prompt completion check scopes before calling application code; unauthorized enumeration fails `resources/list`, rather than returning a partial list. `requireScopes` (`src/runtime/scopes.ts`) wraps the handler each of the three `[buildDefinition]()` methods pushes, reads `event.context.oauth`, and throws `McpJsonRpcError(-32003, …, { status: 403 })`; `settle()` relays that without turning it into an `isError` result. That `status` only reaches the wire on the modern revision — a legacy request gets the same JSON-RPC error inside a `200` stream, as it does for every error — so assert on the code, not the status, unless the test pins an era. It fails closed — scopes on an endpoint with no OAuth refuse every call. With OAuth, `createMcpHandler` turns that modern `403` into RFC 6750's `insufficient_scope` challenge (granted plus required scopes, `resource_metadata`) from the scopes `requireScopes` records per event, and adds `scope` from `scopesSupported` to h3-mcp's `401` challenge; an `authorize` denial stays a bare `403`. Filtering `tools/list` instead is not available: h3-mcp resolves the handler's options (where the `X-MCP-Tools` filter lives) **before** `checkAuth` populates `event.context.oauth`, and that resolution is synchronous, so no JWT check fits there. The `decorate` plugin hook does run after auth, but only from `handleModernPost`, so it would leave legacy requests ungated while `era` is `dual`. Hiding listings needs a post-auth hook covering both eras upstream in h3-mcp; do not grow a local workaround. Read scopes from `scope` (space-delimited, RFC 6749) and `scp` (string or array, Okta/Entra ID) only — `permissions` is Auth0-specific and was left out on purpose.

**Plugins reach a `mcp()` server through `<dir>/plugins.ts`, not through an option** — an `ExtensionPlugin` is a live function and `mcp()` options cross into generated code as JSON. `discoverPlugins` returns *every* match so the caller can refuse an ambiguous pair; `onePluginsFile` in `src/module/index.ts` does that where it can name the route, which also keeps the watcher's `served()` from dying on a misconfiguration. The handler virtual is `async` for the same reason the registry is: a file written after `setup` must be seen at rebuild. The file's default export goes through `defineMcpPlugins` (`src/runtime/plugins.ts`), an identity function that exists purely to typecheck it — generated code is its only importer and is not checked with the app. Keep its parameter `readonly ExtensionPlugin[]` and **not** a generic: a generic preserves each plugin's `TState` but loses excess-property checking during inference, so a misspelled hook slips through, and nothing reads state through the array anyway (`pluginState` types off the instance). Adding the convention means four places, not one — `discover.ts`, `template.ts` (`renderHandler`'s second argument), `watch.ts` (`couldChangeServed` plus `served`, or creating the file triggers no `rollup:reload`), and `report.ts`.

Expand Down
4 changes: 3 additions & 1 deletion apps/docs/content/5.handlers/2.structure-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ All options passed through discovery become generated code, so they must be seri

Put live extension plugins in `<dir>/plugins.ts`, default-exported through `defineMcpPlugins`.


::warning
Extension plugins are experimental. `McpExtensionPlugin`, `defineMcpPlugins`, `<dir>/plugins.ts` and the `{ extensionPlugins }` argument expose the protocol engine's plugin contract, so they may change in any release, including after 1.0.
::

Type an extension with `McpExtensionPlugin`; it is the engine's plugin contract, so an extension written against it depends on that engine. Plugins are functions, so a `plugins` array in `nuxt.config.ts` is not the discovery API. Ambiguous plugin files in a root are rejected.

Expand Down
16 changes: 2 additions & 14 deletions apps/docs/content/8.examples/1.authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,10 @@ export default createMcpHandler({
import { defineEventHandler } from 'nuxt/server'
import { oauth } from '../../../utils/mcp-oauth'

const headers = {
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET, OPTIONS',
'access-control-allow-headers': '*',
}

export default defineEventHandler((event) => {
if (event.req.method === 'OPTIONS') return new Response(null, { status: 204, headers })
if (event.req.method !== 'GET') {
return new Response(null, { status: 405, headers: { ...headers, allow: 'GET, OPTIONS' } })
}
return Response.json(oauth.metadata, { headers })
})
export default defineEventHandler(event => oauth.metadataHandler(event))
```

`createMcpHandler` accepts the prepared `oauth` instance and exposes it as `handler.oauth`. It also accepts `authorize(identity, event)` alongside `oauth`. `oauth.metadataPath` identifies this metadata URL. Use the public resource origin consistently; it is also carried in authentication challenges. The configured module mounts metadata through its native adapter automatically, while a manual route owns its host HTTP integration.
`createMcpHandler` accepts the prepared `oauth` instance and exposes it as `handler.oauth`. It also accepts `authorize(identity, event)` alongside `oauth`. `oauth.metadataPath` identifies this metadata URL, and `oauth.metadataHandler` answers it, CORS preflight included. Use the public resource origin consistently; it is also carried in authentication challenges. The configured module mounts metadata through its native adapter automatically, while a manual route owns its host HTTP integration.

For opaque tokens, replace the `jwt` option with `verify(token, event)` backed by your provider's resource-aware verifier, keeping `resource` and `authorizationServers`. Populate verified `event.context.oauth` claims for identity/scopes. Do not accept a token merely because it exists or belongs to another API.

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/skills/manage-mcp/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ This mounts `/mcp` and `/mcp/admin`. Each server scans only its own roots. Paths

Use groups and tags for metadata, not authorization. Import generated endpoints from `nitro-mcp-toolkit/servers` and filter `handler.definitions` with ordinary arrays. A non-default export name follows the camel-cased route slug. See [servers](references/handlers.md).

Put endpoint extension plugins in `<dir>/plugins.ts` with `defineMcpPlugins([...])`. An `auth` file default-exports `defineMcpAuth({ schemes: ['bearer'], validate })` options; callbacks can read private runtime configuration. Paths resolve from the project root, with Nuxt aliases supported. Keep automatic discovery for live verifiers; manual collections can still use an ordinary route exporting `createMcpHandler(...)`.
Put endpoint extension plugins in `<dir>/plugins.ts` with `defineMcpPlugins([...])`. Plugins are experimental: they expose the engine's plugin contract and may change in any release. An `auth` file default-exports `defineMcpAuth({ schemes: ['bearer'], validate })` options; callbacks can read private runtime configuration. Paths resolve from the project root, with Nuxt aliases supported. Keep automatic discovery for live verifiers; manual collections can still use an ordinary route exporting `createMcpHandler(...)`.

## Authorization and request context

Expand Down
5 changes: 4 additions & 1 deletion packages/nitro-mcp-toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ Declared `group`, non-empty `tags`, and non-empty `scopes` take precedence over

### Plugins

> [!WARNING]
> Extension plugins are experimental. They expose the protocol engine's plugin contract, so `McpExtensionPlugin`, `defineMcpPlugins`, `plugins.ts` and `{ extensionPlugins }` may change in any release, including after 1.0.

`server/mcp/plugins.ts`, beside the three directories, installs [h3-mcp](https://github.com/h3js/h3-mcp) extension plugins on that endpoint. Its default export is the array:

```ts
Expand Down Expand Up @@ -526,7 +529,7 @@ export default createMcpHandler({ name: 'my-server', version: '1.0.0', tools: [g

Handwritten definitions name themselves, since no filename is there to do it.

The handler also exposes a web-standard `fetch`, so it mounts anywhere else too — `new H3().all('/mcp', handler)`, or straight onto any fetch-native runtime. Pass `{ extensionPlugins }` (`McpHandlerSetup`) as the second argument to install [h3-mcp](https://mcp.h3.dev) extensions such as tasks or MCP Apps.
The handler also exposes a web-standard `fetch`, so it mounts anywhere else too — `new H3().all('/mcp', handler)`, or straight onto any fetch-native runtime. Pass `{ extensionPlugins }` (`McpHandlerSetup`) as the second argument to install [h3-mcp](https://mcp.h3.dev) extensions such as tasks or MCP Apps. Like `plugins.ts`, this is experimental.

Framework adapters can pass request context by reference with `handler.fetch(request, context)`:

Expand Down
28 changes: 24 additions & 4 deletions packages/nitro-mcp-toolkit/src/runtime/auth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import type { AuthCredentials, AuthOptions, AuthScheme } from 'h3-mcp'
import type { H3Event } from 'h3/generic'
import type { McpOAuth } from './oauth.ts'

export type McpAuthOptions = AuthOptions
export type McpAuthCredentials = AuthCredentials
export type McpAuthScheme = AuthScheme
export type McpAuthScheme = 'bearer' | 'api-key'

/** The credential a request presented, as `validate` receives it. */
export interface McpAuthCredentials {
scheme: McpAuthScheme
token: string
}

/** Bearer token or API key authentication for an endpoint. */
export interface McpAuthOptions {
/** @default true */
enabled?: boolean
/** @default ['bearer'] */
schemes?: McpAuthScheme[]
/** Static tokens accepted as-is. */
tokens?: string[]
/** Return `true` to accept the credential. Runs when no static token matched. */
validate?: (credentials: McpAuthCredentials, event: H3Event) => boolean | Promise<boolean>
/** Header carrying an API key. */
header?: string
/** RFC 9728 metadata URL carried on the `401` challenge. */
resourceMetadataUrl?: string
}

export function assertMcpOAuth(oauth: McpOAuth): void {
if (
Expand Down
Loading
Loading