Curious Minds

Clear answers to science and history questions

Model Context Protocol: How It Works

· 8 min read · Science

The Model Context Protocol (MCP) is an open standard that lets AI applications connect to external data sources and tools through a uniform client-server interface, so a model can retrieve context or perform actions without custom integrations for each source. In practice, an MCP host (such as a chat app or coding assistant) runs one or more MCP clients, each maintaining a session with an MCP server that exposes capabilities like resources, tools, and prompts.

Background: Why a Protocol for Model Context?

Large language models are trained on fixed data and have no built-in way to reach live files, databases, APIs, or business systems. Developers have long bridged that gap with ad hoc plugins, function-calling schemas, and bespoke connectors. Each integration tends to be vendor-specific and must be rebuilt when the model, host application, or data source changes.

MCP emerged as a way to standardize that bridge. Instead of every AI host inventing its own plugin format, MCP defines a common language for discovery and invocation. The protocol is inspired by the Language Server Protocol (LSP), which solved a similar fragmentation problem for code editors and language tooling. Just as LSP lets any editor talk to any language server, MCP aims to let any compatible host talk to any compatible server.

The protocol is open and implementation-agnostic. It does not prescribe a particular model, vendor, or transport beyond defining how messages are structured and exchanged. That separation is the core design idea: the host handles the user experience and model orchestration, while servers encapsulate access to specific systems.

Core Architecture: Hosts, Clients, and Servers

MCP uses a client-server architecture with three roles:

  • Host — the application the user interacts with, such as an IDE, chat interface, or agent runtime. The host decides which servers to connect to and how model outputs map to server calls.
  • Client — a connector inside the host that maintains a one-to-one session with a single server. A host may run multiple clients concurrently.
  • Server — a program that exposes context and capabilities. Servers can be local processes on the same machine or remote services reachable over a network.

This separation means a server author does not need to know which host will use it, and a host author does not need to know how each server implements its data access. The contract is the protocol itself.

How the Protocol Works: Sessions, Capabilities, and Messages

An MCP session begins with a handshake. The client and server exchange protocol version information and declare their capabilities. Capabilities are the features each side supports, such as whether the server offers tools, resources, or prompts, and whether the client can handle sampling or roots. This negotiation prevents either side from assuming features the other does not implement.

After the handshake, communication follows a JSON-RPC 2.0 message pattern. JSON-RPC is a lightweight remote procedure call standard that uses JSON for requests, responses, and notifications. MCP builds on it with defined method names and payload shapes for its specific operations.

Messages fall into three broad categories:

  • Requests — ask the other side to perform an action and expect a response.
  • Responses — return the result of a request or an error.
  • Notifications — one-way messages that do not expect a reply, such as a server announcing that its list of available tools has changed.

The transport layer is separate from the message format. MCP defines two standard transports: stdio, where the client launches the server as a subprocess and communicates over standard input and output, and HTTP with Server-Sent Events (SSE) for remote connections. The stdio transport is common for local tools, while HTTP-based transport suits shared or hosted servers. Because the transport is abstracted, the same server logic can often be exposed over either transport with modest changes.

The Three Server Primitives: Resources, Tools, and Prompts

MCP servers expose three primary kinds of capability, each with a different purpose and control model.

Resources

Resources are read-only pieces of context identified by URIs. They are analogous to files or database records that the host can list and read. Examples include a document, a configuration file, a log excerpt, or a row from a table. Resources are typically application-controlled: the host decides when to include them in the model's context, often based on user selection or relevance. A server can also notify clients when a resource changes, allowing the host to refresh its view.

Tools

Tools are functions the model can invoke to perform actions or computations. Each tool has a name, a description, and an input schema, usually expressed as JSON Schema, so the host can validate arguments before calling. Tools are model-controlled in the sense that the model proposes a call, but the host remains responsible for approving and executing it. A tool might query a database, send a message, run a calculation, or create a file. Because tools can have side effects, hosts commonly implement confirmation steps or permission policies.

Prompts

Prompts are reusable templates that guide interactions. They can accept arguments and return structured messages intended for the model. Prompts are often user-controlled: a user might pick a prompt from a menu, such as a code-review template or a summarization instruction, and the host fills in the arguments. This gives servers a way to ship curated workflows without hard-coding them into the host.

