echo
Facilitates dynamic user input collection by echoing back submitted messages, demonstrating the MCP elicitation system's functionality.
Instructions
Echoes back the input!
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| message | Yes | Message to echo |
Implementation Reference
- src/tools/tool-echo.ts:12-17 (handler)The handler function for the echo tool. Parses input args with EchoSchema and returns a text content response echoing the message.handler: async (args: any) => { const validatedArgs = EchoSchema.parse(args); return { content: [{ type: "text" as const, text: `Echo: ${validatedArgs.message}` }], }; },
- src/tools/tool-echo.ts:4-6 (schema)Zod schema defining the input for the echo tool: a required string message.const EchoSchema = z.object({ message: z.string().describe("Message to echo"), });
- src/tools/index.ts:22-37 (registration)echoTool is registered by inclusion in the allTools array, which populates tool lists and handlers for the MCP server.const allTools = [ echoTool, addTool, longRunningOperationTool, printEnvTool, sampleLlmTool, sampleWithPreferencesTool, sampleMultimodalTool, sampleConversationTool, sampleAdvancedTool, getTinyImageTool, annotatedMessageTool, getResourceReferenceTool, elicitationTool, getResourceLinksTool, ];
- src/tools/index.ts:53-70 (registration)Registers the MCP server request handlers for listing tools (ListToolsRequestSchema) and calling tools (CallToolRequestSchema), delegating to getToolHandler for execution.export const setupTools = (server: Server) => { // Handle listing all available tools server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: getTools() }; }); // Handle tool execution server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; const handler = getToolHandler(name); if (handler) { return await handler(args, request, server); } throw new Error(`Unknown tool: ${name}`); }); };
- src/tools/index.ts:47-50 (helper)Helper function that retrieves the handler for a tool by its name from the allTools array.export const getToolHandler = (name: string) => { const tool = allTools.find((t) => t.name === name); return tool?.handler; };