Anatomy of an MCP Server: What's Inside and How It's Built
7 min read
You don't need to build an MCP server to use one, but understanding the structure helps you evaluate servers, read their source code, and eventually build your own.
The entry point
An MCP server is typically a Node.js script (TypeScript compiled to JavaScript) or a Python script. When your AI client starts it, the server process launches and communicates over stdio. The first thing it does is declare its capabilities in response to the client's initialization request.
Tool definitions
Each tool is defined with a name, description, and inputSchema (JSON Schema). The description is what the AI reads to decide when to use the tool — so well-written descriptions lead to better AI behavior. When the AI calls the tool, the server receives the arguments, runs the logic, and returns a result object.
A minimal TypeScript MCP server
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: "my-server", version: "1.0.0" });
server.tool("greet", { name: z.string() }, async ({ name }) => ({
content: [{ type: "text", text: `Hello, ${name}!` }],
}));
const transport = new StdioServerTransport();
await server.connect(transport);
Resources
Resources are optional. They're declared with a URI template and a handler that returns content when the AI requests that URI. Resources are read-only — they don't execute actions, they return data.
Error handling
If a tool throws, the error is returned as a structured error response. Good servers validate inputs (using Zod in TypeScript or Pydantic in Python) and return clear error messages so the AI can handle failures gracefully.
Packaging and distribution
Most servers are published to npm (for Node.js) or PyPI (for Python). Installation is just `npm install -g package-name` or `pip install package-name`. The install config in your AI client's JSON file points to the installed binary.
Frequently Asked Questions
Do I need to know TypeScript to build an MCP server?
TypeScript is the most common language, but the Python SDK is equally capable. Choose whichever language you're more comfortable with.
How long does it take to build a simple MCP server?
A basic server with one or two tools can be built in under an hour if you know the language. The MCP SDK handles all the protocol boilerplate.
Related Guides
Ready to install your first server?
Browse MCP Servers