Before the Model Context Protocol, connecting an AI assistant to a database, a ticketing system and a file store meant writing three integrations, and then writing them again for the next assistant. MCP replaced that with one protocol. A data source implements an MCP server once, and any compatible AI application can use it.
This article explains how the protocol works, what has changed in the 2026 spec revision, where the security risks are, and how to build a small MCP server in Python that exposes metric definitions to an agent. It's part of a series on the context layer for AI. The series overview explains why agents need governed business context, and MCP is the most common way that context reaches them.
What is the Model Context Protocol?
The Model Context Protocol is an open standard for connecting AI applications to external tools and data. Anthropic announced it in November 2024 as "a new standard for connecting AI assistants to the systems where data lives," with Block and Apollo among the early adopters.
In December 2025, Anthropic donated MCP to the Agentic AI Foundation, a directed fund under the Linux Foundation co-founded with Block and OpenAI. At that point Anthropic reported more than 10,000 active public MCP servers and over 97 million monthly SDK downloads, with support in ChatGPT, Cursor, Gemini, Microsoft Copilot and VS Code. Those are Anthropic's own figures.
A useful comparison is the Language Server Protocol, which the spec names as its inspiration. LSP let every editor support every programming language through one protocol. MCP does the same for AI applications and the systems they need to reach.
How the Model Context Protocol works
MCP has three roles.
- Host: the AI application the user interacts with, such as Claude, an IDE or your own agent.
- Client: a connector inside the host that talks to one server. A host runs one client per server.
- Server: a program that exposes capabilities, such as a database, a catalog or a SaaS API, through the protocol.
Messages are JSON-RPC 2.0. There are two standard transports:
- stdio: the client launches the server as a subprocess and exchanges newline-delimited JSON over standard input and output. Good for local tools.
- Streamable HTTP: each message is an HTTP POST to a single endpoint, and the server replies with JSON or a short-lived event stream. Good for remote, shared servers.
MCP tools, resources and prompts
An MCP server can offer three kinds of capability.
| Primitive | Who controls it | What it's for | Example |
|---|---|---|---|
| Tools | The model decides when to call them | Actions and queries | query_metrics, create_ticket |
| Resources | The application decides what to load | Read-only data addressed by URI | glossary://emea, a file, a table schema |
| Prompts | The user picks them | Reusable templates | "Explain this metric to a business user" |
MCP tools get most of the attention because they're how an agent acts, but resources are underrated for context work. A glossary entry or a table description is data the application can load without the model spending a tool call on it.
On the client side, the current spec lists elicitation, which lets a server ask the user for more information mid-task.
What changed in the 2026 spec
The protocol is versioned by date. The current revision, 2026-07-28, made bigger changes than earlier ones, and older tutorials don't reflect them.
- Stateless by design. Each request carries its protocol version and capabilities, and the session concept and
Mcp-Session-Idheader are gone. Servers implementserver/discoverinstead. - Deprecated features. Sampling, roots and logging are deprecated, with at least a 12-month window. The suggested replacements are passing paths as tool parameters, calling model APIs directly, and logging to stderr or OpenTelemetry.
- Old HTTP+SSE transport deprecated in favour of Streamable HTTP.
The Python SDK client (version 2.3.0) still requires a session.initialize() call, so you'll see one in the example below. If you're designing something new, don't build on sampling or roots.
Build an MCP server in Python
The official Python SDK changed shape in version 2.0, released in July 2026. The FastMCP class is now MCPServer, and the old import from mcp.server.fastmcp import FastMCP fails. The example below uses version 2.3.0.
Install the SDK with the CLI extras (Python 3.10 or later):
pip install "mcp[cli]"
Here's a small MCP server that exposes metric definitions, the kind of business context an analytics agent needs before it writes any SQL:
from mcp.server import MCPServer
mcp = MCPServer("metrics-catalog")
METRICS = {
"net_revenue": {
"definition": "Gross bookings minus refunds, excluding intercompany sales.",
"owner": "finance-analytics",
"certified": True,
},
"active_customers": {
"definition": "Customers with at least one paid order in the last 90 days.",
"owner": "growth-analytics",
"certified": True,
},
"revenue_legacy": {
"definition": "Old revenue metric, includes intercompany sales.",
"owner": "unknown",
"certified": False,
},
}
@mcp.tool()
def list_metrics(certified_only: bool = True) -> list[str]:
"""List metric names. By default only certified metrics are returned."""
return [name for name, m in METRICS.items() if m["certified"] or not certified_only]
@mcp.tool()
def get_metric(name: str) -> dict:
"""Return the definition, owner and certification status of one metric."""
if name not in METRICS:
raise ValueError(f"Unknown metric: {name}")
return {"name": name, **METRICS[name]}
@mcp.resource("glossary://{term}")
def glossary(term: str) -> str:
"""Business glossary entry for a term."""
entries = {"emea": "Europe, Middle East and Africa sales territory, by sales region, not billing country."}
return entries.get(term.lower(), f"No glossary entry for '{term}'.")
@mcp.prompt()
def explain_metric(name: str) -> str:
"""Prompt template that asks the model to explain a metric to a business user."""
return f"Explain the metric '{name}' in plain language, using get_metric for its definition."
if __name__ == "__main__":
mcp.run(transport="stdio")
Save it as server.py. The SDK builds each tool's schema from the type hints and uses the docstring as the description the model reads, so write docstrings for the model, not for yourself. Notice that list_metrics hides the uncertified legacy metric by default. That one line is a small piece of governance: the agent doesn't see the legacy metric in the listing unless it passes certified_only=False.
Call the server from a client
To check the server works, here's a short client that launches it over stdio, lists the MCP tools and calls them:
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
server = StdioServerParameters(command="python", args=["server.py"])
async def main():
async with stdio_client(server) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools = await session.list_tools()
print("tools:", [t.name for t in tools.tools])
result = await session.call_tool("list_metrics", {})
print("list_metrics:", result.structured_content)
result = await session.call_tool("get_metric", {"name": "net_revenue"})
print("get_metric:", result.content[0].text)
res = await session.read_resource("glossary://EMEA")
print("glossary:", res.contents[0].text)
asyncio.run(main())
Output:
tools: ['list_metrics', 'get_metric']
list_metrics: {'result': ['net_revenue', 'active_customers']}
get_metric: {
"name": "net_revenue",
"definition": "Gross bookings minus refunds, excluding intercompany sales.",
"owner": "finance-analytics",
"certified": true
}
glossary: Europe, Middle East and Africa sales territory, by sales region, not billing country.
The client sees two tools, the legacy metric is filtered out, and the glossary resource resolves "EMEA" to the sales territory, not the billing country. That last line is exactly the kind of fact that stops an agent from filtering on the wrong column.
Test with the MCP Inspector
For interactive testing, the SDK's CLI opens your server in the MCP Inspector, a browser UI where you can list and call tools by hand:
mcp dev server.py
You can also run the Inspector directly with npx @modelcontextprotocol/inspector followed by the command that starts your server. The Inspector needs a recent Node.js version.
Run it over HTTP
To share the server with remote clients, switch the transport. In version 2 of the SDK, transport settings go to run(), not the constructor:
mcp.run(transport="streamable-http", host="0.0.0.0", port=9000)
A common mistake with stdio servers: calling print() inside a tool. Standard output is the protocol channel, so stray prints corrupt the JSON-RPC stream. Log to standard error instead.
Security: what can go wrong with MCP servers
The spec is direct about the risk: tools are arbitrary code execution, and hosts must get user consent before calling them. Three problems come up most.
Tool poisoning. In April 2025, Invariant Labs described attacks where hidden instructions in a tool's description tell the model to read files such as SSH keys and leak them through a tool argument. The user never sees the description, and the model follows it. A server can also change its descriptions after you approved it, which Invariant calls a rug pull. Mitigations: show users full tool descriptions, pin descriptions by hash, and only install servers you trust.
Token passthrough. The authorization spec is based on OAuth 2.1. A remote MCP server acts as an OAuth resource server, must check that each token was issued for it, and must not forward the token it received to downstream APIs. If your server calls a warehouse on a user's behalf, it should get its own token for that call, scoped to that user.
Over-broad scopes. The security best practices page warns against wildcard scopes. Start with the least access and request more step by step.
For data teams, the practical rule is that an MCP server in front of a warehouse should enforce the same row and column security the user would get in a BI tool. An agent with a shared admin account is a data leak with a chat interface.
MCP servers in the data stack
Many data platforms now ship an MCP server, which is why the protocol matters for the context layer.
- Semantic layers expose metric tools. The hands-on guide to the dbt Semantic Layer for AI agents shows
list_metricsandquery_metricsfrom the official dbt MCP server. - Warehouses expose governed query tools. Snowflake's managed MCP server and Microsoft's Fabric IQ endpoints are compared in Snowflake Horizon Context vs Microsoft Fabric IQ.
- Catalogs expose search, lineage and glossary tools.
- Graph stores expose traversal and query tools, covered in knowledge graphs for AI agents.
MCP is how context gets delivered, not the context itself. Calling an MCP server your context layer skips the hard part, which is deciding what the definitions, permissions and relationships should be. The comparison of context and semantic layers covers that side, and how to build a context layer for AI puts the pieces in order.
Every tool you connect also costs context. Each tool definition sits in the model's prompt, and dozens of them degrade tool choice. The article on context engineering for AI agents covers tool selection and clearing old tool results.
Designing good MCP tools for data
The protocol is the easy part. The design of your MCP tools decides whether an agent uses your server well. A few rules help.
Design for tasks, not endpoints. Wrapping every REST endpoint as a tool gives the model 40 options and no guidance. A get_metric tool that returns the definition, owner and certification in one call beats three tools the model has to chain.
Return small, structured results. A tool that dumps 5,000 rows into the context window wastes tokens and buries the answer. Return summaries, the top rows, or a count with a way to page further.
Make errors useful. An error such as "Unknown metric: net_revenu. Did you mean net_revenue?" lets the model fix its own mistake, where a stack trace doesn't. The example server keeps its error simpler, and adding a suggestion with Python's difflib.get_close_matches is a small change.
Hide what shouldn't be used. Filter deprecated and uncertified assets out by default, as the example server does, rather than relying on the model to read a warning.
Keep descriptions precise. The description is the only documentation the model reads. Say what the tool returns, when to use it and when not to.
Version deliberately. Renaming a tool or changing its arguments breaks every agent that relied on it. Add new tools rather than changing old ones in place, and retire old ones on a schedule.
Several of these rules also cut the number of tool calls an agent makes, which saves latency and cost.
Should you use stdio or Streamable HTTP?
Use stdio when the server runs on the same machine as the host, such as a developer tool reading local files. The client starts and stops it, credentials come from environment variables, and there's no inbound network endpoint to secure.
Use Streamable HTTP when several users or agents share one server, when it sits next to a warehouse in your cloud, or when it needs central logging and OAuth. For data teams, governed servers in front of shared systems should almost always be remote HTTP servers with per-user authorization. Stdio suits local experiments and personal tools.
Model Context Protocol vs function calling
A common question: how is the Model Context Protocol different from the function calling built into model APIs?
Function calling is how a model asks to run a function within one application. You define the functions in your request, and your code runs them. MCP standardizes where those functions come from. An MCP client discovers tools from servers at runtime and hands them to the model as function definitions. The two work together. MCP doesn't replace function calling, it makes the tools portable across applications.
In practice the flow looks like this: the client calls list_tools on each server, the host passes those tools to the model as function definitions, the model returns a tool call, and the client sends it to the right server with call_tool. If your agent only ever uses three functions inside one application, plain function calling is enough. MCP pays off when the same tools are shared across agents and teams.
Common mistakes
- Copying v1 tutorials.
FastMCPimports fail on SDK version 2, and host and port now go torun(). - Printing to stdout in a stdio server. It breaks the protocol stream.
- Building on deprecated features. Sampling and roots are deprecated in the current spec.
- Vague docstrings. The model picks tools from their descriptions. "Gets data" is not a description.
- Too many tools on one server. Group by task and keep each server focused.
- Passing user tokens through. Get a scoped token per downstream service.
Key takeaways
- The Model Context Protocol is an open standard, now under the Linux Foundation, that lets any compatible AI application use tools, resources and prompts from any MCP server.
- Hosts run one client per server, messages are JSON-RPC 2.0, and the transports are stdio for local servers and Streamable HTTP for remote ones.
- The 2026-07-28 revision made the protocol stateless and deprecated sampling, roots and logging. The Python SDK version 2 renamed
FastMCPtoMCPServer. - A useful MCP server for data work is small, well described and governed: certified definitions only, per-user permissions, no token passthrough.
- MCP delivers context. It doesn't decide what the context should be.