Skip to content

Commit f7e391b

Browse files
feat(compat): add @modelcontextprotocol/server/zod-schemas subpath
Re-exports the internal *Schema Zod constants (CallToolRequestSchema, JSONRPCMessageSchema, etc.) from a deprecated /zod-schemas subpath so v1 code that imported schemas from @modelcontextprotocol/sdk/types.js has a single drop-in target. - packages/server/src/zodSchemas.ts: re-export barrel (deprecated module) - packages/server/package.json: ./zod-schemas exports entry - packages/server/tsdown.config.ts: build entry + dts path mapping - packages/server/tsconfig.json: path mappings for core/schemas and the self-reference subpath - packages/core/package.json: internal ./schemas subpath (core is private, consumed only by sibling packages) - compat test asserting the import resolves and schemas parse The schemas remain an internal implementation detail; their Zod major version is not covered by semver. Subpath will be removed in v3.
1 parent 9ed62fe commit f7e391b

9 files changed

Lines changed: 80 additions & 5 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modelcontextprotocol/server': patch
3+
---
4+
5+
Add `@modelcontextprotocol/server/zod-schemas` subpath for v1 compatibility
6+
7+
Re-exports the `*Schema` Zod constants (e.g. `CallToolRequestSchema`, `JSONRPCMessageSchema`) and the `getRequestSchema(method)` / `getResultSchema(method)` / `getNotificationSchema(method)` lookup helpers, so v1 code that imported schemas from `@modelcontextprotocol/sdk/types.js` can be pointed at a single subpath. These are Zod schemas; their TS type may change with internal Zod upgrades. Prefer `specTypeSchema()` for runtime validation.

docs/migration-SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Notes:
9898
| `StreamableHTTPError` | REMOVED (use `SdkError` with `SdkErrorCode.ClientHttp*`) |
9999
| `WebSocketClientTransport` | REMOVED (use `StreamableHTTPClientTransport` or `StdioClientTransport`) |
100100

101-
All other **type** symbols from `@modelcontextprotocol/sdk/types.js` retain their original names. **Zod schemas** (e.g., `CallToolResultSchema`, `ListToolsResultSchema`) are no longer part of the public API — they are internal to the SDK. For runtime validation, use type guard functions like `isCallToolResult` instead of `CallToolResultSchema.safeParse()`.
101+
All other **type** symbols from `@modelcontextprotocol/sdk/types.js` retain their original names. **Zod schemas** (e.g., `CallToolResultSchema`, `ListToolsResultSchema`) are not exported from the package root; for runtime validation prefer type guard functions like `isCallToolResult` or `specTypeSchema()`. For v1 compatibility the schemas are available from the `@modelcontextprotocol/server/zod-schemas` subpath.
102102

103103
### Error class changes
104104

