Model Context Protocol (MCP): Architecture Evolution and Engineering Practices

    This article examines the Model Context Protocol (MCP), a standardized contract designed to decouple context providers from context consumers so host applications can connect to multiple MCP servers through a unified interface. It breaks down the protocol's client-server architecture across three roles—hosts, clients, and servers—and explains its three capability types: tools, resources, and prompts. The article then traces the architectural shift from stateful sessions to a stateless design based on versioned extension frameworks and explicit handles, with a code skeleton illustrating stateless tool handling. It closes with practical guidance on implementation patterns, security and least-privilege access, observability, context cost control, and ecosystem adoption trends.

    1. The Core Problem the Protocol Solves

    As large model applications move from single-turn question answering to continuous task execution, engineering teams most often find that the bottleneck is not model capability but fragmented context supply: business data is scattered across databases, object storage, message queues, and internal services. Every time a new model or a new AI coding tool is onboarded, teams must rewrite the same glue code for data retrieval, permission checks, result trimming, and format conversion. This “one-to-one integration” complexity grows linearly or even quadratically with the number of models, eventually turning into a hard-to-maintain swamp of adapter layers.

    The Model Context Protocol (MCP) was proposed precisely to converge this glue code into a standardized contract. Its core idea is to decouple “the party providing context” from “the party consuming context,” letting the protocol define the messages and capability declarations through which both sides interoperate. This enables a host application to connect to multiple context servers via a unified interface and obtain semantically structured data that the model can understand. It is worth stressing that the protocol does not dictate how a model reasons, nor does it prescribe how data is stored; it only makes context flow in a discoverable, callable, and constrainable way.

    2. Architecture Breakdown: Hosts, Clients, and Servers

    The protocol uses a client-server architecture, but in real deployments it typically presents three roles:

    • Host application: the user-facing entry point, responsible for session orchestration, permission boundaries, and final presentation—for example, a desktop assistant, an AI coding panel inside an integrated development environment (IDE), or an internal operations copilot at an enterprise.
    • Client: instantiated inside the host, maintaining a one-to-one connection with the server, and handling capability negotiation, request routing, and lifecycle management. A single host can concurrently hold multiple client connections.
    • Server: encapsulates a specific kind of capability as a standard interface, such as code repository search, log querying, document retrieval, or ticketing-system read/write.

    The direct benefit of this layering is separation of concerns: a server only needs to focus on “how to turn domain data into a model-friendly structure,” while the host only needs to focus on “when to call and how to assemble the results.” The two negotiate through capability declarations, avoiding any hardcoded assumptions about the other side’s implementation details.

    3. Three Capability Types: Tools, Resources, and Prompts

    The protocol supports three capability types. They correspond to three different intents behind a model’s use of context, and understanding the differences is the prerequisite for modeling them correctly.

    Tools are actions actively triggered by the model. They have side effects and uncertain outcomes, making them suitable for querying computations, writing records, triggering workflows, and similar scenarios. Tools require strict input-schema constraints and clear error semantics, because what the model generates is structured parameters rather than trusted code.

    Resources are data read passively by the model. They usually carry a stable identifier and a readable MIME type, and are suitable for file contents, configurations, table schemas, metric snapshots, and so on. Resources emphasize addressability and cacheability, and are the main lever for controlling context cost.

    Prompts are parameterized templates preset by the server that codify domain best practices. Users or hosts reuse them at very low cost, reducing the burden of hand-writing long instructions every time.

    A schematic capability declaration can be abstracted into the following structure (it only expresses protocol semantics, not any specific implementation):

    1. {
    2. "capabilities": {
    3. "tools": [{ "name": "query_metrics", "input_schema": { "type": "object" } }],
    4. "resources": [{ "uri": "scheme://metrics/latest", "mimeType": "application/json" }],
    5. "prompts": [{ "name": "incident_triage", "arguments": ["service", "window"] }]
    6. }
    7. }

    4. Architectural Evolution: From Session State to Statelessness

    Early implementations commonly relied on sessions: after a connection was established, the server kept the context, and subsequent requests continued that state via a session identifier. This was convenient for single-machine demos, but it exposed three problems in production: first, horizontal scaling was difficult, because instance affinity complicated load balancing and canary releases; second, lingering state introduced risks of stale reads and unauthorized access; third, failure-recovery semantics were ambiguous, making it hard to judge whether state could be trusted after a reconnection.

    The new generation of the specification therefore moves toward a stateless architecture, removing the built-in session mechanism and handing state explicitly back to the caller to manage. It introduces two key designs: a versioned extension framework, so that adding capabilities does not break existing clients; and an explicit handle mechanism, which makes resource references, pagination cursors, and task identifiers returned by the server first-class citizens that the client explicitly carries in subsequent requests. The engineering implication of this shift is that replayability, auditability, and parallelism become default capabilities, at the cost of the caller having to take on responsibility for state storage and consistency.

    5. Implementation Patterns and Code Skeleton

    A minimal usable server typically involves four steps: declare capabilities, validate inputs, execute domain logic, and return results in a unified structure. The pseudocode below shows a processing skeleton in a stateless style:

    1. def handle_tool_call(name, args, handle=None):
    2. if name == "query_logs":
    3. schema_check(args, required=["service", "since"])
    4. page = log_backend.search(service=args["service"], since=args["since"],
    5. cursor=handle) # explicit handle replaces implicit session
    6. return {
    7. "content": [{"type": "text", "text": summarize(page.hits)}],
    8. "next_handle": page.cursor, # explicitly returned by the client
    9. "is_error": False
    10. }
    11. return error("unknown_tool")

    Recommended accompanying practices include: setting timeouts and concurrency limits for tools; adding cache keys and invalidation strategies for resource reads; version-tagging prompt templates; and keeping every response body in a stable form of “content blocks + error flag + optional handle” to avoid a combinatorial explosion of branches on the host side.

    6. Security, Observability, and Cost Control

    The context supply layer is a convergence point for permissions and must default to least privilege: servers expose only the resource scope necessary to complete the current task; tool write operations introduce a secondary confirmation and idempotency keys; and cross-tenant data is isolated through scoping rather than relying on the caller’s self-discipline. At the same time, prompt injection should be treated as a first-class risk—apply source labeling and instruction isolation to external content so that text within documents is not executed as system instructions.

    For observability, it is recommended to record the trace identifier, capability name, latency, result size, and error category for every call, and to integrate these with logging services and monitoring alerts, forming a complete traceable path from model decision to data access. For cost control, prefer using resource handles and summaries instead of full injection, adopt segmentation and on-demand retrieval for long text, and treat the context budget as an explicit design parameter rather than an after-the-fact optimization.

    Since the protocol’s release, industry adoption has clearly accelerated: it was first validated for value by IDEs and desktop-class applications, then mainstream model capability platforms and agent-development frameworks successively announced support, and the ecosystem has entered a scaling phase. Three evolution directions can be anticipated: more automated capability discovery, finer-grained permission models, and extension mechanisms that emphasize backward compatibility. For developers, abstracting the context layer into an independent module early, and connecting to multiple models and multiple data sources through a unified contract, is the key to staying portable in this trend.