@modelcontextprotocol/server-everything
Version:
MCP server that exercises all the features of the MCP protocol
37 lines (36 loc) • 1.15 kB
JavaScript
import { z } from "zod";
import { PROMPT_ICONS } from "../server/icons.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) => {
// Prompt arguments
const promptArgsSchema = z.object({
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",
icons: PROMPT_ICONS,
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}?`,
},
},
],
};
});
};