-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(server-auth-legacy): add frozen v1 Authorization-Server package #1908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7cac712
cee3ec3
e7e1b52
126b89a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@modelcontextprotocol/server-auth-legacy': patch | ||
| --- | ||
|
|
||
| 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`. | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,7 +54,7 @@ | |||||||||||||||||||
| | `@modelcontextprotocol/sdk/server/stdio.js` | `@modelcontextprotocol/server` | | ||||||||||||||||||||
| | `@modelcontextprotocol/sdk/server/streamableHttp.js` | `@modelcontextprotocol/node` (class renamed to `NodeStreamableHTTPServerTransport`) OR `@modelcontextprotocol/server` (web-standard `WebStandardStreamableHTTPServerTransport` for Cloudflare Workers, Deno, etc.) | | ||||||||||||||||||||
| | `@modelcontextprotocol/sdk/server/sse.js` | REMOVED (migrate to Streamable HTTP) | | ||||||||||||||||||||
| | `@modelcontextprotocol/sdk/server/auth/*` | REMOVED (use external auth library) | | ||||||||||||||||||||
| | `@modelcontextprotocol/sdk/server/auth/*` | `@modelcontextprotocol/server-auth-legacy` (deprecated; frozen v1 copy) | | ||||||||||||||||||||
| | `@modelcontextprotocol/sdk/server/middleware.js` | `@modelcontextprotocol/express` (signature changed, see section 8) | | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ### Types / shared imports | ||||||||||||||||||||
|
|
@@ -319,8 +319,7 @@ | |||||||||||||||||||
|
|
||||||||||||||||||||
| ### Server-side auth | ||||||||||||||||||||
|
|
||||||||||||||||||||
| 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 | ||||||||||||||||||||
| `examples/server/src/` for demos. | ||||||||||||||||||||
| 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. | ||||||||||||||||||||
|
Check failure on line 322 in docs/migration-SKILL.md
|
||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 The §"OAuth error consolidation" table (migration-SKILL.md ~L167-204, migration.md ~L725-754) still says Extended reasoning...What's wrongThis PR's commit 7cac712 rewrote three locations in However, the pre-existing §"OAuth error consolidation" table (migration-SKILL.md section 5, ~L167-204; migration.md §"OAuth error refactoring", ~L725-754) was left unchanged. It still flatly states:
In v1 these subclasses were defined only in Why this is a runtime trap, not just a prose nitThere are now two distinct
A provider that throws core's Step-by-step proof
Expected (v1 behavior): 400 The same applies to Why this was introduced by this PRBefore 7cac712, migration-SKILL.md L57 said Why nothing else catches it
FixEither or both of:
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| ### Host header validation (Express) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -502,6 +501,6 @@ | |||||||||||||||||||
| 6. Replace plain header objects with `new Headers({...})` and bracket access (`headers['x']`) with `.get()` calls per section 7 | ||||||||||||||||||||
| 7. If using `hostHeaderValidation` from server, update import and signature per section 8 | ||||||||||||||||||||
| 8. If using server SSE transport, migrate to Streamable HTTP | ||||||||||||||||||||
| 9. If using server auth from the SDK, migrate to an external auth library | ||||||||||||||||||||
| 9. If using server auth from the SDK, import from `@modelcontextprotocol/server-auth-legacy` (deprecated; frozen v1 copy) | ||||||||||||||||||||
| 10. If relying on `listTools()`/`listPrompts()`/etc. throwing on missing capabilities, set `enforceStrictCapabilities: true` | ||||||||||||||||||||
| 11. Verify: build with `tsc` / run tests | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # @modelcontextprotocol/server-auth-legacy | ||
|
|
||
| <!-- prettier-ignore --> | ||
| > [!WARNING] | ||
| > **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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Migration | ||
|
|
||
| - **Resource Server glue** (`requireBearerAuth`, `mcpAuthMetadataRouter`, Protected Resource Metadata): use the first-class helpers in `@modelcontextprotocol/express`. | ||
| - **Authorization Server**: use a dedicated IdP (Auth0, Keycloak, Okta, etc.) or a purpose-built OAuth library. | ||
|
|
||
| ## Usage (legacy) | ||
|
|
||
| ```ts | ||
| import express from 'express'; | ||
| import { mcpAuthRouter, ProxyOAuthServerProvider } from '@modelcontextprotocol/server-auth-legacy'; | ||
|
|
||
| const app = express(); | ||
| app.use(mcpAuthRouter({ provider, issuerUrl: new URL('https://example.com') })); | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // @ts-check | ||
|
|
||
| import baseConfig from '@modelcontextprotocol/eslint-config'; | ||
|
|
||
| export default [ | ||
| ...baseConfig, | ||
| { | ||
| settings: { | ||
| 'import/internal-regex': '^@modelcontextprotocol/core' | ||
| } | ||
| } | ||
| ]; |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||||||||
| { | ||||||||||||
| "name": "@modelcontextprotocol/server-auth-legacy", | ||||||||||||
| "private": false, | ||||||||||||
| "version": "2.0.0-alpha.2", | ||||||||||||
|
felixweinberger marked this conversation as resolved.
|
||||||||||||
| "description": "Frozen v1 OAuth Authorization Server helpers (mcpAuthRouter, ProxyOAuthServerProvider) for the Model Context Protocol TypeScript SDK. Deprecated; use a dedicated OAuth server in production.", | ||||||||||||
| "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.", | ||||||||||||
| "license": "MIT", | ||||||||||||
| "author": "Anthropic, PBC (https://anthropic.com)", | ||||||||||||
| "homepage": "https://modelcontextprotocol.io", | ||||||||||||
| "bugs": "https://github.com/modelcontextprotocol/typescript-sdk/issues", | ||||||||||||
| "type": "module", | ||||||||||||
| "repository": { | ||||||||||||
| "type": "git", | ||||||||||||
| "url": "git+https://github.com/modelcontextprotocol/typescript-sdk.git" | ||||||||||||
| }, | ||||||||||||
| "engines": { | ||||||||||||
| "node": ">=20" | ||||||||||||
| }, | ||||||||||||
| "keywords": [ | ||||||||||||
| "modelcontextprotocol", | ||||||||||||
| "mcp", | ||||||||||||
| "oauth", | ||||||||||||
| "express", | ||||||||||||
| "legacy" | ||||||||||||
| ], | ||||||||||||
| "types": "./dist/index.d.mts", | ||||||||||||
| "exports": { | ||||||||||||
| ".": { | ||||||||||||
| "types": "./dist/index.d.mts", | ||||||||||||
| "import": "./dist/index.mjs" | ||||||||||||
| } | ||||||||||||
| }, | ||||||||||||
| "files": [ | ||||||||||||
| "dist" | ||||||||||||
| ], | ||||||||||||
| "scripts": { | ||||||||||||
| "typecheck": "tsgo -p tsconfig.json --noEmit", | ||||||||||||
| "build": "tsdown", | ||||||||||||
| "build:watch": "tsdown --watch", | ||||||||||||
| "prepack": "npm run build", | ||||||||||||
| "lint": "eslint src/ && prettier --ignore-path ../../.prettierignore --check .", | ||||||||||||
| "lint:fix": "eslint src/ --fix && prettier --ignore-path ../../.prettierignore --write .", | ||||||||||||
| "check": "pnpm run typecheck && pnpm run lint", | ||||||||||||
| "test": "vitest run", | ||||||||||||
| "test:watch": "vitest" | ||||||||||||
| }, | ||||||||||||
| "dependencies": { | ||||||||||||
| "cors": "catalog:runtimeServerOnly", | ||||||||||||
| "express-rate-limit": "^8.2.1", | ||||||||||||
| "pkce-challenge": "catalog:runtimeShared", | ||||||||||||
| "zod": "catalog:runtimeShared" | ||||||||||||
| }, | ||||||||||||
| "peerDependencies": { | ||||||||||||
| "express": "catalog:runtimeServerOnly" | ||||||||||||
| }, | ||||||||||||
| "peerDependenciesMeta": { | ||||||||||||
| "express": { | ||||||||||||
| "optional": true | ||||||||||||
| } | ||||||||||||
| }, | ||||||||||||
|
Check failure on line 60 in packages/server-auth-legacy/package.json
|
||||||||||||
|
Comment on lines
+56
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 🔴 126b89a marks Extended reasoning...What changedCommit 126b89a (the most recent commit on this PR, pushed after the last review round) added to "peerDependenciesMeta": {
"express": {
"optional": true
}
}This marks the Why it's wrongThe optional-peer pattern is only valid when either (1) the import of that peer is lazy/conditional, or (2) some subset of the package's API is reachable without it. Neither holds here:
Additionally, Step-by-step proof
So the only effect of 126b89a is to remove the helpful install-time signal and replace it with a runtime crash. Repo precedentSibling FixRevert 126b89a — delete the |
||||||||||||
| "devDependencies": { | ||||||||||||
| "@modelcontextprotocol/core": "workspace:^", | ||||||||||||
| "@modelcontextprotocol/tsconfig": "workspace:^", | ||||||||||||
| "@modelcontextprotocol/vitest-config": "workspace:^", | ||||||||||||
| "@modelcontextprotocol/eslint-config": "workspace:^", | ||||||||||||
| "@eslint/js": "catalog:devTools", | ||||||||||||
| "@types/cors": "catalog:devTools", | ||||||||||||
| "@types/express": "catalog:devTools", | ||||||||||||
| "@types/express-serve-static-core": "catalog:devTools", | ||||||||||||
| "@types/supertest": "catalog:devTools", | ||||||||||||
| "@typescript/native-preview": "catalog:devTools", | ||||||||||||
| "eslint": "catalog:devTools", | ||||||||||||
| "eslint-config-prettier": "catalog:devTools", | ||||||||||||
| "eslint-plugin-n": "catalog:devTools", | ||||||||||||
| "express": "catalog:runtimeServerOnly", | ||||||||||||
| "prettier": "catalog:devTools", | ||||||||||||
| "supertest": "catalog:devTools", | ||||||||||||
| "tsdown": "catalog:devTools", | ||||||||||||
| "typescript": "catalog:devTools", | ||||||||||||
| "typescript-eslint": "catalog:devTools", | ||||||||||||
| "vitest": "catalog:devTools" | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import type { OAuthClientInformationFull } from '@modelcontextprotocol/core'; | ||
|
|
||
| /** | ||
| * Stores information about registered OAuth clients for this server. | ||
| */ | ||
| export interface OAuthRegisteredClientsStore { | ||
| /** | ||
| * Returns information about a registered client, based on its ID. | ||
| */ | ||
| getClient(clientId: string): OAuthClientInformationFull | undefined | Promise<OAuthClientInformationFull | undefined>; | ||
|
|
||
| /** | ||
| * 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. | ||
| * | ||
| * 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. | ||
| * | ||
| * If unimplemented, dynamic client registration is unsupported. | ||
| */ | ||
| registerClient?( | ||
| client: Omit<OAuthClientInformationFull, 'client_id' | 'client_id_issued_at'> | ||
| ): OAuthClientInformationFull | Promise<OAuthClientInformationFull>; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.