Skip to content

Commit 1eca8f8

Browse files
committed
add completion examples to everything server
1 parent 3ff22e8 commit 1eca8f8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/everything/everything.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
22
import {
33
CallToolRequestSchema,
4+
CompleteRequestSchema,
45
CreateMessageRequest,
56
CreateMessageResultSchema,
67
GetPromptRequestSchema,
@@ -48,6 +49,13 @@ const SampleLLMSchema = z.object({
4849
.describe("Maximum number of tokens to generate"),
4950
});
5051

52+
// Example completion values
53+
const EXAMPLE_COMPLETIONS = {
54+
style: ["casual", "formal", "technical", "friendly"],
55+
temperature: ["0", "0.5", "0.7", "1.0"],
56+
resourceId: ["1", "2", "3", "4", "5"],
57+
};
58+
5159
const GetTinyImageSchema = z.object({});
5260

5361
enum ToolName {
@@ -412,6 +420,34 @@ export const createServer = () => {
412420
throw new Error(`Unknown tool: ${name}`);
413421
});
414422

423+
server.setRequestHandler(CompleteRequestSchema, async (request) => {
424+
const { ref, argument } = request.params;
425+
426+
if (ref.type === "ref/resource") {
427+
const resourceId = ref.uri.split("/").pop();
428+
if (!resourceId) return { completion: { values: [] } };
429+
430+
// Filter resource IDs that start with the input value
431+
const values = EXAMPLE_COMPLETIONS.resourceId.filter(id =>
432+
id.startsWith(argument.value)
433+
);
434+
return { completion: { values, hasMore: false, total: values.length } };
435+
}
436+
437+
if (ref.type === "ref/prompt") {
438+
// Handle completion for prompt arguments
439+
const completions = EXAMPLE_COMPLETIONS[argument.name as keyof typeof EXAMPLE_COMPLETIONS];
440+
if (!completions) return { completion: { values: [] } };
441+
442+
const values = completions.filter(value =>
443+
value.startsWith(argument.value)
444+
);
445+
return { completion: { values, hasMore: false, total: values.length } };
446+
}
447+
448+
throw new Error(`Unknown reference type`);
449+
});
450+
415451
server.setRequestHandler(SetLevelRequestSchema, async (request) => {
416452
const { level } = request.params;
417453

0 commit comments

Comments
 (0)