From 797078a7bb3e74224c828d85028ea296c622aa35 Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Mon, 30 Mar 2026 20:36:46 +0000 Subject: [PATCH] fix(server): allow registerPrompt callback without args MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Args generic now extends StandardSchemaWithJSON | undefined with a default of undefined, matching registerTool. This lets PromptCallback resolve to the (ctx) => result overload when argsSchema is omitted. Co-authored-by: Anders Søgaard --- .changeset/moody-humans-grow.md | 5 +++ packages/server/src/server/mcp.ts | 2 +- packages/server/test/server/mcp.types.test.ts | 34 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .changeset/moody-humans-grow.md create mode 100644 packages/server/test/server/mcp.types.test.ts diff --git a/.changeset/moody-humans-grow.md b/.changeset/moody-humans-grow.md new file mode 100644 index 000000000..fbd1992d2 --- /dev/null +++ b/.changeset/moody-humans-grow.md @@ -0,0 +1,5 @@ +--- +"@modelcontextprotocol/server": patch +--- + +Fix `registerPrompt` generic to allow the no-args callback overload. The `Args` type parameter now defaults to `undefined`, matching `registerTool`. diff --git a/packages/server/src/server/mcp.ts b/packages/server/src/server/mcp.ts index 4d9f81c50..c85dcde93 100644 --- a/packages/server/src/server/mcp.ts +++ b/packages/server/src/server/mcp.ts @@ -915,7 +915,7 @@ export class McpServer { * ); * ``` */ - registerPrompt( + registerPrompt( name: string, config: { title?: string; diff --git a/packages/server/test/server/mcp.types.test.ts b/packages/server/test/server/mcp.types.test.ts new file mode 100644 index 000000000..c435c5f4d --- /dev/null +++ b/packages/server/test/server/mcp.types.test.ts @@ -0,0 +1,34 @@ +/** + * Compile-time type checks for McpServer registration methods. + * + * These verify that generic type parameters resolve correctly for the + * no-argsSchema and with-argsSchema overloads of registerPrompt. + */ +import type { GetPromptResult, ServerContext } from '@modelcontextprotocol/core'; +import * as z from 'zod/v4'; + +import { McpServer } from '../../src/server/mcp.js'; + +/* eslint-disable @typescript-eslint/no-unused-vars */ + +declare const server: McpServer; +declare const result: GetPromptResult; + +// Without argsSchema, the callback must accept (ctx) only. +// Before the fix, Args had no default and could not be undefined, so the +// PromptCallback conditional never resolved to the no-args branch. +function registerPrompt_noArgs() { + server.registerPrompt('no-args', {}, (ctx: ServerContext) => result); + + // @ts-expect-error -- callback cannot take an args parameter when argsSchema is omitted + server.registerPrompt('no-args', {}, (args: { code: string }, ctx: ServerContext) => result); +} + +// With argsSchema, the callback must accept (args, ctx). +function registerPrompt_withArgs() { + server.registerPrompt( + 'with-args', + { argsSchema: z.object({ code: z.string() }) }, + (args: { code: string }, ctx: ServerContext) => result + ); +}