What it is
The Model Context Protocol (MCP) is an open protocol that lets AI applications use tools and context provided by separate programs. A host (an IDE, a chat application, an agent runtime) creates one client per server it connects to. Servers expose tools (functions the model may call), resources (data addressed by URI) and prompts (reusable templates). Messages are JSON-RPC 2.0 over one of two standard transports: stdio for local servers and Streamable HTTP for remote ones.
The specification is versioned by date (for example 2025-06-18), and client and server agree on a version when they connect.
Why it exists
Before MCP, every AI application integrated every tool in its own way: a different plugin format per host, a different tool schema per model vendor. With M hosts and N tools that is M × N integrations. MCP turns it into M + N: a server written once works in any compliant host, and a host gains every existing server. It also gives tools a shared vocabulary for things beyond a single function call: discovery, change notifications, progress, cancellation, and requests from server back to host.
How it works
Session and capabilities. The client sends initialize with its preferred protocol version, its capabilities (such as roots, sampling, elicitation) and client info. The server replies with the version it will use, its capabilities (tools, resources, prompts, logging, and flags like listChanged) and server info. If the client cannot use that version it disconnects. The client then sends notifications/initialized. Afterwards each side may only use features the other declared.
Messages. Requests carry an id and expect a response; notifications carry no id and get no response. Either side can send both: the server sends notifications/tools/list_changed, progress notifications or requests such as sampling/createMessage (ask the host's model to generate) and elicitation/create (ask the user for input).
Primitives.
- Tools:
tools/listreturns names, descriptions and JSON Schema input (and optionally output) schemas;tools/callruns one and returns content items plus anisErrorflag. Tool failures are results the model can read; protocol errors are JSON-RPC errors. - Resources: listed and read by URI (
resources/list,resources/read), optionally subscribed to for updates. The application decides what to attach to the model's context. - Prompts: templates with arguments (
prompts/list,prompts/get), typically offered to users as slash commands.
stdio transport. The host launches the server as a child process. Each JSON-RPC message is one line on stdin or stdout; stderr is free for logs. No network exposure; credentials typically come from environment variables. The server runs with the user's privileges.
Streamable HTTP transport. The server exposes one endpoint. The client POSTs every JSON-RPC message to it, accepting application/json and text/event-stream. For a request, the server answers either with a single JSON response or with an SSE stream that can carry notifications and server requests before the final response. The client may also open a GET SSE stream for unprompted server messages. A server may assign an Mcp-Session-Id at initialization, which the client sends on every later request (and can end with DELETE); clients also send MCP-Protocol-Version. SSE event ids allow resuming a broken stream. This transport replaced the earlier two-endpoint HTTP+SSE transport in the 2025-03-26 revision.
Authorization (remote servers). Authorization is optional in the protocol and does not apply to stdio. For HTTP servers that need it, the MCP server is an OAuth 2.1 resource server. An unauthenticated request gets 401 with a WWW-Authenticate header pointing to the server's protected resource metadata (RFC 9728), which names its authorization server(s). The client reads the authorization server's metadata, registers or identifies itself (pre-registration, a client ID metadata document or dynamic client registration, depending on the server and spec revision), runs the authorization code flow with PKCE in the user's browser, and includes a resource parameter (RFC 8707) so the token's audience is that MCP server. The server validates tokens and rejects any issued for another audience. It must not pass the client's token through to upstream APIs; it obtains its own credentials for those.
When to use it
- You want one integration usable from several AI hosts (IDEs, desktop assistants, your own agents).
- You publish tools or data for others' AI applications: an MCP server is becoming the expected interface, alongside a REST API.
- Your agent should discover tools at run time, or tools change while it runs.
- You need server-to-host features: progress, sampling with the host's model, asking the user for input.
When not to
- A single application with a few internal functions: plain function calling with your model SDK is simpler, with no extra process or protocol.
- Service-to-service integration with no model involved: use your normal API.
- When you cannot vet the server: installing an MCP server is installing code (stdio) or granting a third party a view into your model's context (remote).
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| MCP server instead of direct function calling | Reuse across hosts, discovery, standard auth | An extra process or network hop, protocol surface to maintain |
| stdio instead of Streamable HTTP | No network exposure, simple deployment per user | Runs on every user's machine with their privileges; updates are per install |
| Remote server | Central updates, shared infrastructure, real auth | OAuth setup, multi-tenant security, latency |
| Many fine-grained tools | Precise actions | More tokens in every prompt, worse tool selection by the model |
| Stateful sessions (session id) | Server-side context per client | Sticky routing or a shared session store when scaling out |
Alternatives
- Native function calling in a model API: define tools in your code, no protocol between processes.
- OpenAPI-described REST APIs turned into tools by an agent framework.
- Framework-specific plugin systems: work within one framework or host only.
Failure modes
- Prompt injection and tool poisoning: text in tool results, resources or even tool descriptions steers the model. Hosts should show users what runs and confirm state-changing calls.
- Over-broad servers: a server with wide filesystem or admin API access turns any successful injection into real damage. Scope tokens, paths and permissions narrowly.
- Token passthrough and confused deputy: forwarding the client's token upstream breaks audience checks and auditing. Forbidden by the specification.
- Local HTTP servers exposed: an HTTP server on localhost that does not validate the
Originheader can be reached from web pages (DNS rebinding). Bind to localhost and checkOrigin. - Version mismatch: client and server with no common protocol version cannot talk; pin and test supported versions.
- Huge tool results: dumping whole files or tables into context costs tokens and accuracy. Return compact content, or resource links the host can fetch selectively.
In production
Treat a remote MCP server like any public API: TLS, OAuth with short-lived audience-bound tokens, per-client rate limits, input validation, audit logs and timeouts on upstream calls. If you use session ids behind a load balancer, route by session or keep session state in a shared store. Version tool names and schemas carefully, since prompts and evaluations depend on them, and emit list_changed when they change. In hosts, keep an allowlist of servers, show which server each tool belongs to, and require confirmation for writes. For .NET, the official C# SDK is published on NuGet as ModelContextProtocol (with ModelContextProtocol.AspNetCore for Streamable HTTP servers); this site's course Build MCP Servers in C# (under /courses) walks through building and securing one.
Common misconceptions
- "The model connects to MCP servers." The host does, through one client per server; the model only proposes tool calls.
- "MCP is a tool-calling format." Tools are one of three server primitives, and servers can also send requests and notifications to the client.
- "Streamable HTTP means WebSockets." It is HTTP POST, optionally answered with Server-Sent Events.
- "MCP handles security." It standardises authorization for remote servers; deciding what a model may do, and confirming it with users, is still the host's job.
- "An MCP server replaces my API." It is usually a thin adapter in front of your existing API, shaped for models.
Interview angle
Be ready to draw host, clients and servers and walk through a session: initialize and capability negotiation, tools/list, tools/call, and a server-initiated notification. Then discuss transports (when stdio, when Streamable HTTP, what sessions mean for horizontal scaling), how a remote server is protected (401 with resource metadata, PKCE, audience-bound tokens, no token passthrough) and how a host limits the damage of a malicious or compromised server.
Model assumptions
This lesson is a scripted illustration: no part of it is simulated. Packets show the order of protocol messages between roles; their durations are not to scale (local stdio hops are drawn at 30 ms but take well under a millisecond, remote hops at 60 ms, model replies at 400 ms, user clicks at 300–600 ms). Message and header names follow the MCP specification revisions from 2025-06-18 on; details such as client registration options vary between revisions, so check the revision your SDK targets.