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.
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.
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.
A connector living inside the host. One client per server, maintaining a 1:1 stateful session and speaking MCP on the model's behalf.
A separate program exposing capabilities - a filesystem, a database, GitHub, Slack, a private API. It does the real work when asked.
| Primitive | What it is | Controlled by | Example |
|---|---|---|---|
| Tools | Callable functions with typed inputs/outputs | The model decides when to call | create_issue(), run_query() |
| Resources | Readable data / context, addressed by URI | The app / user attaches | file:///report.pdf, db://users/42 |
| Prompts | Reusable, parameterized prompt templates | The user invokes (slash commands) | /summarize-pr, /plan-sprint |
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.
Write a server once; every MCP host (Claude, Cursor, Windsurf, custom agents) can use it. No re-integration per app.
Because tools are discovered at runtime, you can add, remove, or upgrade servers without touching the host. Agents compose many servers.
The host mediates every call and can require user approval. Servers run as isolated processes with scoped permissions and their own auth.
An open spec with SDKs in Python, TypeScript, Java, C#, Go and more. Not tied to one model or one company.
Every message is JSON-RPC 2.0. The client and server exchange requests, responses, and notifications over a transport. Two transports dominate:
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.
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.
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")]
{
"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.
Three views: the initial handshake & discovery, a tool call at runtime, and the OAuth flow for remote servers.
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
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
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
Everything that happens from cold start to a completed, tool-assisted answer - the whole journey in order.
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.
Add it to config: a command for stdio, or a url for HTTP. The host now knows the server exists.
On startup the host spawns one client per server and opens the transport - a subprocess pipe (stdio) or an HTTP connection.
initialize exchangeClient and server negotiate protocol version and advertise capabilities, then the client sends notifications/initialized. The session is live.
The client calls tools/list, resources/list, prompts/list. The server returns names, descriptions, and JSON Schemas.
The discovered tool definitions are formatted and placed into the model's context so it knows what it can call and with what arguments.
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.
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.
The client sends tools/call; the server runs the query / hits the API / reads the file and returns structured results (and can stream progress).
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.
With the fresh, real-world data in context, the model produces a grounded final answer. Session stays open for the next turn.
Three representative patterns showing MCP in production-style use.
A developer asks their assistant to "find the flaky test causing CI failures and open a fix PR." The agent composes three MCP servers.
A support engineer asks: "Summarize open P1 incidents this week and post a digest to #ops." The company runs remote MCP servers behind SSO.
search_issues as a tool and issues as resources - the model pulls live P1 tickets.post_message; the host requires explicit approval before posting.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.
MCP went from a single-vendor spec to a broadly adopted standard remarkably fast. The trajectory points at richer, safer, more autonomous agents.
Public server registries for discovery and one-click install - an "app store" for agent capabilities, with signing and provenance.
Servers that are themselves agents, plus emerging agent-to-agent protocols, enabling networks of specialized agents that delegate to each other.
Fine-grained scopes, standardized OAuth 2.1, tool-poisoning defenses, and auditability as MCP moves deeper into enterprises.
Servers can ask the user for input mid-task (elicitation) and request model completions from the host (sampling) - richer two-way interaction.
OS-level and IDE-level MCP hosts, so any app can become an agent surface without bespoke plumbing.
Better support for progress streaming, cancellation, and durable long-running tasks - essential for real autonomous agents.