Skip to content

Commit 7cac712

Browse files
feat(compat): add @modelcontextprotocol/server-auth-legacy package
Frozen, deprecated copy of the v1 SDK's src/server/auth/ Authorization Server helpers (mcpAuthRouter, ProxyOAuthServerProvider, OAuth handlers, middleware, and error subclasses) as a standalone package for v1 -> v2 migration. The package carries a package.json "deprecated" field directing users to a dedicated IdP plus the Resource Server helpers in @modelcontextprotocol/express. Imports of OAuth types/schemas are rewritten to @modelcontextprotocol/core; AuthInfo is re-exported from core for structural compatibility with v2 request-handler context. Minimal edits vs v1 source: override modifiers and noUncheckedIndexedAccess fixes to satisfy the v2 strict tsconfig; behaviour is unchanged.
1 parent 9ed62fe commit 7cac712

29 files changed

+1943
-17
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/server-auth-legacy': patch
3+
---
4+
5+
Add `@modelcontextprotocol/server-auth-legacy`, a deprecated, frozen copy of the v1 SDK's `src/server/auth/` Authorization Server helpers (`mcpAuthRouter`, `ProxyOAuthServerProvider`, OAuth handlers/middleware/errors). Provided solely for v1 → v2 migration; new code should use a dedicated IdP plus the Resource Server helpers in `@modelcontextprotocol/express`.

.changeset/pre.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@modelcontextprotocol/hono": "2.0.0-alpha.0",
1818
"@modelcontextprotocol/node": "2.0.0-alpha.0",
1919
"@modelcontextprotocol/server": "2.0.0-alpha.0",
20+
"@modelcontextprotocol/server-auth-legacy": "2.0.0-alpha.2",
2021
"@modelcontextprotocol/test-conformance": "2.0.0-alpha.0",
2122
"@modelcontextprotocol/test-helpers": "2.0.0-alpha.0",
2223
"@modelcontextprotocol/test-integration": "2.0.0-alpha.0"

docs/faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ For production use, you can either:
6969

7070
The SDK ships several runnable server examples under `examples/server/src`. Start from the server examples index in [`examples/server/README.md`](../examples/server/README.md) and the entry-point quick start in the root [`README.md`](../README.md).
7171

72-
### Why did we remove `server` auth exports?
72+
### Where are the server auth helpers?
7373

74-
Server authentication & authorization is outside of the scope of the SDK, and the recommendation is to use packages that focus on this area specifically (or a full-fledged Authorization Server for those who use such). Example packages provide an example with `better-auth`.
74+
All v1 `server/auth/*` exports are available in the deprecated `@modelcontextprotocol/server-auth-legacy` package (frozen v1 copy). New code should use a dedicated IdP/OAuth library; example packages provide a demo with `better-auth`.
7575

7676
### Why did we remove `server` SSE transport?
7777

docs/migration-SKILL.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Replace all `@modelcontextprotocol/sdk/...` imports using this table.
5454
| `@modelcontextprotocol/sdk/server/stdio.js` | `@modelcontextprotocol/server` |
5555
| `@modelcontextprotocol/sdk/server/streamableHttp.js` | `@modelcontextprotocol/node` (class renamed to `NodeStreamableHTTPServerTransport`) OR `@modelcontextprotocol/server` (web-standard `WebStandardStreamableHTTPServerTransport` for Cloudflare Workers, Deno, etc.) |
5656
| `@modelcontextprotocol/sdk/server/sse.js` | REMOVED (migrate to Streamable HTTP) |
57-
| `@modelcontextprotocol/sdk/server/auth/*` | REMOVED (use external auth library) |
57+
| `@modelcontextprotocol/sdk/server/auth/*` | `@modelcontextprotocol/server-auth-legacy` (deprecated; frozen v1 copy) |
5858
| `@modelcontextprotocol/sdk/server/middleware.js` | `@modelcontextprotocol/express` (signature changed, see section 8) |
5959

6060
### Types / shared imports
@@ -319,8 +319,7 @@ new URL(ctx.http?.req?.url).searchParams.get('debug')
319319

320320
### Server-side auth
321321

322-
All server OAuth exports removed: `mcpAuthRouter`, `OAuthServerProvider`, `OAuthTokenVerifier`, `requireBearerAuth`, `authenticateClient`, `ProxyOAuthServerProvider`, `allowedMethods`, and associated types. Use an external auth library (e.g., `better-auth`). See
323-
`examples/server/src/` for demos.
322+
All v1 `server/auth/*` exports (`mcpAuthRouter`, `OAuthServerProvider`, `OAuthTokenVerifier`, `requireBearerAuth`, `mcpAuthMetadataRouter`, `authenticateClient`, `ProxyOAuthServerProvider`, `allowedMethods`, etc.) are available in the deprecated `@modelcontextprotocol/server-auth-legacy` package. New code should use an external IdP/OAuth library. See `examples/server/src/` for demos.
324323

