Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add completion examples to everything server #370

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions src/everything/everything.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import {
CallToolRequestSchema,
CompleteRequestSchema,
CreateMessageRequest,
CreateMessageResultSchema,
GetPromptRequestSchema,
Expand Down Expand Up @@ -48,6 +49,13 @@ const SampleLLMSchema = z.object({
.describe("Maximum number of tokens to generate"),
});

// Example completion values
const EXAMPLE_COMPLETIONS = {
style: ["casual", "formal", "technical", "friendly"],
temperature: ["0", "0.5", "0.7", "1.0"],
resourceId: ["1", "2", "3", "4", "5"],
};

const GetTinyImageSchema = z.object({});

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

server.setRequestHandler(CompleteRequestSchema, async (request) => {
const { ref, argument } = request.params;

if (ref.type === "ref/resource") {
const resourceId = ref.uri.split("/").pop();
if (!resourceId) return { completion: { values: [] } };

// Filter resource IDs that start with the input value
const values = EXAMPLE_COMPLETIONS.resourceId.filter(id =>
id.startsWith(argument.value)
);
return { completion: { values, hasMore: false, total: values.length } };
}

if (ref.type === "ref/prompt") {
// Handle completion for prompt arguments
const completions = EXAMPLE_COMPLETIONS[argument.name as keyof typeof EXAMPLE_COMPLETIONS];
if (!completions) return { completion: { values: [] } };

const values = completions.filter(value =>
value.startsWith(argument.value)
);
return { completion: { values, hasMore: false, total: values.length } };
}

throw new Error(`Unknown reference type`);
});

server.setRequestHandler(SetLevelRequestSchema, async (request) => {
const { level } = request.params;

Expand Down
Loading