Skip to content

Commit eba6461

Browse files
committed
Failing test case for double completion handlers
1 parent 1fb33e8 commit eba6461

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/server/mcp.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,69 @@ describe("prompt()", () => {
12831283
}));
12841284
});
12851285

1286+
test("should allow registering prompts with arguments", () => {
1287+
const mcpServer = new McpServer({
1288+
name: "test server",
1289+
version: "1.0",
1290+
});
1291+
1292+
// This should succeed
1293+
mcpServer.prompt(
1294+
"echo",
1295+
{ message: z.string() },
1296+
({ message }) => ({
1297+
messages: [{
1298+
role: "user",
1299+
content: {
1300+
type: "text",
1301+
text: `Please process this message: ${message}`
1302+
}
1303+
}]
1304+
})
1305+
);
1306+
});
1307+
1308+
test("should allow registering both resources and prompts with completion handlers", () => {
1309+
const mcpServer = new McpServer({
1310+
name: "test server",
1311+
version: "1.0",
1312+
});
1313+
1314+
// Register a resource with completion
1315+
mcpServer.resource(
1316+
"test",
1317+
new ResourceTemplate("test://resource/{category}", {
1318+
list: undefined,
1319+
complete: {
1320+
category: () => ["books", "movies", "music"],
1321+
},
1322+
}),
1323+
async () => ({
1324+
contents: [
1325+
{
1326+
uri: "test://resource/test",
1327+
text: "Test content",
1328+
},
1329+
],
1330+
}),
1331+
);
1332+
1333+
// Register a prompt with completion
1334+
mcpServer.prompt(
1335+
"echo",
1336+
{ message: completable(z.string(), () => ["hello", "world"]) },
1337+
({ message }) => ({
1338+
messages: [{
1339+
role: "user",
1340+
content: {
1341+
type: "text",
1342+
text: `Please process this message: ${message}`
1343+
}
1344+
}]
1345+
})
1346+
);
1347+
});
1348+
12861349
test("should throw McpError for invalid prompt name", async () => {
12871350
const mcpServer = new McpServer({
12881351
name: "test server",

0 commit comments

Comments
 (0)