From eba64615676bdbdf008105e8fb37ebc9df2a7cbc Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Wed, 22 Jan 2025 11:38:39 +0000 Subject: [PATCH] Failing test case for double completion handlers --- src/server/mcp.test.ts | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/server/mcp.test.ts b/src/server/mcp.test.ts index 4154e7dd..8f9bfa77 100644 --- a/src/server/mcp.test.ts +++ b/src/server/mcp.test.ts @@ -1283,6 +1283,69 @@ describe("prompt()", () => { })); }); + test("should allow registering prompts with arguments", () => { + const mcpServer = new McpServer({ + name: "test server", + version: "1.0", + }); + + // This should succeed + mcpServer.prompt( + "echo", + { message: z.string() }, + ({ message }) => ({ + messages: [{ + role: "user", + content: { + type: "text", + text: `Please process this message: ${message}` + } + }] + }) + ); + }); + + test("should allow registering both resources and prompts with completion handlers", () => { + const mcpServer = new McpServer({ + name: "test server", + version: "1.0", + }); + + // Register a resource with completion + mcpServer.resource( + "test", + new ResourceTemplate("test://resource/{category}", { + list: undefined, + complete: { + category: () => ["books", "movies", "music"], + }, + }), + async () => ({ + contents: [ + { + uri: "test://resource/test", + text: "Test content", + }, + ], + }), + ); + + // 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}` + } + }] + }) + ); + }); + test("should throw McpError for invalid prompt name", async () => { const mcpServer = new McpServer({ name: "test server",