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/fix-omitted-prompt-arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/server': patch
---

Fix prompts/get rejecting omitted arguments when all prompt schema fields are optional.
2 changes: 1 addition & 1 deletion packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ function createPromptHandler(
const typedCallback = callback as (args: unknown, ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>;

return async (args, ctx) => {
const parseResult = await validateStandardSchema(argsSchema, args);
const parseResult = await validateStandardSchema(argsSchema, args ?? {});
if (!parseResult.success) {
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for prompt ${name}: ${parseResult.error}`);
}
Expand Down
53 changes: 53 additions & 0 deletions test/integration/test/server/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4254,6 +4254,59 @@ describe('Zod v4', () => {
]);
});

test('should accept omitted prompt arguments when all schema fields are optional', async () => {
const mcpServer = new McpServer({
name: 'test server',
version: '1.0'
});

const client = new Client({
name: 'test client',
version: '1.0'
});

mcpServer.registerPrompt(
'echo',
{
argsSchema: z.object({
context: z.string().optional()
})
},
({ context }) => ({
messages: [
{
role: 'user',
content: {
type: 'text',
text: `context: ${context ?? 'none'}`
}
}
]
})
);

const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();

await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);

const result = await client.request({
method: 'prompts/get',
params: {
name: 'echo'
}
});

expect(result.messages).toEqual([
{
role: 'user',
content: {
type: 'text',
text: 'context: none'
}
}
]);
});

/***
* Test: Prompt Registration with _meta field
*/
Expand Down
Loading