Model Context Protocol (MCP) 1 · TypeScript server

Create a TypeScript server with a tool

Register a tool with a Zod input schema and run the server over stdio.

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({ name: "demo", version: "1.0.0" });

server.registerTool(
  "add",
  { description: "Add two numbers", inputSchema: { a: z.number(), b: z.number() } },
  async ({ a, b }) => ({ content: [{ type: "text", text: String(a + b) }] })
);

await server.connect(new StdioServerTransport());

Official Model Context Protocol (MCP) 1 documentation

More typescript server commands

All typescript server commands · Model Context Protocol (MCP) 1 cheatsheet

Was this page helpful?