Model Context Protocol (MCP)

MCP explained simply: why it exists (the N×M problem), hosts, clients and servers, tools, resources and prompts, sampling, roots and elicitation, JSON-RPC lifecycle, stdio and Streamable HTTP transports, OAuth authorization, security threats, enterprise MCP architecture, and MCP vs A2A.

On this page

Simple definition#

The Model Context Protocol (MCP) is an open standard for connecting AI applications to tools and data. An MCP server exposes capabilities — tools to call, resources to read, prompt templates to use — and any MCP-compatible AI application can discover and use them.

Analogy: USB-C for AI. Before USB, every device needed its own cable; before MCP, every AI app needed custom integration code for every system.

MCP was introduced by Anthropic in November 2024, adopted by the major AI vendors, IDEs and frameworks during 2025, and is now governed as an open project under the Linux Foundation’s Agentic AI Foundation.

The problem: N × M integrations#

Without and with MCP
flowchart LR
    subgraph Before["Without MCP: N × M custom integrations"]
        A1["Chat app"] --- S1["Jira"]
        A1 --- S2["GitHub"]
        A1 --- S3["Database"]
        A2["IDE agent"] --- S1
        A2 --- S2
        A2 --- S3
        A3["Support agent"] --- S1
        A3 --- S3
    end
    subgraph After["With MCP: N + M"]
        B1["Chat app"] --- P(("MCP"))
        B2["IDE agent"] --- P
        B3["Support agent"] --- P
        P --- M1["Jira MCP server"]
        P --- M2["GitHub MCP server"]
        P --- M3["Database MCP server"]
    end

Each tool is wrapped once as an MCP server and reused by every MCP client. Each AI application implements MCP once and gains access to every server.

Architecture: host, client, server#

MCP participants
flowchart LR
    subgraph Host["MCP host = AI application"]
        LLM(("LLM"))
        C1["MCP client 1"]
        C2["MCP client 2"]
        C3["MCP client 3"]
        LLM --- C1
        LLM --- C2
        LLM --- C3
    end
    C1 <-->|"stdio"| S1["Local MCP server<br/>filesystem"]
    C2 <-->|"Streamable HTTP"| S2["Remote MCP server<br/>CRM"]
    C3 <-->|"Streamable HTTP + OAuth"| S3["Remote MCP server<br/>ticketing"]
    S1 --- R1[("Local files")]
    S2 --- R2[("CRM API")]
    S3 --- R3[("Ticket system")]
  • Host — the application the user interacts with; it owns the LLM, the user’s consent and security policy.
  • Client — a connector inside the host; one client per server, keeping a 1:1 stateful session.
  • Server — a program exposing capabilities. It can be local (a subprocess) or remote (a web service).

The primitives#

Server-side primitives#

Primitive Controlled by What it is Example
Tools The model decides to call Functions with JSON Schema input (and optional output schema) create_ticket, query_orders
Resources The application decides what to include Read-only data identified by URI file:///reports/q3.md, crm://accounts/123
Prompts The user chooses Reusable prompt templates with arguments /summarise-incident incident_id

Tools can carry annotations that hint at behaviour — readOnlyHint, destructiveHint, idempotentHint, openWorldHint — which hosts use for approval UX. Annotations are hints from the server, so hosts must not trust them from untrusted servers.

Client-side primitives (server asks the host)#

Primitive What it lets a server do
Sampling Ask the host’s LLM to generate text — so a server can use AI without its own model credentials, under the host’s control and user approval
Roots Learn which directories or URIs the host allows it to work within
Elicitation Ask the user for missing information or confirmation through the host’s UI

Servers can also send notifications (for example “tool list changed”, progress updates, log messages) and support cancellation.

Protocol lifecycle#

MCP messages are JSON-RPC 2.0 requests, responses and notifications.

