The Model Context Protocol (MCP) is an open standard for connecting AI applications to external tools and data. An application that speaks MCP can use any MCP server, and a server written once works in every compatible application, so nobody has to write a separate integration for each pairing.
This article explains how the protocol works as of the current specification revision, 2026-07-28, which changed the protocol's shape considerably. It is for developers who want to connect an agent to MCP servers or publish a server of their own.
What MCP is and is not
MCP defines three roles. The host is the AI application the user works in, such as a chat client, an IDE or an agent runtime. The host runs one client per server it connects to, and each server exposes capabilities to that client. Messages are JSON-RPC 2.0, and the full definition lives in the MCP specification.
MCP is not a message bus between agents. It has no agent registration, no shared context store and no publish-subscribe channel for agents to talk to each other. It standardises one relationship: an application giving a model access to tools and data. Communication between independent agents is the subject of other protocols, such as Agent2Agent (A2A), and the two are commonly used together.
What a server exposes
A server offers up to three kinds of capability, and each is controlled by a different party.
- Tools are functions the model can decide to call, such as "convert currency" or "create issue". Each has a name, a description and a JSON Schema for its arguments.
- Resources are data the application can read and attach as context, identified by URI.
- Prompts are reusable templates that the user chooses to invoke.
The rest of this article concentrates on tools. The older client-side features have been cut back: the 2026-07-28 revision deprecates Roots, Sampling and Logging, with a removal window of at least twelve months, and its changelog advises new implementations not to adopt them.
Transports
The specification defines two transports. With stdio, the client starts the server as a subprocess and exchanges newline-delimited JSON-RPC messages over standard input and output. This suits local servers that need the user's files or credentials. The server must write nothing but protocol messages to stdout; logs go to stderr.
With Streamable HTTP, the server exposes a single endpoint that accepts POST. Each JSON-RPC request is its own HTTP request, and the server answers with either a JSON body or a Server-Sent Events stream scoped to that request. This is the transport for remote servers.
The original HTTP+SSE transport from the 2024-11-05 revision, which used separate SSE and POST endpoints, has been deprecated since 2025-03-26. Do not build new servers on it.
The stateless revision
Revisions up to 2025-11-25 were stateful. A client opened with an initialize handshake, the server could issue an Mcp-Session-Id, and a long-lived stream carried requests from server to client. That made remote servers awkward to run behind an ordinary load balancer.
The 2026-07-28 revision removes the handshake and protocol-level sessions. Every request now carries its protocol version, client identity and client capabilities in _meta, so any server instance can answer any request. Over HTTP the version, method and tool name are also mirrored into headers so that gateways can route and rate-limit without parsing the body. A tool call looks like this:
POST /mcp HTTP/1.1
Content-Type: application/json
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: get_weather
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": { "location": "Seattle, WA" },
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": { "name": "ExampleClient", "version": "1.0.0" },
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}Several other changes follow from statelessness:
- A server must implement
server/discover, which reports its supported versions, capabilities and identity. Calling it first is optional for the client. - A server can no longer send its own requests to the client. When a tool needs input mid-call, it returns a result with
resultType: "input_required", and the client retries the original call with the answers attached. The specification calls this the multi round-trip request pattern. - Change notifications, such as an updated tool list, arrive on a stream the client opens with
subscriptions/listen. The standaloneGETstream is gone. - List results carry
ttlMsandcacheScopeso clients can cache them, and servers should return tools in a stable order. - A server that needs state across calls returns an explicit handle from one tool, such as a basket ID, and accepts it as an argument to the next.
Tool results and errors
A successful call returns content blocks for the model and, optionally, structuredContent that matches the tool's outputSchema.
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"resultType": "complete",
"content": [{ "type": "text", "text": "Seattle: 12 °C, light rain" }],
"isError": false
}
}There are two kinds of failure, and the difference matters to the model. A protocol error, such as an unknown tool or a malformed request, is a JSON-RPC error object. A tool execution error, such as a rejected date or a failed upstream call, is a normal result with isError: true and a message the model can act on. The tools specification recommends returning execution errors to the model so it can correct its arguments and retry. Write those messages as instructions: "date must be in the future; today is 2026-11-15" is more useful than "invalid input".
Authorization
Authorization is optional and applies to HTTP transports. When a server uses it, the authorization specification builds on OAuth 2.1. The MCP server acts as a resource server. On a request without a token it responds 401 with a WWW-Authenticate header that points to its Protected Resource Metadata (RFC 9728), from which the client discovers the authorization server.
The client then runs an authorization code flow with PKCE and includes a resource parameter (RFC 8707) naming the MCP server. The server must check that each token was issued for it and must not pass the token on to other services. For client registration the current revision prefers Client ID Metadata Documents and deprecates Dynamic Client Registration.
Servers on stdio skip this flow and read credentials from their environment. Plenty of remote servers use an API key in a request header instead of OAuth, which the specification allows because authorization is optional.
Writing a server
The official SDKs handle the wire format. In version 2 of the TypeScript SDK, which implements the 2026-07-28 revision, the server package is @modelcontextprotocol/server. Version 1 was published as @modelcontextprotocol/sdk. The following is a complete stdio server with one tool; the input schema is defined with Zod and validated before the handler runs.
import { McpServer } from '@modelcontextprotocol/server';
import { serveStdio } from '@modelcontextprotocol/server/stdio';
import * as z from 'zod/v4';
function createServer() {
const server = new McpServer({ name: 'units', version: '1.0.0' });
server.registerTool(
'celsius_to_fahrenheit',
{
description: 'Convert a temperature from Celsius to Fahrenheit.',
inputSchema: z.object({ celsius: z.number() })
},
async ({ celsius }) => ({
content: [{ type: 'text', text: String(celsius * 9 / 5 + 32) }]
})
);
return server;
}
serveStdio(createServer);Install the dependencies with npm install @modelcontextprotocol/server zod and set "type": "module" in package.json, because the SDK ships as ES modules. The MCP Inspector lets you call the tool from a browser before you connect a real client.
Most of the quality of a server is in its tool design. Keep the list short, because every definition is sent to the model. Describe when to use a tool as well as what it does, and return compact results.
Finding servers
The MCP Registry is the official catalogue of publicly available servers. It stores metadata, such as a server's name, where its package or remote URL lives and how to run it, and it verifies namespaces against GitHub accounts or DNS. It does not host code or scan it for security problems. Its documentation still labels it a preview, and it is meant to feed marketplaces and client directories; host applications are not expected to query it directly.
Trying it with APIStack
APIStack exposes its APIs as MCP tools on every plan, including the free one. Two endpoints are described on the MCP page, and both use Streamable HTTP.
The facts server at https://apistack.online/api/mcp/facts works without an account for 50 calls a day. It offers a small set of tools for questions a model should not answer from memory, such as get_current_time, check_working_day, convert_currency and validate_iban. To add it to Claude Code:
claude mcp add --transport http apistack-facts https://apistack.online/api/mcp/factsYou can also call it directly to see the protocol. The APIStack servers currently implement the handshake-based revisions, up to 2025-06-18, and they keep no session, so a single request is enough:
curl -s https://apistack.online/api/mcp/facts \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"convert_currency","arguments":{"from":"USD","to":"EUR","amount":100}}}'The unified endpoint at https://apistack.online/api/mcp/connect covers the whole catalogue and needs your API key in the x-api-key header. It exposes three tools, search_apis, get_api_details and call_api, so the model can look up an API when it needs one without dozens of definitions loaded up front. Calls count against your plan quota exactly as REST calls do. The free plan includes 1,000 calls a month.
Operating safely
Tool descriptions and tool results are untrusted input to the model. A malicious or compromised server can use either to steer it. Connect only to servers you trust, and remember that tool annotations such as readOnlyHint are hints from the server and guarantee nothing.
Keep a person in the loop for actions with side effects. The specification says applications should show which tools are exposed and ask for confirmation before sensitive operations. Give each server the narrowest credentials that work. On the server side, validate every argument, rate-limit calls and validate the Origin header on HTTP endpoints, which the transport specification requires in order to prevent DNS rebinding.
Summary
- MCP standardises how an AI application reaches tools, resources and prompts over JSON-RPC. It is not an agent-to-agent messaging system.
- Use stdio for local servers and Streamable HTTP for remote ones. The older HTTP+SSE transport is deprecated.
- The
2026-07-28revision is stateless: noinitializehandshake and no session ID, with version and capabilities sent on every request. - Authorization for HTTP servers is optional and based on OAuth 2.1, with tokens bound to the server they were issued for.
- Treat tool descriptions and results as untrusted, keep tool lists short and require confirmation for actions that change anything.