What is the Model Context Protocol (MCP)? How it works

Explainer · MCP

The Model Context Protocol (MCP) is an open protocol that standardizes how AI applications connect to external tools, data sources, and workflows. Anthropic introduced MCP in November 2024 to replace fragmented, one-off integrations: a team writes an MCP server once, and any MCP-compatible application, from a chat client to a coding agent, can use it. This explainer covers the architecture, walks through a tool call on the wire, and goes into the parts most overviews skip: the stateless redesign in the current specification, transports and authorization, security risks, and where MCP gateways fit.

What is the Model Context Protocol?#

MCP is an open specification, built on JSON-RPC 2.0, that defines how AI applications discover and use the tools, resources, and prompts that external MCP servers expose.

The problem MCP addresses is combinatorial. Without a shared protocol, every AI application needs its own connector for every system it touches, so ten applications and twenty systems means up to two hundred integrations. With MCP, each system ships one server and each application ships one client implementation. The specification credits the Language Server Protocol as inspiration, since LSP solved the same problem for programming-language support in editors.

MCP is deliberately narrow. The protocol covers context exchange between programs; it does not dictate how an application prompts a large language model or manages its context window. Those decisions stay with the application, which is why MCP pairs naturally with context engineering work. The normative definition of the protocol is a TypeScript schema published alongside the specification, and every revision is identified by a date string.

MCP architecture: host vs client vs server#

MCP has three roles. The host is the AI application the user runs, such as an IDE or a chat app. The host creates one MCP client for each server it connects to. Each MCP server is a separate program that exposes capabilities, running either locally as a subprocess or remotely behind an HTTP endpoint.

The official architecture guide uses Visual Studio Code as its example host. When VS Code connects to a remote Sentry server and a local filesystem server, it instantiates two client objects, one per connection. Local servers that use stdio typically serve a single client, while remote servers that use Streamable HTTP typically serve many.

An MCP host application runs three clients, one per server; two connect over stdio to local servers and one over Streamable HTTP to a remote server. MCP hostHost applicationIDE, chat app, or coding agentModel calls · consent UI · policy · contextClient 1Client 2Client 3FilesystemLocal serverDatabaseLocal serverSaaS serverRemote serverstdiostdioStreamable HTTP
Figure 1: One MCP host runs one client per server, local or remote.

The host is where the important decisions live: which model runs, what enters the prompt, which tool calls need user approval, and which data may leave the machine. An MCP server sees only the arguments and metadata in the requests it receives. That split is the basis of MCP's trust model, because the specification requires hosts to obtain explicit user consent before exposing user data to servers or invoking tools.

MCP tools, resources, and prompts#

MCP servers expose three primitives, and the difference between them is who controls their use. Tools are functions the model can invoke. Resources are data the application attaches as context. Prompts are templates a user selects, such as a slash command. A single server can offer all three, and clients discover each through a list method.

Primitive Controlled by Main methods Example
Tools Model tools/list, tools/call Create a ticket, run a SQL query
Resources Application resources/list, resources/read File contents, a database schema
Prompts User prompts/list, prompts/get A /review-pr slash command

A database server illustrates the split: it can expose query tools, a resource containing the schema, and a prompt with few-shot examples for using the tools. Each tool definition carries a name, a model-readable description, an inputSchema in JSON Schema (2020-12 by default), and optionally an outputSchema and behavioral annotations. A tool's structuredContent result is server-produced data, unrelated to structured outputs from the model.

Clients can offer features back to servers. Elicitation lets a server ask the user for input mid-request, such as a missing username or a confirmation. The 2026-07-28 revision deprecated two older client features, sampling and roots: servers that need a model should call a provider API directly, and servers that need directories should take them as tool parameters or configuration.

How does MCP work? A tool call step by step#

A tool call in MCP is a loop between the model, the host, and a server. The host lists the server's tools, passes their definitions to the model through the provider's tool calling API, receives a tool call from the model, sends it to the server as tools/call, and returns the result to the model's context.

Sequence between user, host, and MCP server: the host lists tools, the model emits a call, the user approves it, the server returns a result, and the host answers. UserHostModel + MCP clientMCP server1"File a bug for this"2tools/list3tool definitions4model emits create_issue5approve this call?6approve7tools/call8result (content)9result added to context10answer with issue link
Figure 2: A single MCP tool call, including the user approval step.

On the wire, the call is one JSON-RPC request. In the 2026-07-28 revision, every request carries the protocol version and client capabilities in _meta, usually alongside a clientInfo identity block:

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "weather_current",
    "arguments": { "location": "San Francisco", "units": "imperial" },
    "_meta": {
      "io.modelcontextprotocol/protocolVersion": "2026-07-28",
      "io.modelcontextprotocol/clientCapabilities": { "elicitation": {} }
    }
  }
}

