|
| 1 | +--- |
| 2 | +title: Architecture |
| 3 | +--- |
| 4 | + |
| 5 | +The Model Context Protocol (MCP) follows a client-host-server architecture where each |
| 6 | +host can run multiple client instances. This architecture enables users to integrate AI |
| 7 | +capabilities across applications while maintaining clear security boundaries and |
| 8 | +isolating concerns. Built on JSON-RPC, MCP provides a stateful session protocol focused |
| 9 | +on context exchange and sampling coordination between clients and servers. |
| 10 | + |
| 11 | +## Core Components |
| 12 | + |
| 13 | +```mermaid |
| 14 | +graph LR |
| 15 | + subgraph "Application Host Process" |
| 16 | + H[Host] |
| 17 | + C1[Client 1] |
| 18 | + C2[Client 2] |
| 19 | + C3[Client 3] |
| 20 | + H --> C1 |
| 21 | + H --> C2 |
| 22 | + H --> C3 |
| 23 | + end |
| 24 | +
|
| 25 | + subgraph "Local machine" |
| 26 | + S1[Server 1<br>Files & Git] |
| 27 | + S2[Server 2<br>Database] |
| 28 | + R1[("Local<br>Resource A")] |
| 29 | + R2[("Local<br>Resource B")] |
| 30 | +
|
| 31 | + C1 --> S1 |
| 32 | + C2 --> S2 |
| 33 | + S1 <--> R1 |
| 34 | + S2 <--> R2 |
| 35 | + end |
| 36 | +
|
| 37 | + subgraph "Internet" |
| 38 | + S3[Server 3<br>External APIs] |
| 39 | + R3[("Remote<br>Resource C")] |
| 40 | +
|
| 41 | + C3 --> S3 |
| 42 | + S3 <--> R3 |
| 43 | + end |
| 44 | +``` |
| 45 | + |
| 46 | +### Host |
| 47 | + |
| 48 | +The host process acts as the container and coordinator: |
| 49 | + |
| 50 | +- Creates and manages multiple client instances |
| 51 | +- Controls client connection permissions and lifecycle |
| 52 | +- Enforces security policies and consent requirements |
| 53 | +- Handles user authorization decisions |
| 54 | +- Coordinates AI/LLM integration and sampling |
| 55 | +- Manages context aggregation across clients |
| 56 | + |
| 57 | +### Clients |
| 58 | + |
| 59 | +Each client is created by the host and maintains an isolated server connection: |
| 60 | + |
| 61 | +- Establishes one stateful session per server |
| 62 | +- Handles protocol negotiation and capability exchange |
| 63 | +- Routes protocol messages bidirectionally |
| 64 | +- Manages subscriptions and notifications |
| 65 | +- Maintains security boundaries between servers |
| 66 | + |
| 67 | +A host application creates and manages multiple clients, with each client having a 1:1 |
| 68 | +relationship with a particular server. |
| 69 | + |
| 70 | +### Servers |
| 71 | + |
| 72 | +Servers provide specialized context and capabilities: |
| 73 | + |
| 74 | +- Expose resources, tools and prompts via MCP primitives |
| 75 | +- Operate independently with focused responsibilities |
| 76 | +- Request sampling through client interfaces |
| 77 | +- Must respect security constraints |
| 78 | +- Can be local processes or remote services |
| 79 | + |
| 80 | +## Design Principles |
| 81 | + |
| 82 | +MCP is built on several key design principles that inform its architecture and |
| 83 | +implementation: |
| 84 | + |
| 85 | +1. **Servers should be extremely easy to build** |
| 86 | + |
| 87 | + - Host applications handle complex orchestration responsibilities |
| 88 | + - Servers focus on specific, well-defined capabilities |
| 89 | + - Simple interfaces minimize implementation overhead |
| 90 | + - Clear separation enables maintainable code |
| 91 | + |
| 92 | +2. **Servers should be highly composable** |
| 93 | + |
| 94 | + - Each server provides focused functionality in isolation |
| 95 | + - Multiple servers can be combined seamlessly |
| 96 | + - Shared protocol enables interoperability |
| 97 | + - Modular design supports extensibility |
| 98 | + |
| 99 | +3. **Servers should not be able to read the whole conversation, nor "see into" other |
| 100 | + servers** |
| 101 | + |
| 102 | + - Servers receive only necessary contextual information |
| 103 | + - Full conversation history stays with the host |
| 104 | + - Each server connection maintains isolation |
| 105 | + - Cross-server interactions are controlled by the host |
| 106 | + - Host process enforces security boundaries |
| 107 | + |
| 108 | +4. **Features can be added to servers and clients progressively** |
| 109 | + - Core protocol provides minimal required functionality |
| 110 | + - Additional capabilities can be negotiated as needed |
| 111 | + - Servers and clients evolve independently |
| 112 | + - Protocol designed for future extensibility |
| 113 | + - Backwards compatibility is maintained |
| 114 | + |
| 115 | +## Capability Negotiation |
| 116 | + |
| 117 | +The Model Context Protocol uses a capability-based negotiation system where clients and |
| 118 | +servers explicitly declare their supported features during initialization. Capabilities |
| 119 | +determine which protocol features and primitives are available during a session. |
| 120 | + |
| 121 | +- Servers declare capabilities like resource subscriptions, tool support, and prompt |
| 122 | + templates |
| 123 | +- Clients declare capabilities like sampling support and notification handling |
| 124 | +- Both parties must respect declared capabilities throughout the session |
| 125 | +- Additional capabilities can be negotiated through extensions to the protocol |
| 126 | + |
| 127 | +```mermaid |
| 128 | +sequenceDiagram |
| 129 | + participant Host |
| 130 | + participant Client |
| 131 | + participant Server |
| 132 | +
|
| 133 | + Host->>+Client: Initialize client |
| 134 | + Client->>+Server: Initialize session with capabilities |
| 135 | + Server-->>Client: Respond with supported capabilities |
| 136 | +
|
| 137 | + Note over Host,Server: Active Session with Negotiated Features |
| 138 | +
|
| 139 | + loop Client Requests |
| 140 | + Host->>Client: User- or model-initiated action |
| 141 | + Client->>Server: Request (tools/resources) |
| 142 | + Server-->>Client: Response |
| 143 | + Client-->>Host: Update UI or respond to model |
| 144 | + end |
| 145 | +
|
| 146 | + loop Server Requests |
| 147 | + Server->>Client: Request (sampling) |
| 148 | + Client->>Host: Forward to AI |
| 149 | + Host-->>Client: AI response |
| 150 | + Client-->>Server: Response |
| 151 | + end |
| 152 | +
|
| 153 | + loop Notifications |
| 154 | + Server--)Client: Resource updates |
| 155 | + Client--)Server: Status changes |
| 156 | + end |
| 157 | +
|
| 158 | + Host->>Client: Terminate |
| 159 | + Client->>-Server: End session |
| 160 | + deactivate Server |
| 161 | +``` |
| 162 | + |
| 163 | +Each capability unlocks specific protocol features for use during the session. For |
| 164 | +example: |
| 165 | + |
| 166 | +- Implemented [server features](/specification/draft/server) must be advertised in the |
| 167 | + server's capabilities |
| 168 | +- Emitting resource subscription notifications requires the server to declare |
| 169 | + subscription support |
| 170 | +- Tool invocation requires the server to declare tool capabilities |
| 171 | +- [Sampling](/specification/draft/client) requires the client to declare support in its |
| 172 | + capabilities |
| 173 | + |
| 174 | +This capability negotiation ensures clients and servers have a clear understanding of |
| 175 | +supported functionality while maintaining protocol extensibility. |
0 commit comments