Get to Know MCP
Anthropic originally created the Model Context Protocol (MCP) to add context to Claude Desktop. MCP’s problem statement was to solve copying pasting between your MCP Host (e.g. Claude Desktop) and a disparate data sources and tools. MCP was open sourced on November 2024.
Architecture
At its core, MCP follows a client-server architecture where a host application can connect to multiple servers:
Concepts
MCP follows a client-server architecture where:
- Hosts are LLM applications (like Claude Desktop or IDEs) that initiate connections
- Clients maintain 1:1 connections with servers, inside the host application
- Servers provide context, tools, and prompts to clients
Source: Core architecture - Model Context Protocol
MCP Hosts seems to be a loaded term. Here’s some additional info from Gemini about what it is:
From Gemini: In the context of MCP, the host is the AI-powered application that users interact with directly. Examples include AI assistants like Claude Desktop, IDEs like Cursor, or other AI-powered tools. It’s the central point where the user interacts with the AI and where the MCP clients are managed.
Connection Lifecycle
Initialization
- Client sends initialize request with protocol version and capabilities
- Server responds with its protocol version and capabilities
- Client sends initialized notification as acknowledgment
- Normal message exchange begins
Message Exchange
- Request-Response: Client or server sends requests, the other responds
- Notifications: Either party sends one-way messages
Termination
Either party can terminate the connection:
- Clean shutdown via
close()
- Transport disconnection
- Error conditions
Servers
Tools
Tools are a powerful primitive in the Model Context Protocol (MCP) that enable servers to expose executable functionality to clients. Through tools, LLMs can interact with external systems, perform computations, and take actions in the real world.
Source: Tools - Model Context Protocol
Here’s an example of a tool for a database focused MCP server:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { executeSqlToolHandler, executeSqlSchema } from "./execute-sql.js";
/**
* Register all tool handlers with the MCP server
*/
export function registerTools(server: McpServer): void {
// Tool to run a SQL query (read-only for safety)
server.tool(
"execute_sql",
"Execute a SQL query on the current database",
executeSqlSchema,
executeSqlToolHandler
);
}
Under the hood
executeSqlToolHandler
creates a database connection via a database manager like (node-postgres) to the relevant database- executes the query (example)
Resources
Resources are a core primitive in the Model Context Protocol (MCP) that allow servers to expose data and content that can be read by clients and used as context for LLM interactions.
Source: Resources - Model Context Protocol
Resources can include files, data or whatever context you want to give the model. Resource URIs look like:
[protocol]://[host]/[path]
For a database focused MCP server, a table resource could look like:
[Database table resource example would be shown here]
Prompts
Prompts enable servers to define reusable prompt templates and workflows that clients can easily surface to users and LLMs. They provide a powerful way to standardize and share common LLM interactions.
Source: Prompts - Model Context Protocol
Think of prompts as templates for what a user would want to put in the context window. Prompts are typically implemented as a slash commands.
What’s Next for MCP?
- Anthropic is starting to see MCP hosted servers (remote MCP) in cloud vs MCP servers running on your local machine
- MCP conferences
- Implementing authentication (who) and authorization (what)