Skip to content

Commit 44e7b26

Browse files
committed
fix: address PR #2088 review feedback
- Update `.changeset/cfworker-out-of-barrel.md` to say the `./validators/cf-worker` subpath was removed (was: "reachable only via" that subpath, which is no longer true). - Replace the impossible `import { fromJsonSchema, AjvJsonSchemaValidator } from '@modelcontextprotocol/core'` sample in `.changeset/support-standard-json-schema.md` with `fromJsonSchema` from `@modelcontextprotocol/server` and no explicit validator. - Reword `@default` JSDoc on `ServerOptions`/`ClientOptions` `jsonSchemaValidator` from internal class names to backend names (AJV-backed / `@cfworker/json-schema`-backed) — these lines surface in published `.d.mts` IDE hover. - Rework `.changeset/workerd-shim-vendors-cfworker.md` from a consumer vantage point: drop `core/public` references, state explicitly that the `./validators/cf-worker` subpath was removed and that the validator classes are no longer exported from client/server (not even as types). - Delete the duplicate `describe('fromJsonSchema with default validator (server wrapper)')` block in `test/integration/test/standardSchema.test.ts`; its two tests are strict subsets of the preceding `Raw JSON Schema via fromJsonSchema` block (explicit-validator coverage already lives in the new `jsonSchemaValidatorOverride.test.ts` files). - Document the `./validators/cf-worker` subpath removal in `docs/migration.md` and `docs/migration-SKILL.md` per repo policy for breaking changes.
1 parent 1436a5a commit 44e7b26

8 files changed

Lines changed: 12 additions & 49 deletions

File tree

.changeset/cfworker-out-of-barrel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
'@modelcontextprotocol/client': patch
44
---
55

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` 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), so consumers that don't opt into it no longer ship that code. The interim `@modelcontextprotocol/{server,client}/validators/cf-worker` subpath this introduced has been removed in a follow-up — the runtime shim is now the only entry point.

.changeset/support-standard-json-schema.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ server.registerTool('greet', {
2121
For raw JSON Schema (e.g. TypeBox output), use the new `fromJsonSchema` adapter:
2222

2323
```typescript
24-
import { fromJsonSchema, AjvJsonSchemaValidator } from '@modelcontextprotocol/core';
24+
import { fromJsonSchema } from '@modelcontextprotocol/server';
2525

2626
server.registerTool('greet', {
27-
inputSchema: fromJsonSchema({ type: 'object', properties: { name: { type: 'string' } } }, new AjvJsonSchemaValidator())
27+
inputSchema: fromJsonSchema({ type: 'object', properties: { name: { type: 'string' } } })
2828
}, handler);
2929
```
3030

.changeset/workerd-shim-vendors-cfworker.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
'@modelcontextprotocol/server': patch
55
---
66

7-
Make validator backends symmetrical in core and bundle automatic defaults in client/server runtime shims.
7+
Bundle automatic JSON Schema validator defaults in `@modelcontextprotocol/client` and `@modelcontextprotocol/server` runtime shims.
88

9-
Core no longer re-exports concrete validator providers as runtime values from the root/public barrels. AJV/AJV formats and `@cfworker/json-schema` are optional peer backends behind explicit core validator provider subpaths, used internally by client/server shims.
9+
Client/server select defaults automatically based on the runtime: Node shims use AJV, while browser/workerd shims use `@cfworker/json-schema`. Those backends are bundled into the shim chunks that select them, so consumers do not need to install validator packages or import explicit validators for default behavior. Advanced users can still pass their own `jsonSchemaValidator` interface implementation.
1010

11-
Client/server continue to select defaults automatically: Node shims use AJV, while browser/workerd shims use `@cfworker/json-schema`. Those backends are bundled into the shim chunks that select them, so users do not need to install validator packages or import explicit validators for default behavior. Advanced users can still pass their own `jsonSchemaValidator` implementation.
12-
13-
`AjvJsonSchemaValidator` and `CfWorkerJsonSchemaValidator` are now `@internal` and no longer surface from `@modelcontextprotocol/core/public` (not even as types). The `jsonSchemaValidator` interface remains the public extension point for custom validators. Example JSDoc snippets no longer demonstrate direct validator instantiation.
11+
The `@modelcontextprotocol/{client,server}/validators/cf-worker` subpath export has been removed — there is no longer any public entry point for the SDK's built-in validator classes. `AjvJsonSchemaValidator` and `CfWorkerJsonSchemaValidator` are now `@internal` and no longer exported from `@modelcontextprotocol/client` or `@modelcontextprotocol/server` (not even as types). The `jsonSchemaValidator` interface remains the public extension point for custom validators, and example JSDoc snippets no longer demonstrate direct validator instantiation.

docs/migration-SKILL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ Validator behavior:
531531

532532
- Do not add validator imports for normal migrations.
533533
- Do not install `ajv`, `ajv-formats`, or `@cfworker/json-schema`; client/server bundle the runtime-selected defaults.
534-
- Advanced users may pass `jsonSchemaValidator: myCustomValidator` with their own validator implementation.
534+
- The SDK's built-in validator classes (`AjvJsonSchemaValidator`, `CfWorkerJsonSchemaValidator`) are not exported from `@modelcontextprotocol/{client,server}` (not even as types). The `@modelcontextprotocol/{client,server}/validators/cf-worker` subpath that existed in v2 pre-releases has been removed.
535+
- Advanced users may pass `jsonSchemaValidator: myCustomValidator` with their own implementation of the `jsonSchemaValidator` interface.
535536

536537
## 15. Migration Steps (apply in this order)
537538

docs/migration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ const server = new McpServer(
947947
);
948948
```
949949