The server answers with a content array of text, images, audio, or resource links, plus optional structuredContent. Errors that a corrected call can resolve, such as a date in the wrong format, come back as a normal result with isError: true, so the model receives the message and can emit a new call with fixed arguments.

What changed in the 2026-07-28 revision#

The 2026-07-28 changelog made MCP stateless. The initialize handshake and the Mcp-Session-Id header are gone; a client that wants versions and capabilities up front calls the mandatory server/discover method. Servers that need state across calls, such as a shopping cart, return an explicit handle that the model passes back as a tool argument. When a server needs user input, it returns a result with resultType: "input_required", and the client retries the original request with the answers. Long-running work moved to an opt-in Tasks extension.

MCP transports: stdio and Streamable HTTP#

MCP defines two standard transports. With stdio, the host launches the server as a subprocess and exchanges newline-delimited JSON-RPC messages over standard input and output. With Streamable HTTP, the server runs independently, and the client sends each message as an HTTP POST to one endpoint and receives either JSON or a server-sent events stream.

  • stdio: the server must write only valid MCP messages to stdout and may log to stderr. Cancellation is a notifications/cancelled message, and closing stdin is the shutdown signal.
  • Streamable HTTP: introduced in revision 2025-03-26 to replace the original HTTP+SSE transport, which is now formally deprecated. Every POST carries MCP-Protocol-Version and Mcp-Method headers, plus Mcp-Name for tools/call, resources/read, and prompts/get; these mirror the body, and servers reject mismatches with a HeaderMismatch error.
  • Custom transports: allowed, provided they keep the JSON-RPC format and message patterns. Byte-stream transports such as Unix sockets should reuse stdio framing.

The header mirroring exists so load balancers and gateways can route requests without parsing JSON bodies. The transport also carries hard security rules: Streamable HTTP servers must validate the Origin header to block DNS rebinding, and local servers should bind to 127.0.0.1 rather than all interfaces.

MCP security risks and best practices#

The main security risk in MCP is that tools are arbitrary code execution reached through text a model reads. The specification assigns hosts responsibility for user consent, data privacy, and tool safety, but it states that MCP cannot enforce those principles at the protocol level, so every host and server implementer has to build them.

The MCP security best practices document lists concrete attacks. The ones that matter most in practice:

  • Prompt injection through tools: tool descriptions, annotations, and results all enter the model's context, so a malicious server or poisoned data can carry instructions. The specification says clients must treat annotations from untrusted servers as untrusted and should validate tool results before passing them to the model. See prompt injection.
  • Local server compromise: a one-click install configuration can run any command. Clients must show the full command and require approval, and should sandbox local servers.
  • Token passthrough and confused deputy: a server that forwards a client's token to a downstream API breaks audit trails and trust boundaries. Servers must accept only tokens issued for themselves.
  • Server-side request forgery: a malicious server can point OAuth metadata URLs at internal addresses such as cloud metadata endpoints. Clients should enforce HTTPS and block private IP ranges.
  • State handle hijacking: possession of a cart or workflow handle is not authentication, so servers should bind handles to the authenticated user.

Authorization in MCP#

Authorization is optional in MCP, and the specification defines it only for HTTP transports; stdio servers should read credentials from the environment. A protected MCP server acts as an OAuth 2.1 resource server and must publish Protected Resource Metadata (RFC 9728) so clients can find its authorization server. Clients must send a Resource Indicator (RFC 8707) naming the server, which binds each token to one audience, and use PKCE. Client ID Metadata Documents are the preferred registration method; Dynamic Client Registration was deprecated in 2026-07-28.

Operationally, teams running MCP at scale allowlist approved servers, pin server versions, require approval for write operations, apply guardrails to tool inputs and outputs, and log every tool call for LLM observability.

MCP vs function calling (and MCP vs API)#

MCP and function calling operate at different layers. Function calling is a model API feature: the model returns a structured request to call a function the application described. MCP standardizes where those function definitions come from and how the call is executed, so the same tools work across hosts without per-application glue code.

Function calling MCP
What it is Feature of a model provider's API Client-server protocol between programs
Where tools are defined In each application's request In an MCP server, discovered at runtime
Who executes the call The application's own code The MCP server, via the host's client
Reuse across applications Reimplemented per application One server, many hosts
Scope Functions only Tools, resources, prompts, elicitation

The two are layered, not competing: a host translates MCP tool definitions into whatever format its model provider expects, and the model's tool call is then routed to the right server. Our tool calling guide covers the model side of that loop.

The same reasoning answers "MCP vs API." An MCP server often wraps an existing REST API. The API remains the system of record; the MCP layer adds runtime discovery, descriptions written for models, JSON Schema inputs, and a consent model that a raw API does not provide.

What is an MCP gateway?#

