[WIP] Refactor everything server to be more modular and use recommended APIs.

* Adding prompts (simple, complex, with completions)

* Add prompts/simple.ts
  - in addSimplePrompt()
    - register a simple prompt with no arguments

* Add prompts/complex.ts
  - in addComplexPrompt()
    - define promptArgsSchema containing a required city arg of type string and an optional state arg of type state
    - register the complex prompt with a prompt callback that combines the city and state into a prompt asking for the weather in that location

* Add prompts/completions.ts
  - in addPromptWithCompletions()
    - define promptArgsSchema containing department and name string fields with completion handlers
    - register the completable prompt with a prompt callback that combines the inputs into a prompt asking to promote the selected name to head of the selected department

* Add prompts/index.ts
  - import addSimplePrompt, addComplexPrompt, and addPromptWithCompletions
  - export registerPrompts function
  - in registerPrompts()
    - call addSimplePrompt
    - call addComplexPrompt
    - call addPromptWithCompletions

* In package.json
  - add prettier devDependency
  - add prettier:check script
  - add prettier:fix script
  - in build script, copy docs folder to dist

* All other changes were prettier formatting
This commit is contained in:
cliffhall
2025-12-05 16:09:35 -05:00
parent 1c64b36c78
commit daec74fbc1
5 changed files with 130 additions and 10 deletions

View File

@@ -0,0 +1,46 @@
import { z } from "zod";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { completable } from "@modelcontextprotocol/sdk/server/completable.js";
export const addPromptWithCompletions = (server: McpServer) => {
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));
}
return [];
}),
};
server.registerPrompt(
"completable-prompt",
{
title: "Team Management",
description: "Choose a team member to lead their specific department.",
argsSchema: promptArgsSchema,
},
async ({ department, name }) => ({
messages: [
{
role: "user",
content: {
type: "text",
text: `Please promote ${name} to the head of the ${department} team.`,
},
},
],
})
);
};