packages/core/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"./public": {
3333
"types": "./src/exports/public/index.ts",
3434
"import": "./src/exports/public/index.ts"
35+
},
36+
"./schemas": {
37+
"types": "./src/types/schemas.ts",
38+
"import": "./src/types/schemas.ts"
3539
}
3640
},
3741
"scripts": {

packages/server/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"types": "./dist/index.d.mts",
2525
"import": "./dist/index.mjs"
2626
},
27+
"./zod-schemas": {
28+
"types": "./dist/zodSchemas.d.mts",
29+
"import": "./dist/zodSchemas.mjs"
30+
},
2731
"./validators/cf-worker": {
2832
"types": "./dist/validators/cfWorker.d.mts",
2933
"import": "./dist/validators/cfWorker.mjs"

packages/server/src/zodSchemas.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* v1-compat re-export of all protocol Zod schemas.
3+
*
4+
* Prefer {@linkcode specTypeSchema} for runtime validation. These are Zod
5+
* schemas; their TS type may change with internal Zod upgrades.
6+
*
7+
* @deprecated Use `specTypeSchema()` for runtime validation.
8+
* @packageDocumentation
9+
*/
10+
11+
/** @deprecated Use `specTypeSchema()` for runtime validation. */
12+
export * from '@modelcontextprotocol/core/schemas';
13+
14+
/** @deprecated Use `specTypeSchema()` for runtime validation. */
15+
export {
16+
IdJagTokenExchangeResponseSchema,
17+
OAuthClientInformationFullSchema,
18+
OAuthClientInformationSchema,
19+
OAuthClientMetadataSchema,
20+
OAuthClientRegistrationErrorSchema,
21+
OAuthErrorResponseSchema,
22+
OAuthMetadataSchema,
23+
OAuthProtectedResourceMetadataSchema,
24+
OAuthTokenRevocationRequestSchema,
25+
OAuthTokensSchema,
26+
OpenIdProviderDiscoveryMetadataSchema,
27+
OpenIdProviderMetadataSchema,
28+
OptionalSafeUrlSchema,
29+
SafeUrlSchema
30+
} from '@modelcontextprotocol/core';
31+
export {
32+
/** @deprecated Use {@linkcode JSONRPCErrorResponseSchema}. */
33+
JSONRPCErrorResponseSchema as JSONRPCErrorSchema
34+
} from '@modelcontextprotocol/core/schemas';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as z from 'zod/v4';
2+
3+
// Compat: the deprecated `/zod-schemas` subpath re-exports the internal Zod
4+
// schema constants for v1 source compatibility. This test asserts the import
5+
// resolves and the values are usable Zod schemas at runtime.
6+
import { CallToolRequestSchema, JSONRPCMessageSchema, ListToolsResultSchema } from '@modelcontextprotocol/server/zod-schemas';
7+
8+
describe('@modelcontextprotocol/server/zod-schemas (compat subpath)', () => {
9+
it('re-exports Zod schema constants from core', () => {
10+
expect(CallToolRequestSchema).toBeInstanceOf(z.ZodType);
11+
expect(JSONRPCMessageSchema).toBeInstanceOf(z.ZodType);
12+
expect(ListToolsResultSchema).toBeInstanceOf(z.ZodType);
13+
});
14+
15+
it('schemas parse valid spec values', () => {
16+
const parsed = CallToolRequestSchema.parse({
17+
method: 'tools/call',
18+
params: { name: 'echo', arguments: {} }
19+
});
20+
expect(parsed.method).toBe('tools/call');
21+
expect(parsed.params.name).toBe('echo');
22+
});
23+
});

packages/server/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"*": ["./*"],
88
"@modelcontextprotocol/core": ["./node_modules/@modelcontextprotocol/core/src/index.ts"],
99
"@modelcontextprotocol/core/public": ["./node_modules/@modelcontextprotocol/core/src/exports/public/index.ts"],
10+
"@modelcontextprotocol/core/schemas": ["./node_modules/@modelcontextprotocol/core/src/types/schemas.ts"],
1011
"@modelcontextprotocol/test-helpers": ["./node_modules/@modelcontextprotocol/test-helpers/src/index.ts"],
11-
"@modelcontextprotocol/server/_shims": ["./src/shimsNode.ts"]
12+
"@modelcontextprotocol/server/_shims": ["./src/shimsNode.ts"],
13+
"@modelcontextprotocol/server/zod-schemas": ["./src/zodSchemas.ts"]
1214
}
1315
}
1416
}

packages/server/tsdown.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default defineConfig({
44
failOnWarn: 'ci-only',
55
// 1. Entry Points
66
// Directly matches package.json include/exclude globs
7-
entry: ['src/index.ts', 'src/shimsNode.ts', 'src/shimsWorkerd.ts', 'src/validators/cfWorker.ts'],
7+
entry: ['src/index.ts', 'src/zodSchemas.ts', 'src/shimsNode.ts', 'src/shimsWorkerd.ts', 'src/validators/cfWorker.ts'],
88

99
// 2. Output Configuration
1010
format: ['esm'],
@@ -26,7 +26,8 @@ export default defineConfig({
2626
baseUrl: '.',
2727
paths: {
2828
'@modelcontextprotocol/core': ['../core/src/index.ts'],
29-
'@modelcontextprotocol/core/public': ['../core/src/exports/public/index.ts']
29+
'@modelcontextprotocol/core/public': ['../core/src/exports/public/index.ts'],
30+
'@modelcontextprotocol/core/schemas': ['../core/src/types/schemas.ts']
3031
}
3132
}
3233
},

packages/server/typedoc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://typedoc.org/schema.json",
33
"entryPoints": ["src"],
44
"entryPointStrategy": "expand",
5-
"exclude": ["**/*.test.ts", "**/__*__/**"],
5+
"exclude": ["**/*.test.ts", "**/__*__/**", "**/zodSchemas.ts"],
66
"navigation": {
77
"includeGroups": true,
88
"includeCategories": true

0 commit comments

Comments
 (0)