In addition to these three primitives, MCP defines client-side features that servers can use. Sampling allows a server to request that the host run a model completion, which is useful when a server needs language-model reasoning but should not embed its own model credentials. Roots let a server learn which filesystem or workspace boundaries the client considers relevant. These features are negotiated during the handshake and are optional.

A Typical Interaction, Step by Step

  1. The host starts or connects to an MCP server and creates a client session.
  2. Client and server exchange initialization messages, agreeing on protocol version and capabilities.
  3. The client requests the server's list of resources, tools, and prompts.
  4. The host presents available capabilities to the user or uses them to inform the model's context.
  5. When the model needs external context, the host reads a relevant resource and includes it in the prompt.
  6. When the model proposes a tool call, the host validates the arguments against the tool's schema and, depending on policy, asks the user to confirm.
  7. The host sends the tool call request to the server, which executes it and returns a result.
  8. The host feeds the result back to the model, which continues the conversation or task.

This loop can repeat many times within a single user request. The protocol does not dictate how many turns are allowed or how the host chooses which resources to load; those are host-level design decisions.

Security and Trust Considerations

MCP expands what a model can reach, so trust boundaries matter. A server is a piece of software with its own permissions, and connecting to it grants the host access to whatever the server exposes. Practical considerations include:

  • Least privilege — run servers with only the filesystem or network access they need.
  • User confirmation — require explicit approval for tool calls that modify data or communicate externally.
  • Input validation — treat model-proposed arguments as untrusted and validate them against schemas.
  • Server provenance — install servers from sources you trust, since a malicious server could return misleading context or perform harmful actions within its permissions.
  • Prompt injection — content returned by a server can contain instructions that influence the model; hosts should treat retrieved content as data, not as trusted commands.

The protocol itself does not enforce a security model. It provides the message structure and capability negotiation; the host and server implementers are responsible for authentication, authorization, and sandboxing. Remote servers typically add their own authentication layer on top of the transport.

How MCP Compares with Other Integration Approaches

Before MCP, the most common approach was function calling or plugin APIs defined by each model provider. Those work well within a single ecosystem but require separate implementations for each host and model. MCP standardizes discovery and invocation across hosts, which reduces duplication when the same data source needs to serve multiple AI applications.

MCP is not a replacement for APIs. A server usually wraps an existing API, database, or file system and translates MCP requests into native calls. Nor is it a model or an agent framework; it is a connectivity layer. It also differs from simple retrieval-augmented generation (RAG) pipelines, which typically pre-index documents. MCP is more general: it can expose live resources, executable tools, and reusable prompts, and it supports bidirectional features like sampling.

Frequently Asked Questions

Is MCP tied to a specific AI model or vendor?

No. MCP is an open protocol designed to be model- and vendor-agnostic. Any host that implements the client side can connect to any server that implements the server side, provided their capabilities and transports are compatible.

Does MCP replace function calling?

Not exactly. Function calling is a model-level mechanism for proposing structured calls. MCP is a host-to-server protocol for exposing and invoking capabilities. A host can use a model's function-calling output to decide when to make an MCP tool call, so the two can complement each other.

What is the difference between a resource and a tool?

Resources are read-only context identified by URIs, typically loaded by the host. Tools are executable functions with input schemas, typically invoked when the model proposes a call. Resources provide information; tools perform actions or computations.

Can MCP servers run remotely?

Yes. MCP defines an HTTP with SSE transport for remote connections, in addition to the stdio transport used for local subprocesses. Remote servers usually add authentication and access control on top of the transport.

Do I need to write a server to use MCP?

Only if no existing server exposes the system you need. Many common integrations can be served by existing MCP servers. Writing a server is a matter of implementing the protocol's message handlers and mapping them to your data source or API.

Is MCP secure by default?

No protocol can guarantee security by itself. MCP provides structure for capability negotiation and message exchange, but safety depends on how hosts and servers implement permissions, validation, sandboxing, and user confirmation.

In this article
  1. Background: Why a Protocol for Model Context?
  2. Core Architecture: Hosts, Clients, and Servers
  3. How the Protocol Works: Sessions, Capabilities, and Messages
  4. The Three Server Primitives: Resources, Tools, and Prompts
  5. A Typical Interaction, Step by Step
  6. Security and Trust Considerations
  7. How MCP Compares with Other Integration Approaches
  8. Frequently Asked Questions