Build an MCP Server in 30 Minutes: A Step-by-Step Tutorial
Step-by-step MCP server tutorial: choose tools, pick stdio or HTTP transport, write a working server with the TypeScript SDK, and deploy it for AI clients.
Every coding assistant and agent you have used recently probably consumed tools over the Model Context Protocol (MCP). Building your own MCP server is the fastest way to expose your service to every AI client at once, instead of writing one integration per assistant. This tutorial builds a real, working server in about 30 minutes — no prior MCP experience required.
The example we will build is a weather-and-time server written in TypeScript with the official @modelcontextprotocol/sdk. It exposes three tools: one returns the current time, one forecasts weather for a city, and one converts temperatures. You will finish with a server you can test, debug, and wire into a desktop or remote client.
What you need before you start
- Node.js 20 or newer installed locally.
- npm or your preferred package manager.
- An MCP-capable client for testing: Claude Desktop, a recent VS Code build, or the official mcp-inspector tool via npx @modelcontextprotocol/inspector.
Project setup
- Create a directory and initialize it with npm init -y, then set the package to module type in package.json.
- Install the SDK and schema library: npm install @modelcontextprotocol/sdk zod.
- Create a src/server.ts file and add a minimal TypeScript config (target ES2022, module NodeNext).
Declaring tools with zod schemas
The SDK exposes a server object whose tool() method takes a name, a description, and a Zod schema describing the arguments. The description matters more than you think: the model uses it to decide when to call the tool and how to fill in the arguments, so write it the way you would document a public API for a human. A vague description means the model calls your tool at the wrong time with the wrong inputs.
stdio vs HTTP: choosing a transport
The transport is how clients reach your server. stdio spawns the server as a child process and talks over stdin and stdout — ideal for local desktop tools where the user already runs your binary. HTTP (the newer stateless transport) exposes the server over the network, so many clients and users can connect to a single running instance. Local tool? Use stdio. Shared service? Use HTTP. The SDK keeps the transport pluggable, so you can support both with a few lines of wiring.
- stdio: zero network surface and simplest to debug, but one server process per client.
- HTTP: one server serves many clients and deploys behind a load balancer, but you must handle authentication and rate limiting.
- Start with stdio during development, then switch to HTTP for deployment without rewriting your tool logic.
Testing your server without a client
Before wiring in a full assistant, drive the server directly. The inspector gives you a GUI to list tools, call them with crafted arguments, and inspect the raw JSON-RPC traffic. Add a small script that connects over stdio, calls each tool with edge-case inputs (an empty city, missing arguments), and asserts the result shape — this catches schema mistakes before any model ever sees your tool.
Deploying for remote clients
- Build a single bundled entry point (esbuild or tsc) so the HTTP transport starts cleanly in production.
- Run behind a TLS-terminating proxy and add an API-key check in a middleware wrapper.
- Set a generous request timeout — a hanging tool call stalls the entire assistant conversation.
- Monitor tool latency and failure rates from day one; a broken tool silently degrades every client that calls it.
FAQ
Do I need a specific LLM to use MCP?+
No. MCP is a protocol, not a model feature. Any MCP-capable client — assistants, IDEs, agent frameworks — can call your server regardless of which model is under the hood.
Is stdio or HTTP better for production?+
HTTP is the better choice for shared production services because it supports many concurrent clients and standard infrastructure. Use stdio for local desktop tools or during development.
How do I secure an MCP server?+
Treat every tool call as untrusted input. Validate arguments with your schema, enforce per-tool authorization, and add rate limiting on the HTTP transport. Never let a model call a tool with raw user-controlled shell commands.
Related posts
Aug 9, 2026 · AI gateway
Model Context Protocol (MCP): What It Is and Why It MattersModel Context Protocol (MCP) explained: how it standardizes LLM tool access, how MCP servers work, and when to use it in 2026.
Aug 14, 2026 · AI gateway
Best MCP Servers in 2026: The Curated ListThe best MCP servers in 2026 for files, browsers, databases, GitHub, and dev tools. A curated list to extend your AI assistant with real capabilities.
Aug 11, 2026 · AI gateway
Function Calling With LLMs: A Practical GuideFunction calling with LLMs explained: how tools work, structured schemas, execution loops, and best practices for building reliable AI apps.