Skip to content

Commit ea35591

Browse files
authored
Merge pull request #370 from modelcontextprotocol/ashwin/everythingcompletions
add completion examples to everything server
2 parents 9a42a2d + 1eca8f8 commit ea35591

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,
@@ -50,6 +51,13 @@ const SampleLLMSchema = z.object({
5051
.describe("Maximum number of tokens to generate"),
5152
});
5253

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

5563
enum ToolName {
@@ -431,6 +439,34 @@ export const createServer = () => {
431439
throw new Error(`Unknown tool: ${name}`);
432440
});
433441

442+
server.setRequestHandler(CompleteRequestSchema, async (request) => {
443+
const { ref, argument } = request.params;
444+
445+
if (ref.type === "ref/resource") {
446+
const resourceId = ref.uri.split("/").pop();
447+
if (!resourceId) return { completion: { values: [] } };
448+
449+
// Filter resource IDs that start with the input value
450+
const values = EXAMPLE_COMPLETIONS.resourceId.filter(id =>
451+
id.startsWith(argument.value)
452+
);
453+
return { completion: { values, hasMore: false, total: values.length } };
454+
}
455+
456+
if (ref.type === "ref/prompt") {
457+
// Handle completion for prompt arguments
458+
const completions = EXAMPLE_COMPLETIONS[argument.name as keyof typeof EXAMPLE_COMPLETIONS];
459+
if (!completions) return { completion: { values: [] } };
460+
461+
const values = completions.filter(value =>
462+
value.startsWith(argument.value)
463+
);
464+
return { completion: { values, hasMore: false, total: values.length } };
465+
}
466+
467+
throw new Error(`Unknown reference type`);
468+
});
469+
434470
server.setRequestHandler(SetLevelRequestSchema, async (request) => {
435471
const { level } = request.params;
436472

0 commit comments

Comments
 (0)