import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
export function createMcpServer() {
const server = new McpServer({
name: "math-server",
version: "1.0.0",
});
server.tool(
"calculate",
{
operation: z.enum(["add", "subtract", "multiply", "divide"]),
a: z.number(),
b: z.number(),
},
async ({ operation, a, b }) => {
switch (operation) {
case "add":
return { content: [{ type: "text", text: String(a + b) }] };
case "subtract":
return { content: [{ type: "text", text: String(a - b) }] };
case "multiply":
return { content: [{ type: "text", text: String(a * b) }] };
case "divide":
if (b === 0) {
return { isError: true, content: [{ type: "text", text: "Division by zero" }] };
}
return { content: [{ type: "text", text: String(a / b) }] };
}
}
);
return server;
}