325324
### Host header validation (Express)
326325

@@ -502,6 +501,6 @@ Access validators explicitly:
502501
6. Replace plain header objects with `new Headers({...})` and bracket access (`headers['x']`) with `.get()` calls per section 7
503502
7. If using `hostHeaderValidation` from server, update import and signature per section 8
504503
8. If using server SSE transport, migrate to Streamable HTTP
505-
9. If using server auth from the SDK, migrate to an external auth library
504+
9. If using server auth from the SDK, import from `@modelcontextprotocol/server-auth-legacy` (deprecated; frozen v1 copy)
506505
10. If relying on `listTools()`/`listPrompts()`/etc. throwing on missing capabilities, set `enforceStrictCapabilities: true`
507506
11. Verify: build with `tsc` / run tests

docs/migration.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
130130
const transport = new StreamableHTTPClientTransport(new URL('http://localhost:3000/mcp'));
131131
```
132132

133-
### Server auth removed
133+
### Server auth moved
134134

135-
Server-side OAuth/auth has been removed entirely from the SDK. This includes `mcpAuthRouter`, `OAuthServerProvider`, `OAuthTokenVerifier`, `requireBearerAuth`, `authenticateClient`, `ProxyOAuthServerProvider`, `allowedMethods`, and all associated types.
135+
The full v1 `server/auth/*` tree (including `mcpAuthRouter`, `ProxyOAuthServerProvider`, `requireBearerAuth`, `mcpAuthMetadataRouter`, `OAuthTokenVerifier`, `authenticateClient`, `allowedMethods`, and associated types) is available as a frozen v1 copy in the deprecated `@modelcontextprotocol/server-auth-legacy` package.
136136

137-
Use a dedicated auth library (e.g., `better-auth`) or a full Authorization Server instead. See the [examples](../examples/server/src/) for a working demo with `better-auth`.
137+
New code should use a dedicated IdP/OAuth library (or `better-auth` per the [examples](../examples/server/src/)) instead of running an Authorization Server from the SDK.
138138

139139
Note: `AuthInfo` has moved from `server/auth/types.ts` to the core types and is now re-exported by `@modelcontextprotocol/client` and `@modelcontextprotocol/server`.
140140

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# @modelcontextprotocol/server-auth-legacy
2+
3+
<!-- prettier-ignore -->
4+
> [!WARNING]
5+
> **Deprecated.** This package is a frozen copy of the v1 SDK's `src/server/auth/` Authorization Server helpers (`mcpAuthRouter`, `ProxyOAuthServerProvider`, etc.). It exists solely to ease migration from `@modelcontextprotocol/sdk` v1 and will not receive new features or non-critical bug fixes.
6+
7+
The v2 SDK no longer ships an OAuth Authorization Server implementation. MCP servers are Resource Servers; running your own AS is an anti-pattern for most deployments.
8+
9+
## Migration
10+
11+
- **Resource Server glue** (`requireBearerAuth`, `mcpAuthMetadataRouter`, Protected Resource Metadata): use the first-class helpers in `@modelcontextprotocol/express`.
12+
- **Authorization Server**: use a dedicated IdP (Auth0, Keycloak, Okta, etc.) or a purpose-built OAuth library.
13+
14+
## Usage (legacy)
15+
16+
```ts
17+
import express from 'express';
18+
import { mcpAuthRouter, ProxyOAuthServerProvider } from '@modelcontextprotocol/server-auth-legacy';
19+
20+
const app = express();
21+
app.use(mcpAuthRouter({ provider, issuerUrl: new URL('https://example.com') }));
22+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @ts-check
2+
3+
import baseConfig from '@modelcontextprotocol/eslint-config';
4+
5+
export default [
6+
...baseConfig,
7+
{
8+
settings: {
9+
'import/internal-regex': '^@modelcontextprotocol/core'
10+
}
11+
}
12+
];
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "@modelcontextprotocol/server-auth-legacy",
3+
"private": false,
4+
"version": "2.0.0-alpha.2",
5+
"description": "Frozen v1 OAuth Authorization Server helpers (mcpAuthRouter, ProxyOAuthServerProvider) for the Model Context Protocol TypeScript SDK. Deprecated; use a dedicated OAuth server in production.",
6+
"deprecated": "The MCP SDK no longer ships an Authorization Server implementation. This package is a frozen copy of the v1 src/server/auth helpers for migration purposes only and will not receive new features. Use a dedicated OAuth Authorization Server (e.g. an IdP) and the Resource Server helpers in @modelcontextprotocol/express instead.",
7+
"license": "MIT",
8+
"author": "Anthropic, PBC (https://anthropic.com)",
9+
"homepage": "https://modelcontextprotocol.io",
10+
"bugs": "https://github.com/modelcontextprotocol/typescript-sdk/issues",
11+
"type": "module",
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/modelcontextprotocol/typescript-sdk.git"
15+
},
16+
"engines": {
17+
"node": ">=20"
18+
},
19+
"keywords": [
20+
"modelcontextprotocol",
21+
"mcp",
22+
"oauth",
23+
"express",
24+
"legacy"
25+
],
26+
"types": "./dist/index.d.mts",
27+
"exports": {
28+
".": {
29+
"types": "./dist/index.d.mts",
30+
"import": "./dist/index.mjs"
31+
}
32+
},
33+
"files": [
34+
"dist"
35+
],
36+
"scripts": {
37+
"typecheck": "tsgo -p tsconfig.json --noEmit",
38+
"build": "tsdown",
39+
"build:watch": "tsdown --watch",
40+
"prepack": "npm run build",
41+
"lint": "eslint src/ && prettier --ignore-path ../../.prettierignore --check .",
42+
"lint:fix": "eslint src/ --fix && prettier --ignore-path ../../.prettierignore --write .",
43+
"check": "pnpm run typecheck && pnpm run lint",
44+
"test": "vitest run",
45+
"test:watch": "vitest"
46+
},
47+
"dependencies": {
48+
"cors": "catalog:runtimeServerOnly",
49+
"express-rate-limit": "^8.2.1",
50+
"pkce-challenge": "catalog:runtimeShared",
51+
"zod": "catalog:runtimeShared"
52+
},
53+
"peerDependencies": {
54+
"express": "catalog:runtimeServerOnly"
55+
},
56+
"devDependencies": {
57+
"@modelcontextprotocol/core": "workspace:^",
58+
"@modelcontextprotocol/tsconfig": "workspace:^",
59+
"@modelcontextprotocol/vitest-config": "workspace:^",
60+
"@modelcontextprotocol/eslint-config": "workspace:^",
61+
"@eslint/js": "catalog:devTools",
62+
"@types/cors": "catalog:devTools",
63+
"@types/express": "catalog:devTools",
64+
"@types/express-serve-static-core": "catalog:devTools",
65+
"@types/supertest": "catalog:devTools",
66+
"@typescript/native-preview": "catalog:devTools",
67+
"eslint": "catalog:devTools",
68+
"eslint-config-prettier": "catalog:devTools",
69+
"eslint-plugin-n": "catalog:devTools",
70+
"express": "catalog:runtimeServerOnly",
71+
"prettier": "catalog:devTools",
72+
"supertest": "catalog:devTools",
73+
"tsdown": "catalog:devTools",
74+
"typescript": "catalog:devTools",
75+
"typescript-eslint": "catalog:devTools",
76+
"vitest": "catalog:devTools"
77+
}
78+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { OAuthClientInformationFull } from '@modelcontextprotocol/core';
2+
3+
/**
4+
* Stores information about registered OAuth clients for this server.
5+
*/
6+
export interface OAuthRegisteredClientsStore {
7+
/**
8+
* Returns information about a registered client, based on its ID.
9+
*/
10+
getClient(clientId: string): OAuthClientInformationFull | undefined | Promise<OAuthClientInformationFull | undefined>;
11+
12+
/**
13+
* Registers a new client with the server. The client ID and secret will be automatically generated by the library. A modified version of the client information can be returned to reflect specific values enforced by the server.
14+
*
15+
* NOTE: Implementations should NOT delete expired client secrets in-place. Auth middleware provided by this library will automatically check the `client_secret_expires_at` field and reject requests with expired secrets. Any custom logic for authenticating clients should check the `client_secret_expires_at` field as well.
16+
*
17+
* If unimplemented, dynamic client registration is unsupported.
18+
*/
19+
registerClient?(
20+
client: Omit<OAuthClientInformationFull, 'client_id' | 'client_id_issued_at'>
21+
): OAuthClientInformationFull | Promise<OAuthClientInformationFull>;
22+
}

0 commit comments

Comments
 (0)