You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: remove duplicated RS auth helpers from express package
The requireBearerAuth, mcpAuthMetadataRouter, getOAuthProtectedResourceMetadataUrl,
and OAuthTokenVerifier exports were added to @modelcontextprotocol/express as
backward-compat shims (PR #1907) but are now superseded by
@modelcontextprotocol/server-legacy/auth. All consumers updated.
Copy file name to clipboardExpand all lines: .changeset/cfworker-out-of-barrel.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,4 +3,4 @@
3
3
'@modelcontextprotocol/client': patch
4
4
---
5
5
6
-
Stop bundling `@cfworker/json-schema` into the main package barrel. Previously `CfWorkerJsonSchemaValidator` was re-exported from the core internal barrel, so tsdown inlined the `@cfworker/json-schema`dev dependency into every consumer's bundle even when it was never used. The validator is now reachable only via the `_shims` conditional (workerd/browser) and the explicit `@modelcontextprotocol/{server,client}/validators/cf-worker` subpath, so consumers that don't opt into it no longer ship that code. No public API change.
6
+
Stop bundling `@cfworker/json-schema` into the main package barrel. Previously `CfWorkerJsonSchemaValidator` was re-exported from the core internal barrel, so tsdown inlined the `@cfworker/json-schema` dependency into every consumer's bundle even when it was never used. The named validator classes are now reachable only via the explicit `@modelcontextprotocol/{client,server}/validators/{ajv,cf-worker}` subpaths and the runtime `_shims` conditional, so consumers that import only from the root entry point no longer ship the validator dep.
Bundle automatic JSON Schema validator defaults in `@modelcontextprotocol/client` and `@modelcontextprotocol/server` runtime shims.
8
+
9
+
Client and server pick the right validator automatically based on the runtime: the Node shim uses AJV, the browser/workerd shim uses `@cfworker/json-schema`. Both backends are bundled into the shim chunks that select them, so the default code path needs no extra installs — `import { McpServer } from '@modelcontextprotocol/server'` does not pull `ajv` or `@cfworker/json-schema` into the root entry chunk.
10
+
11
+
The named validator classes remain part of the public surface for consumers who want to customize the built-in backend (pre-register schemas by `$id`, register custom AJV formats, switch dialects, change `@cfworker/json-schema` draft). They are exposed through explicit subpaths so they do not bloat the root index chunk:
12
+
13
+
-`import { AjvJsonSchemaValidator } from '@modelcontextprotocol/{client,server}/validators/ajv'`
14
+
-`import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/{client,server}/validators/cf-worker'`
15
+
16
+
Importing from one of these subpaths means the corresponding peer dep (`ajv` + `ajv-formats`, or `@cfworker/json-schema`) must be in your `package.json`. The shim keeps its own vendored copy for the default path, so a project can use the subpath in some files and rely on the default in others.
17
+
18
+
The `jsonSchemaValidator` interface remains the public extension point for replacing validation entirely with a custom implementation.
Copy file name to clipboardExpand all lines: docs/faq.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ The [server quickstart](./server-quickstart.md) walks you through building a wea
71
71
72
72
### Where are the server auth helpers?
73
73
74
-
Resource Server helpers (`requireBearerAuth`, `mcpAuthMetadataRouter`, `OAuthTokenVerifier`) are first-class in `@modelcontextprotocol/express`. The Authorization Server helpers (`mcpAuthRouter`, `ProxyOAuthServerProvider`, etc.) have been removed from the core SDK; new code should use a dedicated IdP/OAuth library. Example packages provide a demo with `better-auth`.
74
+
All auth helpers (`requireBearerAuth`, `mcpAuthMetadataRouter`, `OAuthTokenVerifier`, `mcpAuthRouter`, `ProxyOAuthServerProvider`, etc.) are available from `@modelcontextprotocol/server-legacy/auth` (deprecated, frozen v1 copy). New code should use a dedicated IdP/OAuth library. Example packages provide a demo with `better-auth`.
|`@modelcontextprotocol/sdk/server/streamableHttp.js`|`@modelcontextprotocol/node` (class renamed to `NodeStreamableHTTPServerTransport`) OR `@modelcontextprotocol/server` (web-standard `WebStandardStreamableHTTPServerTransport` for Cloudflare Workers, Deno, etc.) |
56
56
|`@modelcontextprotocol/sdk/server/sse.js`| REMOVED (migrate to Streamable HTTP); legacy bridge: `@modelcontextprotocol/server-legacy/sse`|
|`@modelcontextprotocol/sdk/server/auth/*`| RS + AS helpers (`requireBearerAuth`, `mcpAuthMetadataRouter`, `OAuthTokenVerifier`, `mcpAuthRouter`, etc.) → `@modelcontextprotocol/server-legacy/auth` (deprecated, frozen v1 copy); migrate to an external IdP/OAuth library |
58
58
|`@modelcontextprotocol/sdk/server/middleware.js`|`@modelcontextprotocol/express` (signature changed, see section 8) |
59
59
60
60
### Types / shared imports
@@ -332,7 +332,7 @@ new URL(ctx.http?.req?.url).searchParams.get('debug')
332
332
333
333
### Server-side auth
334
334
335
-
Resource Server helpers (`requireBearerAuth`, `mcpAuthMetadataRouter`, `getOAuthProtectedResourceMetadataUrl`, `OAuthTokenVerifier`) are first-class in `@modelcontextprotocol/express`. Authorization Server helpers (`mcpAuthRouter`, `OAuthServerProvider`, `ProxyOAuthServerProvider`, `authenticateClient`, `allowedMethods`, etc.) are removed from the core SDK; use an external IdP/OAuth library. See `examples/server/src/` for demos. Legacy bridge: `import { mcpAuthRouter } from '@modelcontextprotocol/server-legacy/auth'` (deprecated, frozen v1 copy).
335
+
All auth helpers (`requireBearerAuth`, `mcpAuthMetadataRouter`, `getOAuthProtectedResourceMetadataUrl`, `OAuthTokenVerifier`, `mcpAuthRouter`, `OAuthServerProvider`, `ProxyOAuthServerProvider`, `authenticateClient`, `allowedMethods`, etc.) are available from `@modelcontextprotocol/server-legacy/auth` (deprecated, frozen v1 copy). Migrate to an external IdP/OAuth library for production use. See `examples/server/src/` for demos.
336
336
337
337
### Host header validation (Express)
338
338
@@ -509,8 +509,8 @@ Type changes in handler context:
509
509
510
510
The SDK now auto-selects the appropriate JSON Schema validator based on runtime:
511
511
512
-
- Node.js → `AjvJsonSchemaValidator` (no change from v1)
- Runtime-aware default: `import { DefaultJsonSchemaValidator } from '@modelcontextprotocol/server/_shims';`
533
-
- AJV (Node.js): `import { AjvJsonSchemaValidator } from '@modelcontextprotocol/server';`
534
-
- CF Worker: `import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker';`
532
+
- Do not add validator imports for normal migrations.
533
+
- Do not install `ajv`, `ajv-formats`, or `@cfworker/json-schema` for the default path; client/server bundle the runtime-selected defaults and the root entry point does not pull either dep in.
534
+
- To customize the built-in backend (e.g. register custom AJV formats, change `@cfworker/json-schema` draft), import the named class from the package subpath: `@modelcontextprotocol/{client,server}/validators/ajv` for `AjvJsonSchemaValidator`, `@modelcontextprotocol/{client,server}/validators/cf-worker` for `CfWorkerJsonSchemaValidator`. Importing from a subpath means the corresponding peer dep must be in your `package.json`.
535
+
- To replace validation entirely, pass `jsonSchemaValidator: myCustomValidator` with your own implementation of the `jsonSchemaValidator` interface.
535
536
536
537
## 15. Migration Steps (apply in this order)
537
538
@@ -543,6 +544,6 @@ Access validators explicitly:
543
544
6. Replace plain header objects with `new Headers({...})` and bracket access (`headers['x']`) with `.get()` calls per section 7
544
545
7. If using `hostHeaderValidation` from server, update import and signature per section 8
545
546
8. If using server SSE transport, migrate to Streamable HTTP
546
-
9. If using server auth from the SDK: RS helpers (`requireBearerAuth`, `mcpAuthMetadataRouter`) → `@modelcontextprotocol/express`; AS helpers → external IdP/OAuth library
547
+
9. If using server auth from the SDK: all auth helpers → `@modelcontextprotocol/server-legacy/auth` (deprecated); migrate to external IdP/OAuth library
547
548
10. If relying on `listTools()`/`listPrompts()`/etc. throwing on missing capabilities, set `enforceStrictCapabilities: true`
Copy file name to clipboardExpand all lines: docs/migration.md
+36-8Lines changed: 36 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,7 +143,7 @@ const transport = new StreamableHTTPClientTransport(new URL('http://localhost:30
143
143
144
144
### Server auth split
145
145
146
-
Resource Server helpers (`requireBearerAuth`, `mcpAuthMetadataRouter`, `getOAuthProtectedResourceMetadataUrl`, `OAuthTokenVerifier`) are now first-class in `@modelcontextprotocol/express`.
146
+
Resource Server helpers (`requireBearerAuth`, `mcpAuthMetadataRouter`, `getOAuthProtectedResourceMetadataUrl`, `OAuthTokenVerifier`) are available from `@modelcontextprotocol/server-legacy/auth`. Migrate to a dedicated OAuth provider for production use.
147
147
148
148
Authorization Server helpers (`mcpAuthRouter`, `OAuthServerProvider`, `ProxyOAuthServerProvider`, `authenticateClient`, `allowedMethods`, etc.) have been removed from the core SDK; new code should use a dedicated IdP/OAuth library. See the [examples](../examples/server/src/) for a working demo with `better-auth`.
This means Cloudflare Workers users no longer need to explicitly pass the validator:
924
924
@@ -949,17 +949,45 @@ const server = new McpServer(
949
949
);
950
950
```
951
951
952
-
You can still explicitly override the validator if needed:
952
+
You do not need to install or import validator packages for the default behavior. The client and server packages bundle the validator backend selected by the runtime shim, so a normal `import { McpServer } from '@modelcontextprotocol/server'` does not pull `ajv` or `@cfworker/json-schema` into your bundle until you choose to customize.
953
+
954
+
If you want to customize the **built-in** backend (for example, pre-register schemas by `$id`, register custom AJV formats, or change the `@cfworker/json-schema` draft), import the named class from the explicit subpath and pass an instance through `jsonSchemaValidator`:
953
955
954
956
```typescript
955
-
// Runtime-aware default (auto-selects AjvJsonSchemaValidator or CfWorkerJsonSchemaValidator)
(both subpaths are also available on `@modelcontextprotocol/client/validators/...`)
986
+
987
+
If you import from one of these subpaths in your own code, the corresponding peer dep (`ajv` + `ajv-formats`, or `@cfworker/json-schema`) needs to be installed in your `package.json`. The runtime shim continues to vendor a copy for the default code path, so you can use the subpath in some files and rely on the default in others.
988
+
989
+
To replace validation wholesale rather than customizing the built-in classes, implement the `jsonSchemaValidator` interface and pass your own implementation through the option above.
990
+
963
991
## Unchanged APIs
964
992
965
993
The following APIs are unchanged between v1 and v2 (only the import paths changed):
0 commit comments