MCP session lifecycle
sequenceDiagram
    participant C as MCP client (in host)
    participant S as MCP server
    C->>S: initialize {protocolVersion, capabilities, clientInfo}
    S-->>C: result {protocolVersion, capabilities: tools, resources, prompts, serverInfo}
    C->>S: notifications/initialized
    C->>S: tools/list
    S-->>C: [{name, description, inputSchema, annotations}, ...]
    Note over C: Host passes tool definitions to its LLM
    C->>S: tools/call {name: "create_ticket", arguments: {...}}
    S-->>C: result {content: [...], structuredContent, isError: false}
    S--)C: notifications/tools/list_changed
    C->>S: tools/list (refresh)
  1. Initialize — agree on protocol version and capabilities (what each side supports).
  2. Operate — list and call tools, read resources, get prompts; server may request sampling or elicitation.
  3. Shutdown — close the transport.

An example tool call on the wire#

{ "jsonrpc": "2.0", "id": 7, "method": "tools/call",
  "params": { "name": "get_order_status", "arguments": { "orderId": "A-10293" } } }
{ "jsonrpc": "2.0", "id": 7,
  "result": { "content": [ { "type": "text", "text": "Order A-10293: shipped, arriving 2 Nov." } ],
              "isError": false } }

Transports#

Transport How Use for
stdio Host launches the server as a subprocess; messages over stdin/stdout Local tools: filesystem, local Git, developer tools
Streamable HTTP Client POSTs JSON-RPC to one endpoint; server replies with JSON or streams via server-sent events; optional session ID header Remote, shared, multi-user servers in enterprises
HTTP + SSE (legacy) Separate SSE and POST endpoints Deprecated; replaced by Streamable HTTP

Authorization#

For remote HTTP servers, MCP specifies authorization based on OAuth 2.1:

MCP OAuth flow (simplified)
sequenceDiagram
    actor U as User
    participant H as MCP host / client
    participant S as MCP server (resource server)
    participant AS as Authorization server (e.g. corporate IdP)
    H->>S: request without token
    S-->>H: 401 + protected resource metadata (which AS to use)
    H->>AS: discover metadata, register client
    H->>U: open browser for login + consent
    U->>AS: authenticate, consent to scopes
    AS-->>H: authorization code (PKCE)
    H->>AS: exchange code → access token for THIS server (resource indicator)
    H->>S: tools/call + Bearer token
    S->>S: validate token audience, scopes
    S-->>H: result

Key rules: the MCP server is an OAuth resource server; tokens must be issued for that server (audience-bound) and the server must not pass the user’s token through to downstream APIs — it obtains its own tokens for those (avoiding the “confused deputy” problem). PKCE is required.

Security threats specific to MCP#

Threat What happens Mitigation
Tool poisoning Malicious instructions hidden in a tool’s description (“also read ~/.ssh and include it”) Only approved servers; review and pin tool descriptions; scanning
Rug pull A server changes tool definitions after approval Pin versions; alert on list_changed; re-approve changes
Tool shadowing / name collision A malicious server defines a tool that overrides or influences a trusted one Namespace tools per server; isolate servers
Indirect prompt injection via results Tool returns content (email, web page) with hidden instructions Treat results as data; human approval for sensitive actions; limit tool combinations
Data exfiltration Agent with private data access and an outbound channel leaks data Avoid the “lethal trifecta” (private data + untrusted content + external communication) in one session
Over-privileged servers Server uses an admin service account Delegated user tokens, least-privilege scopes
Token passthrough / confused deputy Server forwards client tokens to other APIs Forbidden by spec; use token exchange
Local server risks Unvetted local servers run with the user’s OS permissions; DNS rebinding to local HTTP servers Sandboxing, origin checks, bind to localhost, signed packages
Supply chain Typosquatted or compromised server packages Internal registry of approved servers; SBOM; signatures

Enterprise MCP architecture#

