Model Context Protocol (MCP) 1 cheatsheet

Model Context Protocol (MCP) 1: TypeScript server

2 common Model Context Protocol (MCP) 1 tasks.

Install the TypeScript SDK

Install the SDK and Zod, used to describe tool inputs.

npm install @modelcontextprotocol/sdk zod

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());

Was this page helpful?