How to Build an MCP Server in TypeScript (2026 Guide)
A step-by-step guide to building a Model Context Protocol (MCP) server in TypeScript with xmcp: scaffold a project, write your first tool, run it locally, and connect it to Claude or Cursor.
If you want an AI assistant like Claude or Cursor to call your own functions, read your own data, or hit your own APIs, you need an MCP server. This guide walks through building one in TypeScript from an empty terminal to a working server connected to a real client, using xmcp.
By the end you'll have a server with a working tool, running locally, that Claude Desktop or Cursor can call.
What you're building
The Model Context Protocol (MCP) is a standard way to expose tools (functions the model can call), resources (data it can read), and prompts (reusable instructions) to any MCP-compatible client. An MCP server is the program that hosts those capabilities.
We'll build a tiny server with one tool, then point Claude at it.
Prerequisites
- Node.js 20 or later
- An MCP client to test against (Claude Desktop or Cursor)
Step 1: Scaffold the project
The fastest path is the create-xmcp-app CLI, which generates a project with everything wired up:
You'll be prompted for a project name, a template, a package manager, a transport, and which primitives to include:
Pick HTTP as the transport for this guide — it's what you'll deploy remotely, and it's the easiest to test in a browser. (We'll cover the difference between HTTP and STDIO in MCP Transports Explained.)
The CLI creates a folder, installs dependencies, and gives you a file-based project structure:
The key idea: you don't register tools manually. Drop a file in src/tools/ and xmcp discovers it.
Step 2: Understand a tool file
Open src/tools/greet.ts. A tool is just a file with up to three exports:
Three things worth calling out:
schemauses Zod and.describe()so the model understands each parameter. Clear descriptions are what make tools discoverable.InferSchematurns your Zod schema into a TypeScript type automatically — no duplicate type definitions, full autocomplete inside the handler.- The default export is the handler. Returning a plain string or number is enough; xmcp wraps it in the proper MCP response shape for you.
Step 3: Write your own tool
Let's add a tool that does something slightly more real — fetch the current time for a timezone. Create src/tools/current-time.ts:
That's the whole loop: a new file, a schema, a handler. xmcp picks it up automatically — no registry to edit.
Prefer scaffolding?
xmcp create tool current-timegenerates a starter file with the exports already in place.
Step 4: Run the dev server
Start xmcp in development mode:
This runs xmcp dev, which watches your files and reloads on change. By default the HTTP transport serves on port 3001 at the /mcp endpoint, so your server is now live at:
Your xmcp.config.ts controls the transport. For HTTP it looks like this:
http: true uses sensible defaults; pass an object to override the port, endpoint, or CORS settings.
Step 5: Connect a client
Now point an MCP client at your server.
Cursor speaks HTTP directly:
Claude Desktop doesn't connect to HTTP servers natively yet, so you bridge it with the mcp-remote adapter:
Restart the client, and your greet and current-time tools show up. Ask Claude "what time is it in Tokyo?" and it will call your tool.
If the server doesn't appear, see Fix: MCP Server Won't Connect in Claude Desktop — connection issues almost always come down to transport, the mcp-remote bridge, or CORS.
Step 6: Build for production
When you're ready to ship:
xmcp build compiles to a dist/ directory. You start the production server with the script matching your transport:
From here you can deploy to Vercel with zero config — vc deploy is all it takes. See the Vercel deployment docs for the full flow.
Where to go next
You now have a working TypeScript MCP server. To take it further:
- MCP Transports Explained — when to use STDIO vs HTTP, and why it matters for serverless.
- Authentication docs — lock down your tools with OAuth via Better Auth, Clerk, or Auth0.
- Core concepts — resources, prompts, middleware, and structured outputs.
The whole point of xmcp is that adding capability stays this simple: write a file, and it's a tool.