-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(compat): restore McpServer.tool()/.prompt()/.resource() variadic overloads #1900
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
3
commits into
main
Choose a base branch
from
fweinberger/v2-bc-mcpserver-variadic
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.
+257
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b44029f
feat(compat): restore McpServer.tool()/.prompt()/.resource() variadic…
felixweinberger 0dafed3
fix: treat empty object as raw shape (matches v1); drop stale changes…
felixweinberger 1e2946b
fix: zod/v4 import convention; re-export InferRawShape from server index
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
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,5 @@ | ||
| --- | ||
| '@modelcontextprotocol/server': patch | ||
| --- | ||
|
|
||
| Restore `McpServer.tool()`, `.prompt()`, `.resource()` variadic overloads as `@deprecated` v1-compat shims forwarding to `registerTool`/`registerPrompt`/`registerResource`. |
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,74 @@ | ||
| /* eslint-disable @typescript-eslint/no-deprecated */ | ||
| import * as z from 'zod/v4'; | ||
| import { McpServer, ResourceTemplate } from '../../src/server/mcp.js'; | ||
|
|
||
| describe('McpServer v1-compat variadic shims', () => { | ||
| describe('.tool()', () => { | ||
| it('registers with raw-shape schema', () => { | ||
| const server = new McpServer({ name: 't', version: '1' }); | ||
|
|
||
| server.tool('x', { a: z.string() }, ({ a }) => ({ content: [{ type: 'text', text: a }] })); | ||
| server.tool('y', { b: z.number() }, ({ b }) => ({ content: [{ type: 'text', text: String(b) }] })); | ||
|
|
||
| // @ts-expect-error private access for test | ||
| expect(server._registeredTools['x']).toBeDefined(); | ||
| // @ts-expect-error private access for test | ||
| expect(server._registeredTools['y']).toBeDefined(); | ||
| }); | ||
|
|
||
| it('supports (name, description, paramsSchema, annotations, cb) overload', () => { | ||
| const server = new McpServer({ name: 't', version: '1' }); | ||
|
|
||
| const reg = server.tool('x', 'desc', { a: z.string() }, { readOnlyHint: true }, ({ a }) => ({ | ||
| content: [{ type: 'text', text: a }] | ||
| })); | ||
|
|
||
| expect(reg.description).toBe('desc'); | ||
| expect(reg.annotations).toEqual({ readOnlyHint: true }); | ||
| expect(reg.inputSchema).toBeDefined(); | ||
| }); | ||
|
|
||
| it('supports (name, cb) zero-arg overload', () => { | ||
| const server = new McpServer({ name: 't', version: '1' }); | ||
| const reg = server.tool('x', () => ({ content: [{ type: 'text', text: 'ok' }] })); | ||
| expect(reg.inputSchema).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('treats empty object as raw shape, not annotations (matches v1)', () => { | ||
| const server = new McpServer({ name: 't', version: '1' }); | ||
| const reg = server.tool('x', {}, () => ({ content: [{ type: 'text', text: 'ok' }] })); | ||
| expect(reg.inputSchema).toBeDefined(); | ||
| expect(reg.annotations).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.prompt()', () => { | ||
| it('registers with raw-shape argsSchema', () => { | ||
| const server = new McpServer({ name: 't', version: '1' }); | ||
|
|
||
| server.prompt('p1', { topic: z.string() }, ({ topic }) => ({ | ||
| messages: [{ role: 'user', content: { type: 'text', text: topic } }] | ||
| })); | ||
| server.prompt('p2', () => ({ messages: [] })); | ||
|
|
||
| // @ts-expect-error private access for test | ||
| expect(server._registeredPrompts['p1']).toBeDefined(); | ||
| // @ts-expect-error private access for test | ||
| expect(server._registeredPrompts['p2']).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('.resource()', () => { | ||
| it('forwards to registerResource for both string URIs and ResourceTemplates', () => { | ||
| const server = new McpServer({ name: 't', version: '1' }); | ||
|
|
||
| server.resource('r1', 'file:///a', () => ({ contents: [] })); | ||
| server.resource('r2', new ResourceTemplate('file:///{id}', { list: undefined }), () => ({ contents: [] })); | ||
|
|
||
| // @ts-expect-error private access for test | ||
| expect(server._registeredResources['file:///a']).toBeDefined(); | ||
| // @ts-expect-error private access for test | ||
| expect(server._registeredResourceTemplates['r2']).toBeDefined(); | ||
| }); | ||
| }); | ||
| }); |
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.