import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import fs from "fs";
const server = new McpServer({
name: "Simple MCP POC",
version: "1.0.0",
});
// 📄 Read File Tool
server.tool(
"read_file",
"Read a local file",
{
path: z.string(),
},
async ({ path }) => {
try {
const content = fs.readFileSync(path, "utf-8");
return {
content: [{ type: "text", text: content }]
};
} catch (error) {
return {
content: [{ type: "text", text: `Error reading file: ${error.message}` }],
isError: true
};
}
}
);
// ➗ Calculator Tool
server.tool(
"calculator",
"Simple calculator",
{
a: z.number(),
b: z.number(),
operation: z.enum(["add", "subtract", "multiply", "divide"]),
},
async ({ a, b, operation }) => {
let result;
if (operation === "add") result = a + b;
if (operation === "subtract") result = a - b;
if (operation === "multiply") result = a * b;
if (operation === "divide") result = a / b;
return {
content: [{ type: "text", text: `Result: ${result}` }]
};
}
);
// Start MCP server
const transport = new StdioServerTransport();
await server.connect(transport);