No history yet

MCP Server Architecture

The Protocol Backbone

The Model Context Protocol (MCP) standardizes communication between an AI host, like Claude Code, and external capabilities. At its core, MCP leverages JSON-RPC 2.0 as its transport-agnostic remote procedure call mechanism. This choice ensures a lightweight, stateless, and human-readable protocol structure. All interactions, from initialization to tool execution, are framed as JSON-RPC requests and responses.

// Client Request to Server
{
  "jsonrpc": "2.0",
  "method": "mcp/listTools",
  "id": 1
}

// Server Response to Client
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "file/readFile",
        "description": "Reads the content of a file at a given path.",
        "parameters": {
          "type": "object",
          "properties": {
            "path": {
              "type": "string",
              "description": "The absolute path to the file."
            }
          },
          "required": ["path"]
        }
      }
    ]
  }
}

This strict request/response format simplifies integration, as both client and server adhere to a well-defined contract for method calls and data structures. The protocol itself doesn't care how these messages are transported; it only defines their structure.

Transport Mechanisms

While MCP is transport-agnostic, two primary mechanisms are used in practice: standard I/O (stdio) and HTTP with Server-Sent Events (SSE).

The choice of transport depends entirely on the server's deployment context. Local development tools typically favor stdio for its simplicity, while cloud-hosted or web-accessible tools require HTTP.

For a local MCP server, communication via stdio is the most direct method. The host application launches the server as a subprocess and communicates with it by writing JSON-RPC messages to the server's standard input and reading responses from its standard output. This avoids network overhead and simplifies setup for local development environments.

For remote servers, HTTP is the transport of choice. While simple request/response cycles can use standard POST requests, real-time interactions benefit from Server-Sent Events (SSE). SSE allows the server to push data to the client asynchronously after the initial connection is established. This is critical for streaming tool outputs, providing progress updates, or sending notifications without requiring the client to poll for changes. This one-way push mechanism is lighter than WebSockets, which makes it a good fit for MCP's server-to-client data flows.

TransportPrimary Use CaseOverheadComplexity
StdioLocal development serversVery LowLow
HTTP/SSERemote/networked serversMediumHigher (requires HTTP server, endpoint routing)

Capability Negotiation and Registration

An MCP connection's lifecycle begins with a handshake. The host initiates this by sending an mcp/initialize request. This request includes the client's capabilities, such as the protocol versions it supports. The server replies with its own capabilities, including metadata about the server and a manifest of available tools, prompts, and resources.

This initial exchange can expose a set of static tools defined at server startup. However, a key feature of MCP for development workflows is dynamic tool registration. A sophisticated MCP server can monitor the local filesystem for changes. When a developer adds or modifies a function in a designated tool file, the server can detect this change, validate the new tool, and send an mcp/registerTools notification to the host. This allows Claude Code to use the new tool instantly without restarting the server or the connection.

This is powerful because it makes the development loop incredibly fast. You can define a new function, save the file, and immediately ask the AI to use it. The server handles the hot-reloading and registration behind the scenes. Likewise, if a tool is removed, the server can send an mcp/unregisterTools notification.

Alongside tools, servers define resources and prompts. Resources are templates for providing contextual data, such as the contents of a file or the structure of a project directory. Prompts are reusable instructions that can guide the AI's behavior. These are also advertised during the handshake, allowing the host to understand the full range of capabilities the server offers.

Quiz Questions 1/6

What is the underlying remote procedure call (RPC) mechanism that the Model Context Protocol (MCP) is built upon?

Quiz Questions 2/6

For a local MCP server running as a subprocess on the same machine as the AI host, what is the most direct and efficient communication method?