Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-humans-grow.md
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 1 addition & 1 deletion packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ export class McpServer {
* );
* ```
*/
registerPrompt<Args extends StandardSchemaWithJSON>(
registerPrompt<Args extends StandardSchemaWithJSON | undefined = undefined>(
name: string,
config: {
title?: string;
Expand Down
34 changes: 34 additions & 0 deletions packages/server/test/server/mcp.types.test.ts
Original file line number Diff line number Diff line change
@@ -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
);
}
Loading