Implementing Model Context Protocol for AI
MCP Architectural Core
The Three Core Roles
The Model Context Protocol (MCP) organizes interactions between AI models and external systems using a classic client-server architecture. This structure avoids the chaos of creating custom, one-off integrations for every new tool or database. Instead, it defines clear roles for each component, making the system modular, scalable, and secure.
The Single Agent + Model Context Protocol (MCP) Servers + Tools architecture is built on a client-server model that standardizes how AI models interact with external data sources and tools.
There are three main players in this setup:
- The Host: This is the primary, user-facing application. Think of an integrated development environment (IDE) like VS Code, a desktop application like Claude Desktop, or any other program where you interact with an AI. The is the environment where the AI lives and works.
- The Client: Residing within the Host, the Client is the conductor. Its job is to manage connections to various servers. It discovers what capabilities each server offers and then makes requests on behalf of the AI model. It acts as a bridge between the AI's intent and the tool's function.
- The Server: A server is a program that exposes a specific capability. It could be a tool that can read and write files, a resource providing access to a database, or a set of pre-defined prompts to guide the AI. An AI application can connect to many different servers at once to assemble a wide range of skills.
How They Communicate
This clean separation of roles wouldn't work without a common language. MCP standardizes communication using over a reliable transport layer like a TCP socket or a WebSocket. This choice keeps the protocol lightweight and easy to implement in any programming language, as JSON is universally understood.
The connection lifecycle follows a logical sequence. When a Host starts, its Client connects to one or more Servers. The first step is an initialization handshake. During this process, the Server tells the Client about all the capabilities it offers. The Client then registers these capabilities, making them available to the AI model. From that point on, the AI can ask the Client to invoke a tool, and the Client sends the corresponding JSON-RPC request to the correct Server. The Server executes the request and sends the result back.
The Building Blocks of Capability
MCP servers don't just offer a random collection of functions. They expose their capabilities through three specific, well-defined primitives. This structure helps the AI understand what it can do and how to do it. These primitives are the fundamental vocabulary of the MCP world.
MCP defines three core primitives that servers can expose: Tools: Executable functions that AI applications can invoke to perform actions (e.g., file operations, API calls, database queries) Resources: Data sources that provide contextual information to AI applications (e.g., file contents, database records, API responses) Prompts: Reusable templates that help structure interactions with language models (e.g., system prompts, few-shot examples)
The three primitives are:
- : These are actions. A tool is an executable function that the AI can invoke to do something in the outside world, like
readFile,sendEmail, orqueryDatabase. Each tool is described with its name, a description of what it does, and the inputs it expects. This allows the AI to reason about when and how to use a specific tool to accomplish a goal. - Resources: These are sources of information. A resource provides the AI with context, like the contents of the currently open file, the structure of a project directory, or the schema of a database. Resources are often read-only and give the AI the background knowledge it needs to make smart decisions.
- Prompts: These are reusable templates or instructions. A prompt might contain a system message that sets the AI's persona ("You are a helpful coding assistant") or provide examples of how to perform a specific task (few-shot examples). They help steer the AI's behaviour in a consistent way.
| Primitive | Purpose | Example |
|---|---|---|
| Tool | An executable action | git_commit(message: string) |
| Resource | A source of context | file_system/active_document |
| Prompt | A reusable instruction | A system prompt for code generation |
By standardizing around these roles and primitives, MCP creates an open ecosystem. Any developer can build a Host, Client, or Server that works with any other component, moving us away from siloed AI systems and toward a future of interoperable, collaborative intelligence.
What are the three main components that make up the Model Context Protocol (MCP) architecture?
Which component in the MCP is responsible for discovering a server's capabilities and making requests on behalf of the AI model?