-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): restore v1 Zod-schema overloads on setRequestHandler/setNotificationHandler/request #1891
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
Open
felixweinberger
wants to merge
12
commits into
main
Choose a base branch
from
fweinberger/protocol-concrete
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(core): restore v1 Zod-schema overloads on setRequestHandler/setNotificationHandler/request #1891
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5553342
feat(core): restore v1 Zod-schema overloads on setRequestHandler/setN…
felixweinberger cc7bc8b
fix: address review — callTool(params, undefined, opts) drops opts; m…
felixweinberger 3bd5454
docs: mark v1-compat schema-arg overloads @deprecated; lint:fix prettier
felixweinberger 0a932fe
fix: schema-arg setRequestHandler bypassed per-method wrapping in Cli…
felixweinberger c10349d
fix(core): guard spec-schema parse for non-spec methods in handler re…
felixweinberger dd2dc3c
docs(core): align request<T>(req,resultSchema) @deprecated wording wi…
felixweinberger 52843d3
feat(core): mcpReq.send accepts (req, resultSchema, opts) for non-spe…
felixweinberger dbba3a7
refactor(core): un-deprecate schema-arg overloads; inline _registerCo…
felixweinberger c1f6778
docs: align mcpReq.send() schema-param wording with 260fae6b overload
felixweinberger 6e630f4
fix(examples,docs): spawn server via tsx; reword §9 intro to reflect …
felixweinberger ddd6776
fix: revert out-of-scope SdkError, add ctx.mcpReq.send to changeset +…
felixweinberger d2e046d
test(server): make schema-parity test reach the wrapper; use stderr i…
felixweinberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@modelcontextprotocol/client': minor | ||
| '@modelcontextprotocol/server': minor | ||
| --- | ||
|
|
||
| `setRequestHandler`/`setNotificationHandler` accept the v1 `(ZodSchema, handler)` form as a first-class alternative to `(methodString, handler)`. `request()` and `ctx.mcpReq.send()` accept an explicit result schema (`request(req, resultSchema, options?)`) and have method-keyed return types for spec methods. `callTool(params, resultSchema?)` accepts the v1 schema arg (ignored). `removeRequestHandler`/`removeNotificationHandler`/`assertCanSetRequestHandler` accept any method string. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Calling vendor-specific (non-spec) JSON-RPC methods from a `Client`. | ||
| * | ||
| * - Send a custom request: `client.request({ method, params }, resultSchema)` | ||
| * - Send a custom notification: `client.notification({ method, params })` | ||
| * - Receive a custom notification: `client.setNotificationHandler(ZodSchemaWithMethodLiteral, handler)` | ||
| * | ||
| * Pair with the server in examples/server/src/customMethodExample.ts. | ||
| */ | ||
|
|
||
| import { Client, StdioClientTransport } from '@modelcontextprotocol/client'; | ||
| import { z } from 'zod'; | ||
|
|
||
| const SearchResult = z.object({ hits: z.array(z.string()) }); | ||
|
|
||
| const ProgressNotification = z.object({ | ||
| method: z.literal('acme/searchProgress'), | ||
| params: z.object({ stage: z.string(), pct: z.number() }) | ||
| }); | ||
|
|
||
| const client = new Client({ name: 'custom-method-client', version: '1.0.0' }, { capabilities: {} }); | ||
|
|
||
| client.setNotificationHandler(ProgressNotification, n => { | ||
| console.log(`[client] progress: ${n.params.stage} ${n.params.pct}%`); | ||
| }); | ||
|
|
||
| await client.connect(new StdioClientTransport({ command: 'npx', args: ['tsx', '../server/src/customMethodExample.ts'] })); | ||
|
|
||
| const r = await client.request({ method: 'acme/search', params: { query: 'widgets' } }, SearchResult); | ||
| console.log('[client] hits=' + JSON.stringify(r.hits)); | ||
|
|
||
| await client.notification({ method: 'acme/tick', params: { n: 1 } }); | ||
| await client.notification({ method: 'acme/tick', params: { n: 2 } }); | ||
|
|
||
| await client.close(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.