An MCP gateway is a proxy that sits between MCP hosts and many MCP servers and exposes them through one managed endpoint. The MCP specification does not define gateways; they are an operational pattern for centralizing authentication, tool allowlists, rate limits, and audit logs across an organization's servers.

The specification anticipates intermediaries in several places. Aggregators should handle tool-name collisions, since two servers can both expose a search tool and server names are not guaranteed unique; prefixing tool names with a server identifier is the suggested fix. The ttlMs and cacheScope fields on list results tell shared intermediaries whether a response may be cached. The specification also warns that intermediaries enforcing policy on mirrored headers should reject requests from protocol versions that predate header and body validation.

The difference between an MCP gateway and an MCP server is role, not wire format: to a host, a gateway looks like one server, but it implements few or no tools of its own. The pattern mirrors AI gateways, which apply the same controls to model traffic, and some products in the AI gateway category also act as MCP gateways. Bifrost, for example, exposes the MCP servers it connects to through one /mcp endpoint, filters each client's tool list by virtual key, and leaves tool execution to the host unless its agent mode is turned on. agentgateway and LiteLLM also handle model and tool traffic in one proxy.

The MCP ecosystem, versions, and governance#

MCP is versioned by date, and the current revision is 2026-07-28. Anthropic donated MCP to the Agentic AI Foundation, a directed fund under the Linux Foundation, in December 2025. The ecosystem includes official SDKs, reference servers, the MCP Inspector, and an official server registry.

Revision Notable changes
2024-11-05 First public release, with stdio and the original HTTP+SSE transport
2025-03-26 OAuth 2.1 authorization framework, Streamable HTTP, tool annotations
2025-06-18 Structured tool output, elicitation, servers as OAuth resource servers
2025-11-25 Client ID Metadata Documents, URL-mode elicitation, experimental tasks
2026-07-28 Stateless protocol, server/discover, Tasks extension, deprecations

The Agentic AI Foundation launched with MCP, Block's goose, and OpenAI's AGENTS.md as founding projects, and Anthropic's announcement listed ChatGPT, Cursor, Gemini, Microsoft Copilot, and Visual Studio Code among the products that support MCP. The official registry at registry.modelcontextprotocol.io is a community-maintained catalog for discovering servers. Optional extensions, declared in client and server capabilities, add features such as long-running Tasks and MCP Apps for interactive UI.

The foundation also hosts the Agent2Agent protocol, which handles a different job: communication between agents rather than between an agent and its tools. The A2A vs MCP comparison explains how the two fit together, and the A2A protocol glossary entry gives the short version.

Where to go next#

MCP is the tool layer for AI agents, so the agent loop is the natural next read. For the protocol that connects agents to each other, read A2A vs MCP. The MCP topic hub collects every guide, glossary entry, and comparison on the protocol in one place.

Frequently asked questions

What is MCP in AI?

In AI, MCP stands for the Model Context Protocol, an open standard for connecting AI applications such as chat clients, IDEs, and coding agents to external tools and data. An MCP server exposes tools, resources, and prompts over JSON-RPC 2.0, and any MCP-compatible host can discover and use them without custom integration code for each application.

What is an MCP server?

An MCP server is a program that exposes capabilities to AI applications through the Model Context Protocol. A server can offer tools the model can call, resources the application can read as context, and prompt templates a user can select. Servers run locally as subprocesses over stdio or remotely behind an HTTP endpoint using the Streamable HTTP transport.

Is MCP open source?

Yes. The MCP specification, official SDKs, reference servers, and the MCP Inspector are developed in public repositories under the modelcontextprotocol GitHub organization, and new contributions are licensed under Apache 2.0. Anthropic created MCP and donated it in December 2025 to the Agentic AI Foundation, a directed fund under the Linux Foundation.

Is MCP secure?

MCP is as secure as its implementation. The specification defines OAuth 2.1-based authorization for HTTP servers and requires audience-bound tokens, but it cannot enforce user consent or sandboxing at the protocol level. Hosts must confirm tool calls, treat tool descriptions and results as untrusted input, and run local servers with limited privileges.

What is the difference between MCP and an API?

An API is an interface a developer codes against, with endpoints documented for humans. MCP is a protocol that sits in front of APIs and other systems so AI applications can discover capabilities at runtime. An MCP server often wraps an existing REST API, adding model-readable tool descriptions, JSON Schema inputs, and a standard way to call them.

Terms in this guide

Cite this guide

The AI Engineering Editors. "What is the Model Context Protocol (MCP)? How it works." The AI Engineering, updated Nov 11, 2026. https://theaiengineering.com/articles/what-is-model-context-protocol

Title
What is the Model Context Protocol (MCP)? How it works
Author
The AI Engineering Editors
Publisher
The AI Engineering
Published
Updated
View as Markdown

The AI Engineering Editors ·