What is MCP (Model Context Protocol)? Connecting AI assistants to your tools
Understand the problem MCP solves, the host-client-server architecture, the transports, the tools, resources, and prompts primitives, how to configure a client, build a minimal Python server, and use it all safely.
AI$ claude mcp list▍On its own, an AI assistant only knows what was in its training data and what you paste into the chat. To be useful in the daily work of people who build or run systems, it needs to look at the repository, read metrics, open a ticket, run a query. MCP (Model Context Protocol) is the standard that makes those connections predictable — and it’s what powers integrations like the Grafana MCP server.
Coming up: the problem it solves, how it works under the hood, how to configure a client, build a server in Python, and use it safely.
The problem: N × M integrations
Picture 5 AI applications (a desktop chat app, an IDE extension, a terminal tool, an internal bot, a CI agent) and 10 systems you want to connect (Git, databases, observability, cloud, ticketing…). Without a standard, every application needs its own connector for every system: that’s N × M integrations, each with its own format, its own authentication, and its own bugs.
With a common protocol, the math becomes N + M: each system is exposed once as an MCP server, and each application implements the protocol once as a client. It’s the same idea that made USB and LSP (Language Server Protocol, which standardized how editors talk to language tooling) so useful.
MCP was introduced by Anthropic in late 2024 as an open specification, with official SDKs in several languages. Since then it has been adopted by many tools and vendors; today it is an open standard with broad adoption — check the current governance on the official site, modelcontextprotocol.io.
Architecture: host, client, and server
MCP defines three roles:
- Host: the application the user works in and that contains the model — a chat app, an IDE, a terminal tool. The host decides which servers to connect to and when to ask the user for approval.
- Client: the component inside the host that maintains one connection to one server. A host with three servers has three clients.
- Server: a program that exposes capabilities (tools, data, prompts) from a specific system.
Host (AI app: chat, IDE, terminal)
├── Model (LLM)
├── MCP client A ──── stdio ──────────▶ Local MCP server: Git
├── MCP client B ──── stdio ──────────▶ Local MCP server: Postgres
└── MCP client C ──── Streamable HTTP ▶ Remote MCP server: observability
Notice that the model doesn’t talk to the server directly. It asks to use a tool; the host mediates, may ask the user for confirmation, makes the call through the client, and hands the result back to the model as context.
Transports and messages
Messages use the JSON-RPC 2.0 format: requests with id, method, and params, responses with result or error, and notifications that expect no reply. A tool call looks like this:
{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "http_status",
"arguments": { "url": "https://example.com" }
}
}
These messages travel over a transport:
| Transport | How it works | Typical use |
|---|---|---|
| stdio | The host launches the server as a child process and exchanges messages over standard input and output | Local servers, on the user’s machine |
| Streamable HTTP | The server is a standalone HTTP service; the client sends POST requests and can receive streamed responses | Remote servers, shared by a team |
The older HTTP+SSE transport was superseded by Streamable HTTP in more recent versions of the specification; you may still run into it on older servers.
Server primitives: tools, resources, and prompts
An MCP server can offer three kinds of capability:
| Primitive | What it is | Who controls it | Example |
|---|---|---|---|
| Tools | Functions the model can invoke, with parameters described by JSON Schema | The model decides to call them (with host/user approval) | create_issue, run_query, restart_deployment |
| Resources | Read-only data identified by a URI | The application/user picks what to attach to the context | file:///repo/README.md, a database schema |
| Prompts | Reusable message templates with arguments | The user picks them (for example, as a slash command) | “Review this PR”, “Summarize incident” |
In practice, tools are the most used primitive and the one that demands the most care, because they can have side effects. The protocol also defines features the client offers to the server, which are less common — check the specification if you need them.
Configuring a client
Most hosts use a configuration in the mcpServers format: a name for each server, the command that starts it, its arguments, and its environment variables.
{
"mcpServers": {
"http-status": {
"command": "python3",
"args": ["/home/you/mcp/server.py"],
"env": {
"HTTP_TIMEOUT": "10"
}
}
}
}
Where this file lives varies from one application to another (desktop app, IDE, terminal tool) — check your host’s documentation. In Claude Code, you register servers from the command line:
# local server over stdio (everything after -- is the server command)
claude mcp add http-status -e HTTP_TIMEOUT=10 -- python3 /home/you/mcp/server.py
# remote server over Streamable HTTP
claude mcp add --transport http observability https://mcp.example.com/mcp
# check what is configured
claude mcp list
A minimal MCP server in Python
The official Python SDK includes FastMCP, which turns plain functions into tools: the typed signature becomes the parameters’ JSON Schema, and the docstring becomes the description the model reads. Install the SDK (it requires a recent Python; see the minimum version in the README):
pip install "mcp[cli]"
Our server will have a single tool that returns the HTTP status of a URL, using only the standard library:
# server.py
import os
import urllib.error
import urllib.request
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("http-status")
TIMEOUT = float(os.environ.get("HTTP_TIMEOUT", "10"))
@mcp.tool()
def http_status(url: str) -> str:
"""Return the HTTP status code of a URL (HEAD request)."""
if not url.startswith(("http://", "https://")):
return "Error: provide a URL starting with http:// or https://"
req = urllib.request.Request(url, method="HEAD")
try:
with urllib.request.urlopen(req, timeout=TIMEOUT) as resp:
return f"{url} returned {resp.status}"
except urllib.error.HTTPError as e:
return f"{url} returned {e.code}"
except urllib.error.URLError as e:
return f"Failed to reach {url}: {e.reason}"
if __name__ == "__main__":
mcp.run() # default: stdio transport
Two important details: in stdio servers, never print() to standard output, because it is the protocol channel — log to stderr instead. And before connecting it to an assistant, test the server with the MCP Inspector, an official web UI for listing and calling tools by hand (mcp dev server.py opens the Inspector with your server).
Security: the assistant acts with your credentials
An MCP server is code that runs with access to your systems. Treat it like any privileged dependency:
- Least privilege for tokens: create dedicated credentials, read-only whenever possible, with narrow scope and a set expiration.
- Review what each tool does: read the list of tools and their descriptions. A “query” tool that accepts arbitrary SQL can also drop tables.
- Prompt injection through results: content coming back from a tool (a log line, an issue, a web page) may contain malicious instructions. The model can’t reliably tell data from commands — see the AI application security guide.
- Trust only reviewed servers: prefer official vendor servers or code you have audited, and pin versions. A server installed from just anywhere is a supply chain risk.
- Human approval for side effects: keep the host’s confirmation on for tools that write, delete, or spend money.
- Watch network access: even our innocent example lets the model reach internal URLs. In production, restrict destinations.
Popular servers by category
The ecosystem moves fast; check the official site and the community-maintained server registries before choosing:
- Git hosting: repositories, issues, pull requests, and pipelines.
- Observability: dashboards, metric and log queries, alerts — like the Grafana server.
- Databases: schema inspection and queries (ideally with a read-only user).
- Cloud: documentation, resource inventory, and operations on the major providers.
Many of these servers are, underneath, a wrapper around an existing REST API — MCP standardizes the description and the call, but the API remains the source of truth. And when a model combines several servers to plan and carry out steps on its own, we arrive at AI agents in DevOps.
Summary
- MCP replaces N × M integrations with N + M through a common protocol
- The host contains the model; each client keeps one connection to one server
- Messages are JSON-RPC 2.0 over stdio (local) or Streamable HTTP (remote)
- Servers offer tools, resources, and prompts
- A minimal Python server fits in a few lines with FastMCP
- Least-privilege tokens, reviewed servers, and human approval for actions with side effects
MCP gives the assistant hands; it’s up to you to decide what those hands can touch.