Model Context Protocol

How MCP actually works - the complete picture

MCP is the "USB-C for AI apps": one open protocol that lets any AI assistant plug into any tool, database, or API without custom glue code. Here's the what, how, why, and where it's going - with sequence diagrams, a full 0โ†’100 runtime flow, and real case studies.

JSON-RPC 2.0 stdio ยท HTTP/SSE Tools ยท Resources ยท Prompts Open standard
01 - What

What is MCP?

The Model Context Protocol is an open standard (introduced by Anthropic in late 2024) that defines a universal way for AI applications to connect to external systems. Before MCP, every integration between an AI app and a tool was bespoke: M apps ร— N tools = Mร—N custom connectors. MCP turns that into M+N - build a server once, and every MCP-compatible client can use it.

๐Ÿ–ฅ๏ธ Host

The user-facing AI app - Claude Code, Claude Desktop, an IDE, or your own agent built on the SDK. It runs the model and orchestrates everything.

๐Ÿ”Œ Client

A connector living inside the host. One client per server, maintaining a 1:1 stateful session and speaking MCP on the model's behalf.

โš™๏ธ Server

A separate program exposing capabilities - a filesystem, a database, GitHub, Slack, a private API. It does the real work when asked.

The three things a server exposes

PrimitiveWhat it isControlled byExample
ToolsCallable functions with typed inputs/outputsThe model decides when to callcreate_issue(), run_query()
ResourcesReadable data / context, addressed by URIThe app / user attachesfile:///report.pdf, db://users/42
PromptsReusable, parameterized prompt templatesThe user invokes (slash commands)/summarize-pr, /plan-sprint
Key mental model: the LLM never touches your database or API directly. It emits a structured request; the host mediates and approves; the server executes. MCP is the standardized contract in the middle.
02 - Why

Why MCP exists

LLMs are powerful but isolated - trapped behind their training cutoff with no access to your live data or the ability to act. Every team solving this independently produced brittle, one-off integrations. MCP standardizes the connection layer.

๐Ÿงฉ Solves the Mร—N problem

Write a server once; every MCP host (Claude, Cursor, Windsurf, custom agents) can use it. No re-integration per app.

๐Ÿ”„ Swappable & composable

Because tools are discovered at runtime, you can add, remove, or upgrade servers without touching the host. Agents compose many servers.

๐Ÿ” Clear trust boundaries

The host mediates every call and can require user approval. Servers run as isolated processes with scoped permissions and their own auth.

๐ŸŒ Open & vendor-neutral

An open spec with SDKs in Python, TypeScript, Java, C#, Go and more. Not tied to one model or one company.

03 - How

How it works under the hood

Every message is JSON-RPC 2.0. The client and server exchange requests, responses, and notifications over a transport. Two transports dominate:

๐Ÿ“Ÿ stdio (local)

The server is a subprocess; messages flow over stdin/stdout. Fast, no network, ideal for local tools (filesystem, git). Auth is implicit - it runs as you.

๐ŸŒ Streamable HTTP + SSE (remote)

The server is a web service reached over HTTP, with Server-Sent Events for streaming. Serves many clients, and uses OAuth 2.1 for authentication.

The connection lifecycle

Architecture - one host, many servers, one client per server
flowchart LR
    subgraph Host["๐Ÿ–ฅ๏ธ  Host  (Claude Code / Desktop)"]
        LLM["๐Ÿง  LLM"]
        C1["๐Ÿ”Œ Client A"]
        C2["๐Ÿ”Œ Client B"]
        C3["๐Ÿ”Œ Client C"]
        LLM <--> C1
        LLM <--> C2
        LLM <--> C3
    end
    C1 <-->|stdio| S1["โš™๏ธ Filesystem Server"]
    C2 <-->|HTTP/SSE| S2["โš™๏ธ GitHub Server"]
    C3 <-->|HTTP/SSE| S3["โš™๏ธ Postgres Server"]
    S1 --> D1[("๐Ÿ“ Local files")]
    S2 --> D2{{"๐ŸŒ GitHub API"}}
    S3 --> D3[("๐Ÿ—„๏ธ Database")]
        

