mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-18 16:13:22 +02:00
* Updated architecture.md * Refactor / renamed all addXPrompt, addXTool, and addXResource functions to registerX... * Added the add tool
24 lines
685 B
TypeScript
24 lines
685 B
TypeScript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
import { z } from "zod";
|
|
|
|
export const EchoSchema = z.object({
|
|
message: z.string().describe("Message to echo"),
|
|
});
|
|
|
|
const name = "echo";
|
|
const config = {
|
|
title: "Echo Tool",
|
|
description: "Echoes back the input string",
|
|
inputSchema: EchoSchema,
|
|
};
|
|
|
|
export const registerEchoTool = (server: McpServer) => {
|
|
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
|
|
const validatedArgs = EchoSchema.parse(args);
|
|
return {
|
|
content: [{ type: "text", text: `Echo: ${validatedArgs.message}` }],
|
|
};
|
|
});
|
|
};
|