mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-18 00:03:23 +02:00
[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:
41
src/everything/prompts/args.ts
Normal file
41
src/everything/prompts/args.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { z } from "zod";
|
||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
|
||||
/**
|
||||
* Register a prompt with arguments
|
||||
* - Two arguments, one required and one optional
|
||||
* - Combines argument values in the returned prompt
|
||||
*
|
||||
* @param server
|
||||
*/
|
||||
export const registerArgumentsPrompt = (server: McpServer) => {
|
||||
// Prompt arguments
|
||||
const promptArgsSchema = {
|
||||
city: z.string().describe("Name of the city"),
|
||||
state: z.string().describe("Name of the state").optional(),
|
||||
};
|
||||
|
||||
// Register the prompt
|
||||
server.registerPrompt(
|
||||
"args-prompt",
|
||||
{
|
||||
title: "Arguments Prompt",
|
||||
description: "A prompt with two arguments, one required and one optional",
|
||||
argsSchema: promptArgsSchema,
|
||||
},
|
||||
(args) => {
|
||||
const location = `${args?.city}${args?.state ? `, ${args?.state}` : ""}`;
|
||||
return {
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: {
|
||||
type: "text",
|
||||
text: `What's weather in ${location}?`,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user