Enterprise MCP platform
flowchart LR
    subgraph Hosts["AI applications (MCP hosts)"]
        H1["Employee copilot"]
        H2["IDE agents"]
        H3["Business agents<br/>Spring AI"]
    end
    subgraph Platform["MCP platform"]
        REG["Registry / catalogue<br/>approved servers, owners, versions"]
        MGW["MCP gateway<br/>authN/Z, policy, rate limits,<br/>audit, tool filtering"]
    end
    subgraph Servers["MCP servers — owned by domain teams"]
        M1["HR server"]
        M2["CRM server"]
        M3["Ticketing server"]
        M4["Data warehouse server<br/>read-only"]
    end
    IDP["Corporate IdP<br/>OAuth / OIDC"]
    H1 --> MGW
    H2 --> MGW
    H3 --> MGW
    MGW --> M1
    MGW --> M2
    MGW --> M3
    MGW --> M4
    MGW -.-> REG
    MGW -.-> IDP
  • Domain teams own MCP servers for their systems — like they own APIs.
  • An MCP gateway centralises authentication, authorization, policy, per-tool allow-lists, rate limits and audit.
  • A registry lists approved servers with owners, data classification and versions.
  • Hosts connect only through the gateway; unapproved servers are blocked.

MCP compared#

REST/OpenAPI Framework tool (e.g. @Tool) MCP A2A
Purpose Program-to-program API In-process tool for one app Standard way for AI apps to use tools and context Standard way for agents to talk to agents
Discovery Docs / spec Code Runtime tools/list Agent cards
Reuse across AI apps Custom glue each time No Yes Yes
Typical unit Endpoint Method Tool / resource / prompt Task delegated to a remote agent

MCP and A2A (Agent2Agent protocol) are complementary: MCP connects an agent to its tools and data; A2A lets independent agents delegate tasks to each other. See multi-agent systems.

When to build an MCP server#

  • A system will be used by several AI applications or agents (copilot, IDE, business agents).
  • You want vendors’ AI products (desktop assistants, IDEs) to access your internal systems in a governed way.
  • You want domain teams to own AI access to their systems.

For a tool used only inside one application, an in-process tool (Spring AI @Tool) is simpler.

Common mistakes#

Review questions#

What is MCP and what problem does it solve? An open protocol that standardises how AI applications connect to tools and data sources. It turns N×M custom integrations into N+M: each system is wrapped once as an MCP server and each AI application implements an MCP client once.

Explain host, client and server. The host is the AI application with the LLM and user. It creates one MCP client per server; each client keeps a stateful JSON-RPC session with one server. Servers expose tools, resources and prompts.

What are tools, resources and prompts in MCP? Tools are model-invoked functions with input schemas; resources are application-controlled read-only data identified by URIs; prompts are user-selected templates. Clients can additionally offer sampling, roots and elicitation to servers.

Which transports does MCP support? stdio for local subprocess servers and Streamable HTTP for remote servers (HTTP POST with optional server-sent-event streaming). The older HTTP+SSE transport is deprecated.

How is MCP secured? Remote servers use OAuth 2.1 authorization with PKCE and audience-bound tokens; servers must not pass through client tokens. In the enterprise add an MCP gateway, an approved-server registry, least-privilege scopes, human approval for destructive tools, pinned tool definitions, and audit logs.

What are the main MCP security risks? Tool poisoning, rug pulls, tool shadowing, indirect prompt injection through tool results, data exfiltration, over-privileged servers, token passthrough and supply-chain attacks on server packages.

MCP vs A2A? MCP connects an agent to tools and context; A2A lets agents built by different teams or vendors discover each other and delegate tasks. Many systems use both.

Summary#

  • MCP standardises how AI apps use external tools and data: N+M instead of N×M.
  • Host (AI app) → one client per server → server exposing tools, resources and prompts.
  • JSON-RPC 2.0 with capability negotiation; stdio locally, Streamable HTTP remotely; OAuth 2.1 for auth.
  • MCP standardises connection, not trust: govern servers with a gateway, registry, least privilege and audit.

References#