diff --git a/.changeset/funky-baths-attack.md b/.changeset/funky-baths-attack.md new file mode 100644 index 000000000..f65f1263c --- /dev/null +++ b/.changeset/funky-baths-attack.md @@ -0,0 +1,8 @@ +--- +'@modelcontextprotocol/node': patch +'@modelcontextprotocol/test-integration': patch +'@modelcontextprotocol/server': patch +'@modelcontextprotocol/core': patch +--- + +remove deprecated .tool, .prompt, .resource method signatures diff --git a/.changeset/shy-times-learn.md b/.changeset/shy-times-learn.md new file mode 100644 index 000000000..99617f8b7 --- /dev/null +++ b/.changeset/shy-times-learn.md @@ -0,0 +1,8 @@ +--- +'@modelcontextprotocol/node': patch +'@modelcontextprotocol/test-integration': patch +'@modelcontextprotocol/server': patch +'@modelcontextprotocol/core': patch +--- + +deprecated .tool, .prompt, .resource method removal diff --git a/examples/server/src/ssePollingExample.ts b/examples/server/src/ssePollingExample.ts index 78b1fda19..2416d2ec3 100644 --- a/examples/server/src/ssePollingExample.ts +++ b/examples/server/src/ssePollingExample.ts @@ -35,11 +35,12 @@ const server = new McpServer( ); // Register a long-running tool that demonstrates server-initiated disconnect -server.tool( +server.registerTool( 'long-task', - 'A long-running task that sends progress updates. Server will disconnect mid-task to demonstrate polling.', - {}, - async (_args, extra): Promise => { + { + description: 'A long-running task that sends progress updates. Server will disconnect mid-task to demonstrate polling.' + }, + async (extra): Promise => { const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); console.log(`[${extra.sessionId}] Starting long-task...`); diff --git a/packages/core/src/types/types.ts b/packages/core/src/types/types.ts index 63d6f2d23..d3e404c58 100644 --- a/packages/core/src/types/types.ts +++ b/packages/core/src/types/types.ts @@ -215,13 +215,6 @@ export const JSONRPCResultResponseSchema = z export const isJSONRPCResultResponse = (value: unknown): value is JSONRPCResultResponse => JSONRPCResultResponseSchema.safeParse(value).success; -/** - * @deprecated Use {@link isJSONRPCResultResponse} instead. - * - * Please note that {@link JSONRPCResponse} is a union of {@link JSONRPCResultResponse} and {@link JSONRPCErrorResponse} as per the updated JSON-RPC specification. (was previously just {@link JSONRPCResultResponse}) - */ -export const isJSONRPCResponse = isJSONRPCResultResponse; - /** * Error codes defined by the JSON-RPC specification. */ @@ -265,11 +258,6 @@ export const JSONRPCErrorResponseSchema = z }) .strict(); -/** - * @deprecated Use {@link JSONRPCErrorResponseSchema} instead. - */ -export const JSONRPCErrorSchema = JSONRPCErrorResponseSchema; - /** * Checks if a value is a valid JSONRPCErrorResponse. * @param value - The value to check. @@ -279,11 +267,6 @@ export const JSONRPCErrorSchema = JSONRPCErrorResponseSchema; export const isJSONRPCErrorResponse = (value: unknown): value is JSONRPCErrorResponse => JSONRPCErrorResponseSchema.safeParse(value).success; -/** - * @deprecated Use {@link isJSONRPCErrorResponse} instead. - */ -export const isJSONRPCError = isJSONRPCErrorResponse; - export const JSONRPCMessageSchema = z.union([ JSONRPCRequestSchema, JSONRPCNotificationSchema, @@ -2115,11 +2098,6 @@ export const ResourceTemplateReferenceSchema = z.object({ uri: z.string() }); -/** - * @deprecated Use ResourceTemplateReferenceSchema instead - */ -export const ResourceReferenceSchema = ResourceTemplateReferenceSchema; - /** * Identifies a prompt. */ @@ -2432,12 +2410,6 @@ export type JSONRPCRequest = Infer; export type JSONRPCNotification = Infer; export type JSONRPCResponse = Infer; export type JSONRPCErrorResponse = Infer; -/** - * @deprecated Use {@link JSONRPCErrorResponse} instead. - * - * Please note that spec types have renamed {@link JSONRPCError} to {@link JSONRPCErrorResponse} as per the updated JSON-RPC specification. (was previously just {@link JSONRPCError}) and future versions will remove {@link JSONRPCError}. - */ -export type JSONRPCError = JSONRPCErrorResponse; export type JSONRPCResultResponse = Infer; export type JSONRPCMessage = Infer; @@ -2609,10 +2581,6 @@ export type ElicitResult = Infer; /* Autocomplete */ export type ResourceTemplateReference = Infer; -/** - * @deprecated Use ResourceTemplateReference instead - */ -export type ResourceReference = ResourceTemplateReference; export type PromptReference = Infer; export type CompleteRequestParams = Infer; export type CompleteRequest = Infer; diff --git a/packages/middleware/node/test/streamableHttp.test.ts b/packages/middleware/node/test/streamableHttp.test.ts index 406194a2b..ca7728d88 100644 --- a/packages/middleware/node/test/streamableHttp.test.ts +++ b/packages/middleware/node/test/streamableHttp.test.ts @@ -161,10 +161,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { config ??= { sessionIdGenerator: () => randomUUID() }; const mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); - mcpServer.tool( + mcpServer.registerTool( 'greet', - 'A simple greeting tool', - { name: z.string().describe('Name to greet') }, + { + description: 'A simple greeting tool', + inputSchema: { name: z.string().describe('Name to greet') } + }, async ({ name }): Promise => { return { content: [{ type: 'text', text: `Hello, ${name}!` }] }; } @@ -206,10 +208,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }> { const mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); - mcpServer.tool( + mcpServer.registerTool( 'profile', - 'A user profile data tool', - { active: z.boolean().describe('Profile status') }, + { + description: 'A user profile data tool', + inputSchema: { active: z.boolean().describe('Profile status') } + }, async ({ active }, { authInfo }): Promise => { return { content: [{ type: 'text', text: `${active ? 'Active' : 'Inactive'} profile from token: ${authInfo?.token}!` }] }; } @@ -394,10 +398,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { it('should pass request info to tool callback', async () => { sessionId = await initializeServer(); - mcpServer.tool( + mcpServer.registerTool( 'test-request-info', - 'A simple test tool with request info', - { name: z.string().describe('Name to greet') }, + { + description: 'A simple test tool with request info', + inputSchema: { name: z.string().describe('Name to greet') } + }, async ({ name }, { requestInfo }): Promise => { // Convert Headers object to plain object for JSON serialization // Headers is a Web API class that doesn't serialize with JSON.stringify @@ -1845,7 +1851,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // Register a tool that closes its own SSE stream via extra callback - mcpServer.tool('close-stream-tool', 'Closes its own stream', {}, async (_args, extra) => { + mcpServer.registerTool('close-stream-tool', { description: 'Closes its own stream' }, async extra => { // Close the SSE stream for this request extra.closeSSEStream?.(); streamCloseCalled = true; @@ -1913,7 +1919,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { let receivedCloseSSEStream: (() => void) | undefined; // Register a tool that captures the extra.closeSSEStream callback - mcpServer.tool('test-callback-tool', 'Test tool', {}, async (_args, extra) => { + mcpServer.registerTool('test-callback-tool', { description: 'Test tool' }, async extra => { receivedCloseSSEStream = extra.closeSSEStream; return { content: [{ type: 'text', text: 'Done' }] }; }); @@ -1972,7 +1978,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { let receivedCloseStandaloneSSEStream: (() => void) | undefined; // Register a tool that captures the extra.closeSSEStream callback - mcpServer.tool('test-old-version-tool', 'Test tool', {}, async (_args, extra) => { + mcpServer.registerTool('test-old-version-tool', { description: 'Test tool' }, async extra => { receivedCloseSSEStream = extra.closeSSEStream; receivedCloseStandaloneSSEStream = extra.closeStandaloneSSEStream; return { content: [{ type: 'text', text: 'Done' }] }; @@ -2031,7 +2037,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { let receivedCloseSSEStream: (() => void) | undefined; // Register a tool that captures the extra.closeSSEStream callback - mcpServer.tool('test-no-callback-tool', 'Test tool', {}, async (_args, extra) => { + mcpServer.registerTool('test-no-callback-tool', { description: 'Test tool' }, async extra => { receivedCloseSSEStream = extra.closeSSEStream; return { content: [{ type: 'text', text: 'Done' }] }; }); @@ -2088,7 +2094,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { let receivedCloseStandaloneSSEStream: (() => void) | undefined; // Register a tool that captures the extra.closeStandaloneSSEStream callback - mcpServer.tool('test-standalone-callback-tool', 'Test tool', {}, async (_args, extra) => { + mcpServer.registerTool('test-standalone-callback-tool', { description: 'Test tool' }, async extra => { receivedCloseStandaloneSSEStream = extra.closeStandaloneSSEStream; return { content: [{ type: 'text', text: 'Done' }] }; }); @@ -2143,7 +2149,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { mcpServer = result.mcpServer; // Register a tool that closes the standalone SSE stream via extra callback - mcpServer.tool('close-standalone-stream-tool', 'Closes standalone stream', {}, async (_args, extra) => { + mcpServer.registerTool('close-standalone-stream-tool', { description: 'Closes standalone stream' }, async extra => { extra.closeStandaloneSSEStream?.(); return { content: [{ type: 'text', text: 'Stream closed' }] }; }); @@ -2224,7 +2230,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { mcpServer = result.mcpServer; // Register a tool that closes the standalone SSE stream - mcpServer.tool('close-standalone-for-reconnect', 'Closes standalone stream', {}, async (_args, extra) => { + mcpServer.registerTool('close-standalone-for-reconnect', { description: 'Closes standalone stream' }, async extra => { extra.closeStandaloneSSEStream?.(); return { content: [{ type: 'text', text: 'Stream closed' }] }; }); diff --git a/packages/server/src/server/mcp.ts b/packages/server/src/server/mcp.ts index 9e3be719f..2b9672d03 100644 --- a/packages/server/src/server/mcp.ts +++ b/packages/server/src/server/mcp.ts @@ -628,78 +628,6 @@ export class McpServer { this._promptHandlersInitialized = true; } - /** - * Registers a resource `name` at a fixed URI, which will use the given callback to respond to read requests. - * @deprecated Use `registerResource` instead. - */ - resource(name: string, uri: string, readCallback: ReadResourceCallback): RegisteredResource; - - /** - * Registers a resource `name` at a fixed URI with metadata, which will use the given callback to respond to read requests. - * @deprecated Use `registerResource` instead. - */ - resource(name: string, uri: string, metadata: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource; - - /** - * Registers a resource `name` with a template pattern, which will use the given callback to respond to read requests. - * @deprecated Use `registerResource` instead. - */ - resource(name: string, template: ResourceTemplate, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate; - - /** - * Registers a resource `name` with a template pattern and metadata, which will use the given callback to respond to read requests. - * @deprecated Use `registerResource` instead. - */ - resource( - name: string, - template: ResourceTemplate, - metadata: ResourceMetadata, - readCallback: ReadResourceTemplateCallback - ): RegisteredResourceTemplate; - - resource(name: string, uriOrTemplate: string | ResourceTemplate, ...rest: unknown[]): RegisteredResource | RegisteredResourceTemplate { - let metadata: ResourceMetadata | undefined; - if (typeof rest[0] === 'object') { - metadata = rest.shift() as ResourceMetadata; - } - - const readCallback = rest[0] as ReadResourceCallback | ReadResourceTemplateCallback; - - if (typeof uriOrTemplate === 'string') { - if (this._registeredResources[uriOrTemplate]) { - throw new Error(`Resource ${uriOrTemplate} is already registered`); - } - - const registeredResource = this._createRegisteredResource( - name, - undefined, - uriOrTemplate, - metadata, - readCallback as ReadResourceCallback - ); - - this.setResourceRequestHandlers(); - this.sendResourceListChanged(); - return registeredResource; - } else { - if (this._registeredResourceTemplates[name]) { - throw new Error(`Resource template ${name} is already registered`); - } - - const registeredResourceTemplate = this._createRegisteredResourceTemplate( - name, - undefined, - uriOrTemplate, - metadata, - readCallback as ReadResourceTemplateCallback - ); - - this.setResourceRequestHandlers(); - this.sendResourceListChanged(); - return registeredResourceTemplate; - } - } - /** * Registers a resource with a config object and callback. * For static resources, use a URI string. For dynamic resources, use a ResourceTemplate. @@ -925,129 +853,6 @@ export class McpServer { return registeredTool; } - /** - * Registers a zero-argument tool `name`, which will run the given function when the client calls it. - * @deprecated Use `registerTool` instead. - */ - tool(name: string, cb: ToolCallback): RegisteredTool; - - /** - * Registers a zero-argument tool `name` (with a description) which will run the given function when the client calls it. - * @deprecated Use `registerTool` instead. - */ - tool(name: string, description: string, cb: ToolCallback): RegisteredTool; - - /** - * Registers a tool taking either a parameter schema for validation or annotations for additional metadata. - * This unified overload handles both `tool(name, paramsSchema, cb)` and `tool(name, annotations, cb)` cases. - * - * Note: We use a union type for the second parameter because TypeScript cannot reliably disambiguate - * between ToolAnnotations and ZodRawShapeCompat during overload resolution, as both are plain object types. - * @deprecated Use `registerTool` instead. - */ - tool( - name: string, - paramsSchemaOrAnnotations: Args | ToolAnnotations, - cb: ToolCallback - ): RegisteredTool; - - /** - * Registers a tool `name` (with a description) taking either parameter schema or annotations. - * This unified overload handles both `tool(name, description, paramsSchema, cb)` and - * `tool(name, description, annotations, cb)` cases. - * - * Note: We use a union type for the third parameter because TypeScript cannot reliably disambiguate - * between ToolAnnotations and ZodRawShapeCompat during overload resolution, as both are plain object types. - * @deprecated Use `registerTool` instead. - */ - tool( - name: string, - description: string, - paramsSchemaOrAnnotations: Args | ToolAnnotations, - cb: ToolCallback - ): RegisteredTool; - - /** - * Registers a tool with both parameter schema and annotations. - * @deprecated Use `registerTool` instead. - */ - tool( - name: string, - paramsSchema: Args, - annotations: ToolAnnotations, - cb: ToolCallback - ): RegisteredTool; - - /** - * Registers a tool with description, parameter schema, and annotations. - * @deprecated Use `registerTool` instead. - */ - tool( - name: string, - description: string, - paramsSchema: Args, - annotations: ToolAnnotations, - cb: ToolCallback - ): RegisteredTool; - - /** - * tool() implementation. Parses arguments passed to overrides defined above. - */ - tool(name: string, ...rest: unknown[]): RegisteredTool { - if (this._registeredTools[name]) { - throw new Error(`Tool ${name} is already registered`); - } - - let description: string | undefined; - let inputSchema: ZodRawShapeCompat | undefined; - let outputSchema: ZodRawShapeCompat | undefined; - let annotations: ToolAnnotations | undefined; - - // Tool properties are passed as separate arguments, with omissions allowed. - // Support for this style is frozen as of protocol version 2025-03-26. Future additions - // to tool definition should *NOT* be added. - - if (typeof rest[0] === 'string') { - description = rest.shift() as string; - } - - // Handle the different overload combinations - if (rest.length > 1) { - // We have at least one more arg before the callback - const firstArg = rest[0]; - - if (isZodRawShapeCompat(firstArg)) { - // We have a params schema as the first arg - inputSchema = rest.shift() as ZodRawShapeCompat; - - // Check if the next arg is potentially annotations - if (rest.length > 1 && typeof rest[0] === 'object' && rest[0] !== null && !isZodRawShapeCompat(rest[0])) { - // Case: tool(name, paramsSchema, annotations, cb) - // Or: tool(name, description, paramsSchema, annotations, cb) - annotations = rest.shift() as ToolAnnotations; - } - } else if (typeof firstArg === 'object' && firstArg !== null) { - // Not a ZodRawShapeCompat, so must be annotations in this position - // Case: tool(name, annotations, cb) - // Or: tool(name, description, annotations, cb) - annotations = rest.shift() as ToolAnnotations; - } - } - const callback = rest[0] as ToolCallback; - - return this._createRegisteredTool( - name, - undefined, - description, - inputSchema, - outputSchema, - annotations, - { taskSupport: 'forbidden' }, - undefined, - callback - ); - } - /** * Registers a tool with a config object and callback. */ @@ -1082,59 +887,6 @@ export class McpServer { ); } - /** - * Registers a zero-argument prompt `name`, which will run the given function when the client calls it. - * @deprecated Use `registerPrompt` instead. - */ - prompt(name: string, cb: PromptCallback): RegisteredPrompt; - - /** - * Registers a zero-argument prompt `name` (with a description) which will run the given function when the client calls it. - * @deprecated Use `registerPrompt` instead. - */ - prompt(name: string, description: string, cb: PromptCallback): RegisteredPrompt; - - /** - * Registers a prompt `name` accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. - * @deprecated Use `registerPrompt` instead. - */ - prompt(name: string, argsSchema: Args, cb: PromptCallback): RegisteredPrompt; - - /** - * Registers a prompt `name` (with a description) accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments. - * @deprecated Use `registerPrompt` instead. - */ - prompt( - name: string, - description: string, - argsSchema: Args, - cb: PromptCallback - ): RegisteredPrompt; - - prompt(name: string, ...rest: unknown[]): RegisteredPrompt { - if (this._registeredPrompts[name]) { - throw new Error(`Prompt ${name} is already registered`); - } - - let description: string | undefined; - if (typeof rest[0] === 'string') { - description = rest.shift() as string; - } - - let argsSchema: PromptArgsRawShape | undefined; - if (rest.length > 1) { - argsSchema = rest.shift() as PromptArgsRawShape; - } - - const cb = rest[0] as PromptCallback; - const registeredPrompt = this._createRegisteredPrompt(name, undefined, description, argsSchema, cb); - - this.setPromptRequestHandlers(); - this.sendPromptListChanged(); - - return registeredPrompt; - } - /** * Registers a prompt with a config object and callback. */ diff --git a/packages/server/test/server/streamableHttp.test.ts b/packages/server/test/server/streamableHttp.test.ts index bf264ced4..2a08d669a 100644 --- a/packages/server/test/server/streamableHttp.test.ts +++ b/packages/server/test/server/streamableHttp.test.ts @@ -129,10 +129,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { beforeEach(async () => { mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); - mcpServer.tool( + mcpServer.registerTool( 'greet', - 'A simple greeting tool', - { name: z.string().describe('Name to greet') }, + { + description: 'A simple greeting tool', + inputSchema: { name: z.string().describe('Name to greet') } + }, async ({ name }): Promise => { return { content: [{ type: 'text', text: `Hello, ${name}!` }] }; } @@ -435,9 +437,13 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { beforeEach(async () => { mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); - mcpServer.tool('echo', 'Echo tool', { message: z.string() }, async ({ message }): Promise => { - return { content: [{ type: 'text', text: message }] }; - }); + mcpServer.registerTool( + 'echo', + { description: 'Echo tool', inputSchema: { message: z.string() } }, + async ({ message }): Promise => { + return { content: [{ type: 'text', text: message }] }; + } + ); transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: undefined @@ -479,9 +485,13 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { beforeEach(async () => { mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); - mcpServer.tool('greet', 'Greeting tool', { name: z.string() }, async ({ name }): Promise => { - return { content: [{ type: 'text', text: `Hello, ${name}!` }] }; - }); + mcpServer.registerTool( + 'greet', + { description: 'Greeting tool', inputSchema: { name: z.string() } }, + async ({ name }): Promise => { + return { content: [{ type: 'text', text: `Hello, ${name}!` }] }; + } + ); transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID(), @@ -647,9 +657,13 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); - mcpServer.tool('greet', 'Greeting tool', { name: z.string() }, async ({ name }): Promise => { - return { content: [{ type: 'text', text: `Hello, ${name}!` }] }; - }); + mcpServer.registerTool( + 'greet', + { description: 'Greeting tool', inputSchema: { name: z.string() } }, + async ({ name }): Promise => { + return { content: [{ type: 'text', text: `Hello, ${name}!` }] }; + } + ); transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: () => randomUUID(), diff --git a/test/integration/test/issues/test1277.zod.v4.description.test.ts b/test/integration/test/issues/test1277.zod.v4.description.test.ts index 75a61cb36..107b803cb 100644 --- a/test/integration/test/issues/test1277.zod.v4.description.test.ts +++ b/test/integration/test/issues/test1277.zod.v4.description.test.ts @@ -25,11 +25,13 @@ describe.each(zodTestMatrix)('Issue #1277: $zodVersionLabel', (entry: ZodMatrixE version: '1.0' }); - mcpServer.prompt( + mcpServer.registerPrompt( 'test', { - name: z.string().describe('The user name'), - value: z.string().describe('The value to set') + argsSchema: { + name: z.string().describe('The user name'), + value: z.string().describe('The value to set') + } }, async ({ name, value }) => ({ messages: [ diff --git a/test/integration/test/server/mcp.test.ts b/test/integration/test/server/mcp.test.ts index 6837d4e64..5d811848b 100644 --- a/test/integration/test/server/mcp.test.ts +++ b/test/integration/test/server/mcp.test.ts @@ -109,11 +109,13 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // Create a tool that sends progress updates - mcpServer.tool( + mcpServer.registerTool( 'long-operation', - 'A long running operation with progress updates', { - steps: z.number().min(1).describe('Number of steps to perform') + description: 'A long running operation with progress updates', + inputSchema: { + steps: z.number().min(1).describe('Number of steps to perform') + } }, async ({ steps }, { sendNotification, _meta }) => { const progressToken = _meta?.progressToken; @@ -270,7 +272,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { notifications.push(notification); }; - mcpServer.tool('test', async () => ({ + mcpServer.registerTool('test', {}, async () => ({ content: [ { type: 'text', @@ -301,7 +303,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { expect(notifications).toHaveLength(0); // Adding another tool triggers the update notification - mcpServer.tool('test2', async () => ({ + mcpServer.registerTool('test2', {}, async () => ({ content: [ { type: 'text', @@ -338,7 +340,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial tool - const tool = mcpServer.tool('test', async () => ({ + const tool = mcpServer.registerTool('test', {}, async () => ({ content: [ { type: 'text', @@ -403,10 +405,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial tool - const tool = mcpServer.tool( + const tool = mcpServer.registerTool( 'test', { - name: z.string() + inputSchema: { + name: z.string() + } }, async ({ name }) => ({ content: [ @@ -586,7 +590,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial tool - const tool = mcpServer.tool('test', async () => ({ + const tool = mcpServer.registerTool('test', {}, async () => ({ content: [ { type: 'text', @@ -643,26 +647,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - // old api - mcpServer.tool( - 'test', - { - name: z.string(), - value: z.number() - }, - async ({ name, value }) => ({ - content: [ - { - type: 'text', - text: `${name}: ${value}` - } - ] - }) - ); - - // new api mcpServer.registerTool( - 'test (new api)', + 'test', { inputSchema: { name: z.string(), value: z.number() } }, @@ -682,7 +668,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { ListToolsResultSchema ); - expect(result.tools).toHaveLength(2); + expect(result.tools).toHaveLength(1); expect(result.tools[0]!.name).toBe('test'); expect(result.tools[0]!.inputSchema).toMatchObject({ type: 'object', @@ -691,8 +677,6 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { value: { type: 'number' } } }); - expect(result.tools[1]!.name).toBe('test (new api)'); - expect(result.tools[1]!.inputSchema).toEqual(result.tools[0]!.inputSchema); }); /*** @@ -708,8 +692,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - // old api - mcpServer.tool('test', 'Test description', async () => ({ + mcpServer.registerTool('test', { description: 'Test description' }, async () => ({ content: [ { type: 'text', @@ -765,17 +748,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool('test', { title: 'Test Tool', readOnlyHint: true }, async () => ({ - content: [ - { - type: 'text', - text: 'Test response' - } - ] - })); - mcpServer.registerTool( - 'test (new api)', + 'test', { annotations: { title: 'Test Tool', readOnlyHint: true } }, @@ -800,17 +774,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { ListToolsResultSchema ); - expect(result.tools).toHaveLength(2); + expect(result.tools).toHaveLength(1); expect(result.tools[0]!.name).toBe('test'); expect(result.tools[0]!.annotations).toEqual({ title: 'Test Tool', readOnlyHint: true }); - expect(result.tools[1]!.name).toBe('test (new api)'); - expect(result.tools[1]!.annotations).toEqual({ - title: 'Test Tool', - readOnlyHint: true - }); }); /*** @@ -826,12 +795,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool('test', { name: z.string() }, { title: 'Test Tool', readOnlyHint: true }, async ({ name }) => ({ - content: [{ type: 'text', text: `Hello, ${name}!` }] - })); - mcpServer.registerTool( - 'test (new api)', + 'test', { inputSchema: { name: z.string() }, annotations: { title: 'Test Tool', readOnlyHint: true } @@ -847,7 +812,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { const result = await client.request({ method: 'tools/list' }, ListToolsResultSchema); - expect(result.tools).toHaveLength(2); + expect(result.tools).toHaveLength(1); expect(result.tools[0]!.name).toBe('test'); expect(result.tools[0]!.inputSchema).toMatchObject({ type: 'object', @@ -857,9 +822,6 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { title: 'Test Tool', readOnlyHint: true }); - expect(result.tools[1]!.name).toBe('test (new api)'); - expect(result.tools[1]!.inputSchema).toEqual(result.tools[0]!.inputSchema); - expect(result.tools[1]!.annotations).toEqual(result.tools[0]!.annotations); }); /*** @@ -875,18 +837,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool( - 'test', - 'A tool with everything', - { name: z.string() }, - { title: 'Complete Test Tool', readOnlyHint: true, openWorldHint: false }, - async ({ name }) => ({ - content: [{ type: 'text', text: `Hello, ${name}!` }] - }) - ); - mcpServer.registerTool( - 'test (new api)', + 'test', { description: 'A tool with everything', inputSchema: { name: z.string() }, @@ -907,7 +859,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { const result = await client.request({ method: 'tools/list' }, ListToolsResultSchema); - expect(result.tools).toHaveLength(2); + expect(result.tools).toHaveLength(1); expect(result.tools[0]!.name).toBe('test'); expect(result.tools[0]!.description).toBe('A tool with everything'); expect(result.tools[0]!.inputSchema).toMatchObject({ @@ -919,10 +871,6 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { readOnlyHint: true, openWorldHint: false }); - expect(result.tools[1]!.name).toBe('test (new api)'); - expect(result.tools[1]!.description).toBe('A tool with everything'); - expect(result.tools[1]!.inputSchema).toEqual(result.tools[0]!.inputSchema); - expect(result.tools[1]!.annotations).toEqual(result.tools[0]!.annotations); }); /*** @@ -938,25 +886,10 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool( - 'test', - 'A tool with everything but empty params', - {}, - { - title: 'Complete Test Tool with empty params', - readOnlyHint: true, - openWorldHint: false - }, - async () => ({ - content: [{ type: 'text', text: 'Test response' }] - }) - ); - mcpServer.registerTool( - 'test (new api)', + 'test', { description: 'A tool with everything but empty params', - inputSchema: {}, annotations: { title: 'Complete Test Tool with empty params', readOnlyHint: true, @@ -974,7 +907,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { const result = await client.request({ method: 'tools/list' }, ListToolsResultSchema); - expect(result.tools).toHaveLength(2); + expect(result.tools).toHaveLength(1); expect(result.tools[0]!.name).toBe('test'); expect(result.tools[0]!.description).toBe('A tool with everything but empty params'); expect(result.tools[0]!.inputSchema).toMatchObject({ @@ -986,10 +919,6 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { readOnlyHint: true, openWorldHint: false }); - expect(result.tools[1]!.name).toBe('test (new api)'); - expect(result.tools[1]!.description).toBe('A tool with everything but empty params'); - expect(result.tools[1]!.inputSchema).toEqual(result.tools[0]!.inputSchema); - expect(result.tools[1]!.annotations).toEqual(result.tools[0]!.annotations); }); /*** @@ -1005,24 +934,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool( - 'test', - { - name: z.string(), - value: z.number() - }, - async ({ name, value }) => ({ - content: [ - { - type: 'text', - text: `${name}: ${value}` - } - ] - }) - ); - mcpServer.registerTool( - 'test (new api)', + 'test', { inputSchema: { name: z.string(), @@ -1066,30 +979,6 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { } ]) ); - - const result2 = await client.request( - { - method: 'tools/call', - params: { - name: 'test (new api)', - arguments: { - name: 'test', - value: 'not a number' - } - } - }, - CallToolResultSchema - ); - - expect(result2.isError).toBe(true); - expect(result2.content).toEqual( - expect.arrayContaining([ - { - type: 'text', - text: expect.stringContaining('Input validation error: Invalid arguments for tool test (new api)') - } - ]) - ); }); /*** @@ -1101,7 +990,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool('test', async () => ({ + mcpServer.registerTool('test', {}, async () => ({ content: [ { type: 'text', @@ -1111,7 +1000,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { })); expect(() => { - mcpServer.tool('test', async () => ({ + mcpServer.registerTool('test', {}, async () => ({ content: [ { type: 'text', @@ -1132,10 +1021,10 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // This should succeed - mcpServer.tool('tool1', () => ({ content: [] })); + mcpServer.registerTool('tool1', {}, () => ({ content: [] })); // This should also succeed and not throw about request handlers - mcpServer.tool('tool2', () => ({ content: [] })); + mcpServer.registerTool('tool2', {}, () => ({ content: [] })); }); /*** @@ -1448,7 +1337,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); let receivedSessionId: string | undefined; - mcpServer.tool('test-tool', async extra => { + mcpServer.registerTool('test-tool', {}, async extra => { receivedSessionId = extra.sessionId; return { content: [ @@ -1494,7 +1383,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); let receivedRequestId: string | number | undefined; - mcpServer.tool('request-id-test', async extra => { + mcpServer.registerTool('request-id-test', {}, async extra => { receivedRequestId = extra.requestId; return { content: [ @@ -1556,8 +1445,8 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { receivedLogMessage = notification.params.data as string; }); - mcpServer.tool('test-tool', async ({ sendNotification }) => { - await sendNotification({ + mcpServer.registerTool('test-tool', {}, async extra => { + await extra.sendNotification({ method: 'notifications/message', params: { level: 'debug', data: loggingMessage } }); @@ -1599,11 +1488,13 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool( + mcpServer.registerTool( 'test', - 'Test tool', { - input: z.string() + description: 'Test tool', + inputSchema: { + input: z.string() + } }, async ({ input }) => ({ content: [ @@ -1654,7 +1545,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool('error-test', async () => { + mcpServer.registerTool('error-test', {}, async () => { throw new Error('Tool execution failed'); }); @@ -1695,7 +1586,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.tool('test-tool', async () => ({ + mcpServer.registerTool('test-tool', {}, async () => ({ content: [ { type: 'text', @@ -1759,7 +1650,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { message: 'Authorization required' }; - mcpServer.tool('needs-authorization', async () => { + mcpServer.registerTool('needs-authorization', {}, async () => { throw new UrlElicitationRequiredError([elicitationParams], 'Confirmation required'); }); @@ -2065,7 +1956,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource('test', 'test://resource', async () => ({ + mcpServer.registerResource('test', 'test://resource', {}, async () => ({ contents: [ { uri: 'test://resource', @@ -2108,7 +1999,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial resource - const resource = mcpServer.resource('test', 'test://resource', async () => ({ + const resource = mcpServer.registerResource('test', 'test://resource', {}, async () => ({ contents: [ { uri: 'test://resource', @@ -2176,9 +2067,10 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial resource template - const resourceTemplate = mcpServer.resource( + const resourceTemplate = mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{id}', { list: undefined }), + {}, async uri => ({ contents: [ { @@ -2248,7 +2140,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial resource - const resource = mcpServer.resource('test', 'test://resource', async () => ({ + const resource = mcpServer.registerResource('test', 'test://resource', {}, async () => ({ contents: [ { uri: 'test://resource', @@ -2299,11 +2191,11 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial resources - const resource1 = mcpServer.resource('resource1', 'test://resource1', async () => ({ + const resource1 = mcpServer.registerResource('resource1', 'test://resource1', {}, async () => ({ contents: [{ uri: 'test://resource1', text: 'Resource 1 content' }] })); - mcpServer.resource('resource2', 'test://resource2', async () => ({ + mcpServer.registerResource('resource2', 'test://resource2', {}, async () => ({ contents: [{ uri: 'test://resource2', text: 'Resource 2 content' }] })); @@ -2352,9 +2244,10 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register resource template - const resourceTemplate = mcpServer.resource( + const resourceTemplate = mcpServer.registerResource( 'template', new ResourceTemplate('test://resource/{id}', { list: undefined }), + {}, async uri => ({ contents: [ { @@ -2404,7 +2297,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); const mockDate = new Date().toISOString(); - mcpServer.resource( + mcpServer.registerResource( 'test', 'test://resource', { @@ -2460,7 +2353,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource('test', new ResourceTemplate('test://resource/{id}', { list: undefined }), async () => ({ + mcpServer.registerResource('test', new ResourceTemplate('test://resource/{id}', { list: undefined }), {}, async () => ({ contents: [ { uri: 'test://resource/123', @@ -2498,7 +2391,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{id}', { list: async () => ({ @@ -2514,6 +2407,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { ] }) }), + {}, async uri => ({ contents: [ { @@ -2555,11 +2449,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{category}/{id}', { list: undefined }), + {}, async (uri, { category, id }) => ({ contents: [ { @@ -2603,7 +2498,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource('test', 'test://resource', async () => ({ + mcpServer.registerResource('test', 'test://resource', {}, async () => ({ contents: [ { uri: 'test://resource', @@ -2613,7 +2508,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { })); expect(() => { - mcpServer.resource('test2', 'test://resource', async () => ({ + mcpServer.registerResource('test2', 'test://resource', {}, async () => ({ contents: [ { uri: 'test://resource', @@ -2634,7 +2529,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // This should succeed - mcpServer.resource('resource1', 'test://resource1', async () => ({ + mcpServer.registerResource('resource1', 'test://resource1', {}, async () => ({ contents: [ { uri: 'test://resource1', @@ -2644,7 +2539,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { })); // This should also succeed and not throw about request handlers - mcpServer.resource('resource2', 'test://resource2', async () => ({ + mcpServer.registerResource('resource2', 'test://resource2', {}, async () => ({ contents: [ { uri: 'test://resource2', @@ -2663,7 +2558,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource('test', new ResourceTemplate('test://resource/{id}', { list: undefined }), async () => ({ + mcpServer.registerResource('test', new ResourceTemplate('test://resource/{id}', { list: undefined }), {}, async () => ({ contents: [ { uri: 'test://resource/123', @@ -2673,7 +2568,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { })); expect(() => { - mcpServer.resource('test', new ResourceTemplate('test://resource/{id}', { list: undefined }), async () => ({ + mcpServer.registerResource('test', new ResourceTemplate('test://resource/{id}', { list: undefined }), {}, async () => ({ contents: [ { uri: 'test://resource/123', @@ -2697,7 +2592,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource('error-test', 'test://error', async () => { + mcpServer.registerResource('error-test', 'test://error', {}, async () => { throw new Error('Resource read failed'); }); @@ -2731,7 +2626,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource('test', 'test://resource', async () => ({ + mcpServer.registerResource('test', 'test://resource', {}, async () => ({ contents: [ { uri: 'test://resource', @@ -2770,11 +2665,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{category}', { list: undefined }), + {}, async () => ({ contents: [ { @@ -2805,7 +2701,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{category}', { list: undefined, @@ -2813,6 +2709,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { category: () => ['books', 'movies', 'music'] } }), + {}, async () => ({ contents: [ { @@ -2844,7 +2741,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{category}', { list: undefined, @@ -2852,6 +2749,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { category: () => ['books', 'movies', 'music'] } }), + {}, async () => ({ contents: [ { @@ -2901,7 +2799,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{category}', { list: undefined, @@ -2909,6 +2807,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { category: (test: string) => ['books', 'movies', 'music'].filter(value => value.startsWith(test)) } }), + {}, async () => ({ contents: [ { @@ -2959,7 +2858,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); let receivedRequestId: string | number | undefined; - mcpServer.resource('request-id-test', 'test://resource', async (_uri, extra) => { + mcpServer.registerResource('request-id-test', 'test://resource', {}, async (_uri, extra) => { receivedRequestId = extra.requestId; return { contents: [ @@ -3012,7 +2911,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt('test', async () => ({ + mcpServer.registerPrompt('test', {}, async () => ({ messages: [ { role: 'assistant', @@ -3057,7 +2956,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial prompt - const prompt = mcpServer.prompt('test', async () => ({ + const prompt = mcpServer.registerPrompt('test', {}, async () => ({ messages: [ { role: 'assistant', @@ -3134,10 +3033,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial prompt - const prompt = mcpServer.prompt( + const prompt = mcpServer.registerPrompt( 'test', { - name: z.string() + argsSchema: { + name: z.string() + } }, async ({ name }) => ({ messages: [ @@ -3236,7 +3137,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial prompt - const prompt = mcpServer.prompt('test', async () => ({ + const prompt = mcpServer.registerPrompt('test', {}, async () => ({ messages: [ { role: 'assistant', @@ -3293,7 +3194,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial prompts - const prompt1 = mcpServer.prompt('prompt1', async () => ({ + const prompt1 = mcpServer.registerPrompt('prompt1', {}, async () => ({ messages: [ { role: 'assistant', @@ -3305,7 +3206,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { ] })); - mcpServer.prompt('prompt2', async () => ({ + mcpServer.registerPrompt('prompt2', {}, async () => ({ messages: [ { role: 'assistant', @@ -3358,11 +3259,13 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt( + mcpServer.registerPrompt( 'test', { - name: z.string(), - value: z.string() + argsSchema: { + name: z.string(), + value: z.string() + } }, async ({ name, value }) => ({ messages: [ @@ -3409,7 +3312,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt('test', 'Test description', async () => ({ + mcpServer.registerPrompt('test', { description: 'Test description' }, async () => ({ messages: [ { role: 'assistant', @@ -3451,11 +3354,13 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt( + mcpServer.registerPrompt( 'test', { - name: z.string(), - value: z.string().min(3) + argsSchema: { + name: z.string(), + value: z.string().min(3) + } }, async ({ name, value }) => ({ messages: [ @@ -3500,7 +3405,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt('test', async () => ({ + mcpServer.registerPrompt('test', {}, async () => ({ messages: [ { role: 'assistant', @@ -3513,7 +3418,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { })); expect(() => { - mcpServer.prompt('test', async () => ({ + mcpServer.registerPrompt('test', {}, async () => ({ messages: [ { role: 'assistant', @@ -3537,7 +3442,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // This should succeed - mcpServer.prompt('prompt1', async () => ({ + mcpServer.registerPrompt('prompt1', {}, async () => ({ messages: [ { role: 'assistant', @@ -3550,7 +3455,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { })); // This should also succeed and not throw about request handlers - mcpServer.prompt('prompt2', async () => ({ + mcpServer.registerPrompt('prompt2', {}, async () => ({ messages: [ { role: 'assistant', @@ -3573,7 +3478,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // This should succeed - mcpServer.prompt('echo', { message: z.string() }, ({ message }) => ({ + mcpServer.registerPrompt('echo', { argsSchema: { message: z.string() } }, ({ message }) => ({ messages: [ { role: 'user', @@ -3596,7 +3501,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // Register a resource with completion - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{category}', { list: undefined, @@ -3604,6 +3509,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { category: () => ['books', 'movies', 'music'] } }), + {}, async () => ({ contents: [ { @@ -3615,17 +3521,21 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { ); // Register a prompt with completion - mcpServer.prompt('echo', { message: completable(z.string(), () => ['hello', 'world']) }, ({ message }) => ({ - messages: [ - { - role: 'user', - content: { - type: 'text', - text: `Please process this message: ${message}` + mcpServer.registerPrompt( + 'echo', + { argsSchema: { message: completable(z.string(), () => ['hello', 'world']) } }, + ({ message }) => ({ + messages: [ + { + role: 'user', + content: { + type: 'text', + text: `Please process this message: ${message}` + } } - } - ] - })); + ] + }) + ); }); /*** @@ -3642,7 +3552,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt('test-prompt', async () => ({ + mcpServer.registerPrompt('test-prompt', {}, async () => ({ messages: [ { role: 'assistant', @@ -3684,10 +3594,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt( + mcpServer.registerPrompt( 'test-prompt', { - name: z.string() + argsSchema: { + name: z.string() + } }, async ({ name }) => ({ messages: [ @@ -3724,10 +3636,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt( + mcpServer.registerPrompt( 'test-prompt', { - name: completable(z.string(), () => ['Alice', 'Bob', 'Charlie']) + argsSchema: { + name: completable(z.string(), () => ['Alice', 'Bob', 'Charlie']) + } }, async ({ name }) => ({ messages: [ @@ -3763,10 +3677,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt( + mcpServer.registerPrompt( 'test-prompt', { - name: completable(z.string(), () => ['Alice', 'Bob', 'Charlie']) + argsSchema: { + name: completable(z.string(), () => ['Alice', 'Bob', 'Charlie']) + } }, async ({ name }) => ({ messages: [ @@ -3820,10 +3736,12 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.prompt( + mcpServer.registerPrompt( 'test-prompt', { - name: completable(z.string(), test => ['Alice', 'Bob', 'Charlie'].filter(value => value.startsWith(test))) + argsSchema: { + name: completable(z.string(), test => ['Alice', 'Bob', 'Charlie'].filter(value => value.startsWith(test))) + } }, async ({ name }) => ({ messages: [ @@ -3878,7 +3796,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); let receivedRequestId: string | number | undefined; - mcpServer.prompt('request-id-test', async extra => { + mcpServer.registerPrompt('request-id-test', {}, async extra => { receivedRequestId = extra.requestId; return { messages: [ @@ -3935,7 +3853,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{id}', { list: async () => ({ @@ -4005,7 +3923,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{id}', { list: async () => ({ @@ -4112,16 +4030,18 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // Tool 1: Only name - mcpServer.tool('tool_name_only', async () => ({ + mcpServer.registerTool('tool_name_only', {}, async () => ({ content: [{ type: 'text', text: 'Response' }] })); // Tool 2: Name and annotations.title - mcpServer.tool( + mcpServer.registerTool( 'tool_with_annotations_title', - 'Tool with annotations title', { - title: 'Annotations Title' + description: 'Tool with annotations title', + annotations: { + title: 'Annotations Title' + } }, async () => ({ content: [{ type: 'text', text: 'Response' }] @@ -4523,12 +4443,14 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // Register the restaurant booking tool from README example - mcpServer.tool( + mcpServer.registerTool( 'book-restaurant', { - restaurant: z.string(), - date: z.string(), - partySize: z.number() + inputSchema: { + restaurant: z.string(), + date: z.string(), + partySize: z.number() + } }, async ({ restaurant, date, partySize }) => { // Check availability @@ -5147,7 +5069,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource('test', 'test://resource', async () => ({ + mcpServer.registerResource('test', 'test://resource', {}, async () => ({ contents: [ { uri: 'test://resource', @@ -5190,7 +5112,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }; // Register initial resource - const resource = mcpServer.resource('test', 'test://resource', async () => ({ + const resource = mcpServer.registerResource('test', 'test://resource', {}, async () => ({ contents: [ { uri: 'test://resource', @@ -5266,7 +5188,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{id}', { list: async () => ({ @@ -5336,7 +5258,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { version: '1.0' }); - mcpServer.resource( + mcpServer.registerResource( 'test', new ResourceTemplate('test://resource/{id}', { list: async () => ({ @@ -5398,16 +5320,18 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // Tool 1: Only name - mcpServer.tool('tool_name_only', async () => ({ + mcpServer.registerTool('tool_name_only', {}, async () => ({ content: [{ type: 'text', text: 'Response' }] })); // Tool 2: Name and annotations.title - mcpServer.tool( + mcpServer.registerTool( 'tool_with_annotations_title', - 'Tool with annotations title', { - title: 'Annotations Title' + description: 'Tool with annotations title', + annotations: { + title: 'Annotations Title' + } }, async () => ({ content: [{ type: 'text', text: 'Response' }] @@ -5809,12 +5733,14 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { }); // Register the restaurant booking tool from README example - mcpServer.tool( + mcpServer.registerTool( 'book-restaurant', { - restaurant: z.string(), - date: z.string(), - partySize: z.number() + inputSchema: { + restaurant: z.string(), + date: z.string(), + partySize: z.number() + } }, async ({ restaurant, date, partySize }) => { // Check availability diff --git a/test/integration/test/stateManagementStreamableHttp.test.ts b/test/integration/test/stateManagementStreamableHttp.test.ts index 3b1ad4be4..e1a4db4ee 100644 --- a/test/integration/test/stateManagementStreamableHttp.test.ts +++ b/test/integration/test/stateManagementStreamableHttp.test.ts @@ -30,7 +30,7 @@ async function setupServer(withSessionManagement: boolean, z: ZNamespace) { ); // Add a simple resource - mcpServer.resource('test-resource', '/test', { description: 'A test resource' }, async () => ({ + mcpServer.registerResource('test-resource', '/test', { description: 'A test resource' }, async () => ({ contents: [ { uri: '/test', @@ -39,7 +39,7 @@ async function setupServer(withSessionManagement: boolean, z: ZNamespace) { ] })); - mcpServer.prompt('test-prompt', 'A test prompt', async () => ({ + mcpServer.registerPrompt('test-prompt', { description: 'A test prompt' }, async () => ({ messages: [ { role: 'user', @@ -51,11 +51,13 @@ async function setupServer(withSessionManagement: boolean, z: ZNamespace) { ] })); - mcpServer.tool( + mcpServer.registerTool( 'greet', - 'A simple greeting tool', { - name: z.string().describe('Name to greet').default('World') + description: 'A simple greeting tool', + inputSchema: { + name: z.string().describe('Name to greet').default('World') + } }, async ({ name }) => { return { diff --git a/test/integration/test/taskResumability.test.ts b/test/integration/test/taskResumability.test.ts index d2370af85..ce124eb93 100644 --- a/test/integration/test/taskResumability.test.ts +++ b/test/integration/test/taskResumability.test.ts @@ -60,11 +60,13 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { mcpServer = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: { logging: {} } }); // Add a simple notification tool that completes quickly - mcpServer.tool( + mcpServer.registerTool( 'send-notification', - 'Sends a single notification', { - message: z.string().describe('Message to send').default('Test notification') + description: 'Sends a single notification', + inputSchema: { + message: z.string().describe('Message to send').default('Test notification') + } }, async ({ message }, { sendNotification }) => { // Send notification immediately @@ -83,12 +85,14 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { ); // Add a long-running tool that sends multiple notifications - mcpServer.tool( + mcpServer.registerTool( 'run-notifications', - 'Sends multiple notifications over time', { - count: z.number().describe('Number of notifications to send').default(10), - interval: z.number().describe('Interval between notifications in ms').default(50) + description: 'Sends multiple notifications over time', + inputSchema: { + count: z.number().describe('Number of notifications to send').default(10), + interval: z.number().describe('Interval between notifications in ms').default(50) + } }, async ({ count, interval }, { sendNotification }) => { // Send notifications at specified intervals diff --git a/test/integration/test/title.test.ts b/test/integration/test/title.test.ts index 97348c117..1e9fe6c29 100644 --- a/test/integration/test/title.test.ts +++ b/test/integration/test/title.test.ts @@ -44,7 +44,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { const server = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: {} }); // Register tool without title - server.tool('test-tool', 'A test tool', { value: z.string() }, async () => ({ content: [{ type: 'text', text: 'result' }] })); + server.registerTool('test-tool', { description: 'A test tool', inputSchema: { value: z.string() } }, async () => ({ + content: [{ type: 'text', text: 'result' }] + })); const client = new Client({ name: 'test-client', version: '1.0.0' }); @@ -64,7 +66,7 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => { const server = new McpServer({ name: 'test-server', version: '1.0.0' }, { capabilities: {} }); // Register prompt with title by updating after creation - const prompt = server.prompt('test-prompt', 'A test prompt', async () => ({ + const prompt = server.registerPrompt('test-prompt', { description: 'A test prompt' }, async () => ({ messages: [{ role: 'user', content: { type: 'text', text: 'test' } }] })); prompt.update({ title: 'Test Prompt Display Name' });