Library

Volume 2 · MCP (Model Context Protocol) & Skills

Notebook
Sign in

Section 42

MCP Architecture

557 words · about 3 min

42.1 Three-Layer Architecture

flowchart TD
    subgraph HostLayer["MCP Host (AI Application)"]
        HostApp["AI Host Environment\n(IDE, Desktop Chat, Custom Enterprise App)\n• Security & Sandbox Boundaries\n• User Consent Enforcement"]
        Client["MCP Client\n(Protocol Handler & Connection Manager)"]
        HostApp --> Client
    end

    subgraph Transport["Transport Layer (JSON-RPC 2.0)"]
        Pipe["stdio (Local Subprocess) OR HTTP + SSE (Remote Service)"]
    end

    subgraph ServerLayer["MCP Server (Capability Provider)"]
        direction TB
        ServerCore["MCP Server Core\n(Capability Negotiation & Routing)"]
        Res["Resources (Read)\nURI-addressed contextual data"]
        Tools["Tools (Execute)\nCallable functions with side-effects"]
        Prompts["Prompts (Templates)\nParameterized interaction templates"]
        ServerCore --> Res
        ServerCore --> Tools
        ServerCore --> Prompts
    end

    Client <-->|Bidirectional JSON-RPC 2.0| Pipe
    Pipe <-->|Bidirectional JSON-RPC 2.0| ServerCore

MCP Host — the AI application embedding the MCP client (a chat client, an IDE integration, a custom enterprise app). Manages security, user consent, and client lifecycle.

MCP Client — the protocol handler within the host; maintains a 1:1 connection with an MCP server, handles capability negotiation, and manages the message transport (stdio or HTTP+SSE).

MCP Server — the service exposing capabilities (Resources, Tools, Prompts); can be a local process or a remote service, stateless or stateful depending on use case.

42.2 The Three Primitives, With Code

1. Resources (read data) — URI-addressed, read-only data the AI can access:

{
  "uri": "file:///project/src/main.py",
  "name": "Main application file",
  "mimeType": "text/x-python",
  "description": "The main entry point for the application"
}

2. Tools (execute actions) — functions the AI can call, defined with JSON Schema parameters, typically requiring user approval before execution:

{
  "name": "query_database",
  "description": "Execute a read-only SQL query against the analytics database",
  "inputSchema": {
    "type": "object",
    "properties": {
      "query": {"type": "string", "description": "SQL SELECT query"},
      "database": {"type": "string", "enum": ["analytics", "reporting"]}
    },
    "required": ["query"]
  }
}

3. Prompts (templates) — pre-defined, parameterizable prompt templates a server exposes for standardizing common interactions:

{
  "name": "code_review",
  "description": "Review code for best practices and bugs",
  "arguments": [
    {"name": "language", "description": "Programming language", "required": true},
    {"name": "code", "description": "Code to review", "required": true}
  ]
}

Section 42 — Interview Q&A

Q1: What’s the practical difference between an MCP Resource and an MCP Tool, and why does that distinction matter for security? Resources are read-only, URI-addressed data — the AI can read them but they never mutate anything. Tools execute actions and can have side effects, including writes. This distinction matters because it lets a host apply differentiated consent policies: resources might be auto-approved for read access within a session, while every tool invocation — especially one with write semantics — can require explicit per-call user approval. Conflating the two would force the host to either over-restrict harmless reads or under-restrict dangerous writes.

Q2: Why does MCP use JSON-RPC 2.0 over stdio/HTTP+SSE rather than a simpler REST convention? JSON-RPC gives bidirectional, session-oriented messaging with built-in request/response correlation and support for notifications — needed because MCP connections are persistent and stateful (capability negotiation happens once per connection, not per call) and because servers may need to push notifications to the client (e.g., a resource changed) outside of a request/response cycle. Plain REST is fundamentally request/response and stateless, which doesn’t fit MCP’s session lifecycle and server-initiated messaging needs.