mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-17 15:53:23 +02:00
In src/everything:
* Refactor / move streamableHttp.ts, sse.ts, and stdio.ts to transports/
* Move everything.ts to server/ for reference
* Add server/index.js
- exports the createServer function
- import registerTools from tools/index.js
- in createServer()
- read instructions.md and include in ServerOptions for McpServer constructor
- construct McpServer instead of Server
- call registerTools, passing server
* Add tools/echo.ts
- define EchoSchema
- define tool config
- export addToolEcho function
- in addToolEcho()
- register handler for Echo tool
* Add tools/index.ts
- import addToolEcho
- export registerTools function
- in registerTools()
- call addToolEcho
24 lines
710 B
TypeScript
24 lines
710 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 addToolEcho = (server: McpServer) => {
|
|
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
|
|
const validatedArgs = EchoSchema.parse(args);
|
|
return {
|
|
content: [{ type: "text", text: `Echo: ${validatedArgs.message}` }],
|
|
};
|
|
});
|
|
};
|