Model Context Protocol (MCP) - An Architectural Pattern for Building AI Agents

The Model Context Protocol (MCP) is an architectural pattern for designing intelligent systems powered by large language models (LLMs). By splitting an agent into four distinct layers—Model, Context, Tools, and Control Plane—it promotes modularity, scalability, and maintainability.

Note: "Model Context Protocol" is also the name of a separate, standardized protocol (by Anthropic) for connecting AI apps to tools and data. This article focuses on the architectural pattern; the protocol is covered in a dedicated article.

Model Context Protocol (MCP) Overview
Model Context Protocol (MCP) Overview

🧩 Core Components of MCP

In a full system, a user-facing Client typically sends requests to a component (often called an MCP Server or orchestrator) that implements these four layers.

Architecture Deep-Dive

This four-layer architecture (sometimes called MCP-style design) interacts in a clear pipeline:

Sample Workflow

Example: a user asks for stock prices.

🚀 Benefits of Using MCP

TypeScript Code Example

The following is a minimal implementation of the four-layer architecture (Model, Context, Tools, Control Plane):


// mcp.ts

/** 1) Define core interfaces **/
export interface ContextManager {
  getHistory(userId: string): Promise<string[]>;
  appendTurn(userId: string, turn: string): Promise<void>;
}

export interface Tool {
  name: string;
  call(args: any): Promise<any>;
}

export interface ControlPlane {
  log(entry: any): void;
  enforce(entry: any): void;
}

// 2) Agent class wiring components
export class MCPAgent {
  constructor(
    private model: (prompt: string) => Promise<string>,
    private context: ContextManager,
    private tools: Record<string, Tool>,
    private control: ControlPlane
  ) {}

  async handle(userId: string, userInput: string) {
    // 2a) Enforce policy
    this.control.enforce({ userId, userInput });

    // 2b) Build prompt
    const history = await this.context.getHistory(userId);
    const prompt = [...history, userInput].join("\n");

    // 2c) Model inference
    const raw = await this.model(prompt);

    // 2d) If tool call detected, route to tool
    if (raw.startsWith("CALL_TOOL:")) {
      const [_, toolName, argJson] = raw.split("|");
      const result = await this.tools[toolName].call(JSON.parse(argJson));
      return this.handle(userId, result);
    }

    // 2e) Log & update memory
    this.control.log({ userId, prompt, response: raw });
    await this.context.appendTurn(userId, userInput);
    await this.context.appendTurn(userId, raw);

    return raw;
  }
}

// 3) Example instantiation omitted for brevity

Where MCP is Used

This architectural pattern (separating model, context, tools, and control) is common in modern agent design. Frameworks such as LangChain, CrewAI, and LangGraph use similar modular ideas—tools, context, and control planes—for building agents. It’s ideal for production-level agents, copilots, and data-driven chatbots. The official Model Context Protocol (Anthropic) is a separate standard for client–server tool and resource integration; it is covered in a dedicated article.