@modelcontextprotocol/server-everything
Version:
MCP server that exercises all the features of the MCP protocol
38 lines (37 loc) • 1.1 kB
JavaScript
import { z } from "zod";
import { TOOL_ICONS } from "../server/icons.js";
// Tool input schema
export const EchoSchema = z.object({
message: z.string().describe("Message to echo"),
});
// Tool configuration
const name = "echo";
const config = {
title: "Echo Tool",
description: "Echoes back the input string",
inputSchema: EchoSchema,
icons: TOOL_ICONS,
annotations: {
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
},
};
/**
* Registers the 'echo' tool.
*
* The registered tool validates input arguments using the EchoSchema and
* returns a response that echoes the message provided in the arguments.
*
* @param {McpServer} server - The McpServer instance where the tool will be registered.
* @returns {void}
*/
export const registerEchoTool = (server) => {
server.registerTool(name, config, async (args) => {
const validatedArgs = EchoSchema.parse(args);
return {
content: [{ type: "text", text: `Echo: ${validatedArgs.message}` }],
};
});
};