950+
The SDK's built-in validator classes (`AjvJsonSchemaValidator`, `CfWorkerJsonSchemaValidator`) are not part of the public surface — `@modelcontextprotocol/{client,server}` no longer export them as runtime values or types, and the `@modelcontextprotocol/{client,server}/validators/cf-worker` subpath that briefly existed in v2 pre-releases has been removed. To customise validation, implement the `jsonSchemaValidator` interface yourself and pass your implementation through the option above.
951+
950952
## Unchanged APIs
951953

952954
The following APIs are unchanged between v1 and v2 (only the import paths changed):

packages/client/src/client/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export type ClientOptions = ProtocolOptions & {
161161
* The validator is used to validate structured content returned by tools
162162
* against their declared output schemas.
163163
*
164-
* @default Runtime-selected validator (`AjvJsonSchemaValidator` on Node.js, `CfWorkerJsonSchemaValidator` on browser/workerd runtimes)
164+
* @default Runtime-selected validator (AJV-backed on Node.js, `@cfworker/json-schema`-backed on browser/workerd runtimes)
165165
*/
166166
jsonSchemaValidator?: jsonSchemaValidator;
167167

packages/server/src/server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export type ServerOptions = ProtocolOptions & {
8383
* The validator is used to validate user input returned from elicitation
8484
* requests against the requested schema.
8585
*
86-
* @default Runtime-selected validator (`AjvJsonSchemaValidator` on Node.js, `CfWorkerJsonSchemaValidator` on browser/workerd runtimes)
86+
* @default Runtime-selected validator (AJV-backed on Node.js, `@cfworker/json-schema`-backed on browser/workerd runtimes)
8787
*/
8888
jsonSchemaValidator?: jsonSchemaValidator;
8989
};

test/integration/test/standardSchema.test.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -428,44 +428,6 @@ describe('Standard Schema Support', () => {
428428
});
429429
});
430430

431-
describe('fromJsonSchema with default validator (server wrapper)', () => {
432-
test('should use runtime-appropriate default validator when none is provided', async () => {
433-
const inputSchema = serverFromJsonSchema<{ name: string }>({
434-
type: 'object',
435-
properties: { name: { type: 'string' } },
436-
required: ['name']
437-
});
438-
439-
mcpServer.registerTool('greet-default', { inputSchema }, async ({ name }) => ({
440-
content: [{ type: 'text', text: `Hello, ${name}!` }]
441-
}));
442-
443-
await connectClientAndServer();
444-
445-
const result = await client.request({ method: 'tools/call', params: { name: 'greet-default', arguments: { name: 'World' } } });
446-
expect((result.content[0] as TextContent).text).toBe('Hello, World!');
447-
});
448-
449-
test('should reject invalid input with default validator', async () => {
450-
const inputSchema = serverFromJsonSchema({ type: 'object', properties: { count: { type: 'number' } }, required: ['count'] });
451-
452-
mcpServer.registerTool('double-default', { inputSchema }, async args => {
453-
const { count } = args as { count: number };
454-
return { content: [{ type: 'text', text: `${count * 2}` }] };
455-
});
456-
457-
await connectClientAndServer();
458-
459-
const result = await client.request({
460-
method: 'tools/call',
461-
params: { name: 'double-default', arguments: { count: 'not a number' } }
462-
});
463-
expect(result.isError).toBe(true);
464-
const errorText = (result.content[0] as TextContent).text;
465-
expect(errorText).toContain('Input validation error');
466-
});
467-
});
468-
469431
describe('Prompt completions with Zod completable', () => {
470432
// Note: completable() is currently Zod-specific
471433
// These tests verify that Zod schemas with completable still work

0 commit comments

Comments
 (0)