Skip to content

Commit ab8b2ed

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 ab8b2ed

File tree

8 files changed

+73
-4
lines changed

8 files changed

+73
-4
lines changed
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 deprecated `@modelcontextprotocol/server/zod-schemas` subpath for v1 compatibility
6+
7+
Re-exports the internal `*Schema` Zod constants (e.g. `CallToolRequestSchema`, `JSONRPCMessageSchema`) so v1 code that imported them from `@modelcontextprotocol/sdk/types.js` can be pointed at a single subpath. These schemas remain an internal implementation detail; their Zod major version is not covered by semver. The subpath will be removed in v3.

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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @deprecated These Zod schema constants are exported for v1 source compatibility
3+
* only. They are an internal implementation detail and their Zod major version is
4+
* NOT covered by semver. For runtime validation of spec types, use
5+
* {@linkcode specTypeSchema} / {@linkcode isSpecType} from the main entry instead.
6+
* This subpath will be removed in v3.
7+
*/
8+
export {
9+
IdJagTokenExchangeResponseSchema,
10+
OAuthClientInformationFullSchema,
11+
OAuthClientInformationSchema,
12+
OAuthClientMetadataSchema,
13+
OAuthClientRegistrationErrorSchema,
14+
OAuthErrorResponseSchema,
15+
OAuthMetadataSchema,
16+
OAuthProtectedResourceMetadataSchema,
17+
OAuthTokenRevocationRequestSchema,
18+
OAuthTokensSchema,
19+
OpenIdProviderDiscoveryMetadataSchema,
20+
OpenIdProviderMetadataSchema,
21+
OptionalSafeUrlSchema,
22+
SafeUrlSchema
23+
} from '@modelcontextprotocol/core';
24+
export * from '@modelcontextprotocol/core/schemas';
25+
export {
26+
/** @deprecated Use {@linkcode JSONRPCErrorResponseSchema}. Removed in v3. */
27+
JSONRPCErrorResponseSchema as JSONRPCErrorSchema
28+
} 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)