MCP: concepts
The Model Context Protocol (MCP) is an open standard for connecting AI applications to tools and data. Build a server once, and it works in Cursor, Claude Code, Claude Desktop, the SDKs, and many other clients. claude.ai (web and mobile) accepts remote servers only, so the local stdio server built in this guide works there only once you deploy it over Streamable HTTP (see Security & production).
Architecture
Section titled “Architecture”┌──────────── Host (Cursor / Claude Desktop / Claude Code) ────────────┐│ Model ◀──▶ MCP client A ◀──▶ ┐ ││ MCP client B ◀──▶ ┼───────────┐ │└──────────────────────────────────┼───────────┼───────────────────────┘ stdio (local) Streamable HTTP (remote) ▼ ▼ MCP server A MCP server B ──▶ API / DB / files- Host: the app the user interacts with.
- Client: one connection per server, managed by the host.
- Server: your program. It exposes capabilities and does the actual work.
- Messages are JSON-RPC 2.0.
Protocol versions
Section titled “Protocol versions”The current MCP specification is revision 2026-07-28. Many clients still speak the legacy (2025 revisions) protocol, so you’ll meet both.
| Current (2026-07-28) | Legacy (2025 revisions) | |
|---|---|---|
| Opening | No handshake. The client can call server/discover to learn the server’s info and capabilities |
initialize → result → notifications/initialized |
| Protocol version | Travels with every request | Negotiated once, in initialize |
| Protocol sessions | None | Optional (Mcp-Session-Id on HTTP) |
| Server-to-client requests | None. Elicitation arrives through an input_required tool result |
Sampling, Roots, Elicitation, and ping |
| Sampling, Roots, and Logging | Deprecated (SEP-2577); kept in the spec until at least 2027-07-28 | Active |
ping |
Removed | Active |
Both official SDKs (TypeScript @modelcontextprotocol/server 2.2 and Python mcp 2.2) serve both eras from the same code, so you don’t pick one. In TypeScript, that means starting the server with serveStdio(createServer) (see Build in TypeScript).
What a server can expose
Section titled “What a server can expose”| Primitive | Controlled by | What it is | Example |
|---|---|---|---|
| Tools | The model decides to call them | Functions with a JSON Schema input that can take actions | create_ticket, query_orders |
| Resources | The app/user attaches them | Read-only data addressed by URI | db://schema, file:///notes/today.md |
| Prompts | The user picks them (often as / commands) |
Reusable message templates with arguments | /summarise-incident <id> |
Tools are by far the most widely supported and most used. Build tools first, and add resources or prompts only if your target clients support them and they help.
A server can also get things from the client, if the client supports it:
| Client feature | What the server gets | Status in 2026-07-28 |
|---|---|---|
| Elicitation | The user’s answer to a question (for example a confirmation or a missing field) | Current. The tool returns an input_required result instead of sending a request. Host support varies, so check your client’s docs |
| Sampling | A completion run on the client’s model | Deprecated. Don’t build new features on it |
| Roots | The directories or URIs the server may work in | Deprecated. Take allowed paths from configuration instead |
| Logging | Log messages shown by the client | Deprecated. Log to stderr instead |
Transports
Section titled “Transports”| Transport | How | Use for |
|---|---|---|
| stdio | The host launches your server as a child process and talks over stdin/stdout | Local tools, personal use, and anything touching local files. Simplest. |
| Streamable HTTP | Your server is an HTTP endpoint (for example https://api.example.com/mcp) with optional SSE streaming |
Remote or shared servers, SaaS integrations, claude.ai connectors, and multi-user setups |
| SSE (legacy) | The older HTTP + Server-Sent Events transport | Only for compatibility with old clients |
The number-one stdio bug: in a stdio server, stdout is the protocol channel. Any
console.logorprint()to stdout corrupts the stream, and the server “mysteriously” fails to connect. Log to stderr instead (console.error,print(..., file=sys.stderr), or the logging module).
Lifecycle
Section titled “Lifecycle”Current (2026-07-28):
1. server/discover client → server (optional: server info, capabilities, supported versions)2. tools/list client → server (discover tools)3. tools/call client → server (model invokes a tool) ... repeat; each request carries the protocol version4. shutdown close transport / kill processLegacy (2025 revisions):
1. initialize client → server (protocol version, client capabilities)2. initialize result server → client (server info, capabilities: tools/resources/prompts)3. initialized client → server (notification)4. tools/list client → server (discover tools)5. tools/call client → server (model invokes a tool) ... repeat6. shutdown close transport / kill processThe official SDKs handle all of this for you. You write the tool handlers.
Anatomy of a tool
Section titled “Anatomy of a tool”{ "name": "search_orders", "title": "Search orders", "description": "Search customer orders by email, order number, or date range. Returns at most 20 orders, newest first, with status and total. Use get_order for full line items. Dates are ISO 8601 (YYYY-MM-DD).", "inputSchema": { "type": "object", "properties": { "email": { "type": "string", "description": "Customer email (exact match)" }, "since": { "type": "string", "format": "date", "description": "ISO date, inclusive" }, "limit": { "type": "integer", "minimum": 1, "maximum": 20, "default": 10 } } }, "annotations": { "readOnlyHint": true, "openWorldHint": true }}A tool result contains content (text, images, audio, resource links, and embedded resources) and, optionally, structuredContent that matches an outputSchema. Failures are returned as results with isError: true, so the model can see what went wrong and recover.
Build vs install
Section titled “Build vs install”Before you build a server, check for an existing one:
- the official MCP Registry at https://registry.modelcontextprotocol.io, and the reference servers at https://github.com/modelcontextprotocol/servers
- the vendor’s own official server (GitHub, Linear, Sentry, Stripe, and others publish them)
- Cursor’s MCP directory and Claude’s connectors directory
Build your own when no trusted server exists, when you need your internal systems, or when existing servers expose far too many tools for your use case.
Official SDKs
Section titled “Official SDKs”| Language | Package | Guide |
|---|---|---|
| TypeScript | @modelcontextprotocol/server (v2; @modelcontextprotocol/sdk was v1) |
Build in TypeScript |
| Python | mcp v2 (MCPServer; it was FastMCP in v1) |
Build in Python |
| Others | C#, Java, Kotlin, Go, Rust, Ruby, Swift, PHP | https://modelcontextprotocol.io |
Next: Build in TypeScript or Build in Python