[WIP] Refactor everything server to be more modular and use recommended APIs.
* Updated architecture.md * Refactor/renamed static.ts to file.ts * Refactor/renamed complex.ts to args.ts * Refactor/renamed template.ts to templates.ts. * In resource.ts, - improved registerEmbeddedResourcePrompt to allow selection of blob or text resource type. * In file.ts - refactor/renamed registerStaticResources to registerFileResources to highlight the fact that it is using files as resources. * In args.ts - refactor/renamed registerComplexPrompt to registerArgumentsPrompt to highlight the fact that it is demonstrating prompt arguments. * Updated inline documentation throughout
This commit is contained in:
parent
9084cd3a96
commit
7b2ff6b064
1 changed files with 168 additions and 62 deletions
|
|
@ -2,36 +2,54 @@ import { z } from "zod";
|
|||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { completable } from "@modelcontextprotocol/sdk/server/completable.js";
|
||||
|
||||
/**
|
||||
* Register a prompt with completable arguments
|
||||
* - Two required arguments, both with completion handlers
|
||||
* - First argument value will be included in context for second argument
|
||||
* - Allows second argument to depend on the first argument value
|
||||
*
|
||||
* @param server
|
||||
*/
|
||||
export const registerPromptWithCompletions = (server: McpServer) => {
|
||||
// Prompt arguments
|
||||
const promptArgsSchema = {
|
||||
department: completable(z.string(), (value) => {
|
||||
return ["Engineering", "Sales", "Marketing", "Support"].filter((d) =>
|
||||
d.startsWith(value)
|
||||
);
|
||||
}),
|
||||
name: completable(z.string(), (value, context) => {
|
||||
const department = context?.arguments?.["department"];
|
||||
if (department === "Engineering") {
|
||||
return ["Alice", "Bob", "Charlie"].filter((n) => n.startsWith(value));
|
||||
} else if (department === "Sales") {
|
||||
return ["David", "Eve", "Frank"].filter((n) => n.startsWith(value));
|
||||
} else if (department === "Marketing") {
|
||||
return ["Grace", "Henry", "Iris"].filter((n) => n.startsWith(value));
|
||||
} else if (department === "Support") {
|
||||
return ["John", "Kim", "Lee"].filter((n) => n.startsWith(value));
|
||||
department: completable(
|
||||
z.string().describe("Choose the department."),
|
||||
(value) => {
|
||||
return ["Engineering", "Sales", "Marketing", "Support"].filter((d) =>
|
||||
d.startsWith(value)
|
||||
);
|
||||
}
|
||||
return [];
|
||||
}),
|
||||
),
|
||||
name: completable(
|
||||
z
|
||||
.string()
|
||||
.describe("Choose a team member to lead the selected department."),
|
||||
(value, context) => {
|
||||
const department = context?.arguments?.["department"];
|
||||
if (department === "Engineering") {
|
||||
return ["Alice", "Bob", "Charlie"].filter((n) => n.startsWith(value));
|
||||
} else if (department === "Sales") {
|
||||
return ["David", "Eve", "Frank"].filter((n) => n.startsWith(value));
|
||||
} else if (department === "Marketing") {
|
||||
return ["Grace", "Henry", "Iris"].filter((n) => n.startsWith(value));
|
||||
} else if (department === "Support") {
|
||||
return ["John", "Kim", "Lee"].filter((n) => n.startsWith(value));
|
||||
}
|
||||
return [];
|
||||
}
|
||||
),
|
||||
};
|
||||
|
||||
// Register the prompt
|
||||
server.registerPrompt(
|
||||
"completable-prompt",
|
||||
{
|
||||
title: "Team Management",
|
||||
description: "Choose a team member to lead their specific department.",
|
||||
description: "First argument choice narrows values for second argument.",
|
||||
argsSchema: promptArgsSchema,
|
||||
},
|
||||
async ({ department, name }) => ({
|
||||
({ department, name }) => ({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
|
|
|
|||
Loading…
Reference in a new issue