A minimal config (Claude Code / Desktop)

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres",
               "postgresql://localhost/mydb"]
    },
    "github": {
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": { "Authorization": "Bearer ${GITHUB_TOKEN}" }
    }
  }
}

The first is a local stdio server spawned as a subprocess; the second is a remote HTTP server. Same protocol, different transport.

04 - Sequence Diagrams

Detailed sequence diagrams

Three views: the initial handshake & discovery, a tool call at runtime, and the OAuth flow for remote servers.

Diagram 1 - Initialization & capability discovery (once, at connect)
sequenceDiagram
    autonumber
    participant U as ๐Ÿ‘ค User
    participant H as ๐Ÿ–ฅ๏ธ Host
    participant C as ๐Ÿ”Œ Client
    participant S as โš™๏ธ Server

    U->>H: Launch app / add server
    H->>C: Spin up a client for this server
    C->>S: initialize (protocol version, capabilities)
    S-->>C: initialize result (server capabilities, info)
    C->>S: notifications/initialized
    Note over C,S: Session is now live
    C->>S: tools/list
    S-->>C: [tools + JSON Schemas]
    C->>S: resources/list
    S-->>C: [resources]
    C->>S: prompts/list
    S-->>C: [prompt templates]
    C-->>H: Register capabilities
    H->>H: Inject tool defs into model context
        
Diagram 2 - A tool call during a conversation (the hot path)
sequenceDiagram
    autonumber
    participant U as ๐Ÿ‘ค User
    participant LLM as ๐Ÿง  Model
    participant H as ๐Ÿ–ฅ๏ธ Host
    participant C as ๐Ÿ”Œ Client
    participant S as โš™๏ธ Server
    participant Ext as ๐ŸŒ Data / API

    U->>H: "How many signups last week?"
    H->>LLM: prompt + available tools
    LLM-->>H: tool_use: run_query(sql=...)
    H->>U: Approve calling run_query? (optional)
    U-->>H: โœ” Approve
    H->>C: dispatch tool call
    C->>S: tools/call { name, arguments }
    S->>Ext: SELECT count(*) FROM signups ...
    Ext-->>S: rows
    S-->>C: tools/call result (structured content)
    C-->>H: result
    H->>LLM: tool result appended to context
    LLM-->>H: "You had 1,284 signups last week."
    H-->>U: Final answer
        
Diagram 3 - OAuth 2.1 authorization for a remote server
sequenceDiagram
    autonumber
    participant U as ๐Ÿ‘ค User
    participant C as ๐Ÿ”Œ Client
    participant S as โš™๏ธ MCP Server
    participant A as ๐Ÿ”‘ Auth Server

    C->>S: tools/call (no / expired token)
    S-->>C: 401 Unauthorized + WWW-Authenticate
    C->>A: Discover metadata, register client
    C->>U: Open browser โ†’ consent screen
    U->>A: Log in & grant scopes
    A-->>C: Authorization code (redirect)
    C->>A: Exchange code + PKCE for tokens
    A-->>C: access_token (+ refresh_token)
    C->>S: Retry tools/call (Bearer token)
    S-->>C: 200 OK + result
        
05 - Step by Step

The 0 โ†’ 100 flow

Everything that happens from cold start to a completed, tool-assisted answer - the whole journey in order.

00
Setup

Author or install a server

Someone writes an MCP server (or you install a published one) that wraps a system - a DB, an API, the filesystem - and declares its tools, resources, and prompts.

10
Configure

Register the server with the host

Add it to config: a command for stdio, or a url for HTTP. The host now knows the server exists.

20
Launch

Host starts the client & transport

On startup the host spawns one client per server and opens the transport - a subprocess pipe (stdio) or an HTTP connection.

30
Handshake

initialize exchange

Client and server negotiate protocol version and advertise capabilities, then the client sends notifications/initialized. The session is live.

40
Discovery

List tools, resources, prompts

The client calls tools/list, resources/list, prompts/list. The server returns names, descriptions, and JSON Schemas.

50
Inject

Host hands tools to the model

The discovered tool definitions are formatted and placed into the model's context so it knows what it can call and with what arguments.

60
Reason

User asks; model decides

The user sends a request. The model reasons over it and the available tools, and emits a structured tool_use request if a tool would help.

70
Guard

Host intercepts & (maybe) asks approval

The host catches the tool call. For sensitive actions it prompts the user to approve. Auth is checked; remote servers may trigger the OAuth flow here.

80
Execute

Server does the real work

The client sends tools/call; the server runs the query / hits the API / reads the file and returns structured results (and can stream progress).

90
Integrate

Result flows back into context

The host appends the tool result to the conversation and calls the model again. The model may chain more tool calls - loop back to step 60 as needed.

100
Deliver

Model answers the user

With the fresh, real-world data in context, the model produces a grounded final answer. Session stays open for the next turn.

06 - Case Studies

Real-world case studies

Three representative patterns showing MCP in production-style use.

๐Ÿ‘ฉโ€๐Ÿ’ป

1 ยท The coding agent (Claude Code + GitHub + Postgres)

Pattern: developer productivity

A developer asks their assistant to "find the flaky test causing CI failures and open a fix PR." The agent composes three MCP servers.

  • Filesystem server (stdio) reads the failing test files and source.
  • Postgres server queries the CI results table to identify which test fails intermittently.
  • GitHub server (HTTP + OAuth) creates a branch, commits the fix, and opens a PR.
โœ… Outcome: One natural-language request spans three systems with no custom integration code - each server was installed once and is reused across every project.
๐Ÿข

2 ยท Enterprise knowledge assistant (internal wiki + Jira + Slack)

Pattern: retrieval + action over private data

A support engineer asks: "Summarize open P1 incidents this week and post a digest to #ops." The company runs remote MCP servers behind SSO.

  • Jira server exposes search_issues as a tool and issues as resources - the model pulls live P1 tickets.
  • Wiki server resources supply runbook context for each incident type.
  • Slack server exposes post_message; the host requires explicit approval before posting.
โœ… Outcome: OAuth scopes keep each user's access correct; the host's approval gate ensures the "write" action (posting) is human-confirmed. Same protocol, enterprise-grade trust.
๐ŸŽจ

3 ยท Design-to-code with Figma MCP

Pattern: bridging a proprietary app to any agent

A front-end dev selects a component in Figma and asks the agent to "build this as a React component." Figma ships an MCP server exposing the live design context.

  • The Figma server exposes the selected frame's structure, tokens, and layout as resources/tools.
  • The agent reads exact spacing, colors, and variants - not a screenshot guess.
  • The filesystem server writes the generated component into the repo.
โœ… Outcome: A proprietary desktop app becomes usable by any MCP client. Design intent transfers with high fidelity because the model reads structured data, not pixels.
07 - Future

Where MCP is heading

MCP went from a single-vendor spec to a broadly adopted standard remarkably fast. The trajectory points at richer, safer, more autonomous agents.

๐ŸŒ A registry & ecosystem

Public server registries for discovery and one-click install - an "app store" for agent capabilities, with signing and provenance.

๐Ÿค Agent-to-agent composition

Servers that are themselves agents, plus emerging agent-to-agent protocols, enabling networks of specialized agents that delegate to each other.

๐Ÿ” Stronger security & identity

Fine-grained scopes, standardized OAuth 2.1, tool-poisoning defenses, and auditability as MCP moves deeper into enterprises.

๐Ÿง  Elicitation & sampling

Servers can ask the user for input mid-task (elicitation) and request model completions from the host (sampling) - richer two-way interaction.

๐Ÿ“ฆ Native platform support

OS-level and IDE-level MCP hosts, so any app can become an agent surface without bespoke plumbing.

โšก Streaming & long-running work

Better support for progress streaming, cancellation, and durable long-running tasks - essential for real autonomous agents.

Bottom line: just as HTTP standardized the web and USB standardized peripherals, MCP is becoming the standard socket between AI models and the real world. Build a capability once - every agent, present and future, can use it.