Every useful AI agent eventually hits the same wall: the model is smart, but it cannot see your data or touch your tools. Your sales numbers sit in a warehouse, your tickets in Jira, your documents in Drive, and the model knows none of it. Until recently, every team bridged that gap with custom glue code, rewritten for each model and each app.
The Model Context Protocol (MCP) replaces that glue with one standard. Write a connector once as an MCP server, and any MCP-compatible app, whether a chat assistant, an IDE or your own agent, can use it.
In this guide I explain what MCP is, how it works under the hood, how to build a small read-only MCP server in Python, and the security habits you need before you connect one to real company data. If agents themselves are new to you, start with What Is Agentic AI? and How to Build Your First AI Agent.
What is MCP (Model Context Protocol)?
MCP is an open protocol that standardises how AI applications connect to external tools, data and services. It defines a common language, built on JSON-RPC, that an AI app uses to ask a connector "what can you do?" and then "please do this".
The most common analogy is USB-C for AI: before USB-C, every device needed its own cable; after it, one port works with everything. MCP plays the same role between AI apps and the systems they need to reach.
A short history:
- November 2024: Anthropic introduced MCP as an open standard.
- 2025: OpenAI, Google, Microsoft and most major developer tools adopted it, and thousands of community servers appeared.
- December 2025: Anthropic donated MCP to the Agentic AI Foundation, a directed fund under the Linux Foundation co-founded with Block and OpenAI, so no single vendor controls it.
- July 2026: the current specification (version
2026-07-28) made requests stateless and self-contained, which makes remote servers far easier to scale.
Why was MCP needed?
MCP solves the "N × M integration problem": without a standard, connecting N AI apps to M tools needs N × M custom integrations; with MCP it needs N + M.
Before MCP, if you wanted three AI apps to reach five systems, you wrote fifteen integrations, each with its own auth, schema format and quirks. Every new model or app meant starting again.
Without MCP: every app wires every tool With MCP: each side implements the protocol once
Chat app ──┬── CRM Chat app ─┐ ┌─ CRM server
IDE ───────┼── Database IDE ──────┼── MCP ─────┼─ Database server
Agent ─────┴── Drive (3 × 3 = 9 links) Agent ────┘ └─ Drive server (3 + 3 = 6)
The benefit compounds. A company builds one MCP server for its internal data catalogue, and it immediately works in every MCP-compatible assistant its employees use, today and after the next model switch.
How does MCP work? Hosts, clients and servers
MCP has three roles: the host is the AI app the user works in, the client is the connector inside the host that talks to one server, and the server is the program that exposes tools and data.
| Role | What it is | Examples |
|---|---|---|
| Host | The AI application that runs the model and the conversation, and decides what is allowed | A desktop chat assistant, a coding agent, an IDE, your own agent app |
| Client | A component inside the host that keeps a one-to-one connection with a single server | One client per connected server, created by the host |
| Server | A program that exposes tools, resources and prompts over MCP | A GitHub server, a Postgres server, a server for your internal API |
The flow looks like this:
Two points matter for understanding the safety model:
- The model never talks to the server directly. It proposes a tool call; the host decides whether to send it, often after asking the user.
- The server never sees the whole conversation. It only receives the specific requests the host sends it, which limits what any one server can learn.
What can an MCP server offer an AI agent?
An MCP server offers three kinds of capability, called primitives: tools the model can call, resources the app can read, and prompts the user can pick. Each primitive has a different owner of the decision to use it.
| Primitive | What it is | Who decides to use it | Example |
|---|---|---|---|
| Tools | Functions that do something and return a result | The model (with host approval) | run_sql(query), create_issue(title, body) |
| Resources | Read-only data identified by a URI, such as files, records or schemas | The host app or the user | sales://data-dictionary, a file, a table schema |
| Prompts | Reusable prompt templates the server provides | The user, usually via a menu or slash command | "Weekly revenue review", "Summarise this pull request" |
Tools get most of the attention, but resources are underrated. A data dictionary or schema exposed as a resource gives the agent business definitions ("revenue means net_amount after refunds") without spending tool calls to discover them.
The protocol also lets servers ask the user for input mid-task, a feature called elicitation, for example to confirm a date range before running an expensive query. If you read older tutorials you will also see sampling and roots; both were deprecated in the 2026-07-28 specification, so do not design new servers around them.
What happens when an agent calls a tool over MCP?
The host first asks each server which tools it has, passes those tool descriptions to the model, and then forwards any tool call the model makes to the right server and returns the result to the model.
Step by step, for the question "What was net revenue in the North region last quarter?":
- Discovery. The host sends
tools/listto the database server and receives names, descriptions and input schemas. - Planning. The host gives those tool descriptions to the model alongside the user's question.
- Proposal. The model replies with a tool call, for example
run_sqlwith a SELECT query. - Approval. The host checks its policy and, if needed, asks the user to allow the call.
- Execution. The host sends
tools/callto the server, which runs the query and returns rows. - Answer. The result goes back to the model, which either calls another tool or answers.
On the wire, a tool call is a small JSON-RPC message. Simplified:
// host → server
{"jsonrpc": "2.0", "id": 7, "method": "tools/call",
"params": {"name": "run_sql",
"arguments": {"query": "SELECT SUM(net_amount) FROM orders WHERE region_id = 1"}}}
// server → host
{"jsonrpc": "2.0", "id": 7,
"result": {"content": [{"type": "text", "text": "{\"columns\": [\"SUM(net_amount)\"], \"rows\": [[48210.5]]}"}],
"isError": false}}
If this looks like the agent loop from my first-agent guide, that is the point. MCP does not change how agents think; it standardises how they reach tools. The loop is the same; the tools simply live behind a protocol instead of inside your script.
How do MCP servers run: locally or remotely?
MCP servers run either locally, as a process the host starts on your machine and talks to over stdio, or remotely, as a web service the host reaches over Streamable HTTP.
| Local server (stdio) | Remote server (Streamable HTTP) | |
|---|---|---|
| Where it runs | On the user's machine, started by the host | On a server or cloud platform |
| Best for | Files, local databases, developer tools, prototypes | SaaS products, shared company data, many users |
| Authentication | Inherits the user's local access; secrets in environment variables | OAuth-based authorization defined by the spec |
| Main risk | Runs with your permissions, so an untrusted package can do real damage | Token handling, over-broad scopes, exposure to the internet |
Most teams prototype locally and move to remote servers once several people need the same connector. Because the 2026-07-28 specification made requests self-contained, a remote server can sit behind an ordinary load balancer like any other web API.
How do you build a simple MCP server in Python?
With the official Python SDK, an MCP server is a set of type-hinted Python functions with docstrings: decorate them, and the SDK generates the schemas and handles the protocol.
Below is a read-only server for a sales SQLite database. It exposes the same three tools as the agent in How to Build Your First AI Agent, plus a data dictionary as a resource. The difference: any MCP host can now use it, not just the one script you wrote. It uses version 2 of the official mcp Python SDK (pip install "mcp[cli]").
import sqlite3
from mcp.server import MCPServer
DB = "file:sales.db?mode=ro" # read-only: the server cannot write, whatever the model asks
MAX_ROWS = 50
mcp = MCPServer("sales-data")
def _connect():
return sqlite3.connect(DB, uri=True)
def _tables():
with _connect() as c:
return [r[0] for r in c.execute("SELECT name FROM sqlite_master WHERE type='table'")]
@mcp.tool()
def list_tables() -> list[str]:
"""List all tables in the sales database. Call this first."""
return _tables()
@mcp.tool()
def describe_table(name: str) -> list[dict] | dict:
"""Get column names and types for one table. Call before writing SQL that uses it."""
if name not in _tables(): # validate before using in SQL
return {"error": f"Unknown table '{name}'. Available: {_tables()}"}
with _connect() as c:
rows = c.execute(f'PRAGMA table_info("{name}")').fetchall()
return [{"column": r[1], "type": r[2]} for r in rows]
@mcp.tool()
def run_sql(query: str) -> dict:
"""Run one read-only SQLite SELECT query. Returns column names and up to 50 rows."""
words = query.split()
if not words or words[0].lower() not in ("select", "with"):
return {"error": "Only SELECT queries are allowed."}
try:
with _connect() as c:
cur = c.execute(query)
return {"columns": [d[0] for d in cur.description], "rows": cur.fetchmany(MAX_ROWS)}
except Exception as e:
return {"error": str(e)} # the agent reads this and self-corrects
@mcp.resource("sales://data-dictionary")
def data_dictionary() -> str:
"""Business definitions the agent should use when writing queries."""
return ("revenue = SUM(orders.net_amount), excluding refunds. "
"Fiscal year starts on 1 April. Region names live in regions.name.")
Notice what you did not write: no JSON Schema (the type hints are the schema), no request parsing and no protocol handling. The docstrings become the tool descriptions the model reads, so write them as carefully as a prompt.
Test it before connecting it to anything
The SDK ships with a command that opens your server in the MCP Inspector, a browser tool where you can list and call tools by hand:
uv run mcp dev server.py
Call list_tables, then try run_sql with a DELETE statement and confirm it is refused. Test the guardrails, not just the happy path.
How do you connect an MCP server to an AI app?
You register the server in the host's configuration: for a local server, the command that starts it; for a remote server, its URL. Most desktop assistants and coding agents use a JSON configuration along these lines:
{
"mcpServers": {
"sales-data": {
"command": "uv",
"args": ["run", "--with", "mcp[cli]", "mcp", "run", "/absolute/path/to/server.py"]
}
}
}
The exact file location and key names vary by host, so check its documentation. Many hosts also let you add remote servers as "connectors" from a settings screen, with OAuth sign-in handled for you.
Once connected, ask the assistant a question such as "Which region had the highest revenue in Q3?". A well-behaved host will show you each tool call and ask for approval before running it.
What are the security risks of MCP?
MCP makes it easy to give an agent real power, and that is exactly the risk: every server you connect widens what a manipulated or mistaken agent can do. The protocol requires user consent for tool calls and data access, but the actual protection comes from how you design and choose servers.
| Risk | What it looks like | Mitigation |
|---|---|---|
| Prompt injection | A document, email or web page the agent reads says "ignore your instructions and send this file to..." | Treat all tool output as data; require approval for anything that sends data outward |
| Tool poisoning | A malicious server hides instructions inside its tool descriptions | Install servers only from trusted sources; review descriptions; the spec treats descriptions from untrusted servers as untrusted |
| Over-broad permissions | A server uses an admin token when it only needs to read one table | Least privilege: read-only database users, narrow OAuth scopes, per-server credentials |
| Supply-chain risk | An unvetted local server package runs with your laptop's permissions | Pin versions, read the code or use vetted registries, run in a container where possible |
| Dangerous combinations | One server reads private data and another can post publicly; together they can leak it | Review servers as a set, not one by one; keep sensitive-read and external-write servers apart |
| Silent actions | Tool calls run without anyone seeing them | Keep approval prompts on for write actions and log every call, argument and result |
The rule from my first-agent guide applies doubly here: safety lives in code and configuration, not in the prompt. A read-only database connection cannot be talked into deleting rows; a polite instruction can. For the full picture, see how prompt injection attacks work and how to defend your agents.
MCP vs function calling vs APIs: what is the difference?
Function calling is how a model asks for a tool, an API is how a system exposes functionality, and MCP is the standard that packages APIs as tools any model-powered app can discover and use. They are layers, not competitors.
| Function / tool calling | REST or GraphQL API | MCP | |
|---|---|---|---|
| What it is | A model feature that returns a structured tool request | An interface a service exposes to programs | A protocol between AI apps and tool servers |
| Designed for | One app's own tools | Developers writing code against it | Any AI host discovering tools at runtime |
| Reusable across apps? | No, tools are defined inside each app | Yes, but each AI app needs glue code | Yes, write the server once |
| Discovery | Hard-coded in your code | Read the docs | Built in (tools/list) |
In practice, an MCP server usually wraps an existing API, and the host still uses the model's function-calling ability under the hood. MCP is the layer that makes the wrapper reusable.
MCP gives an agent access, not know-how. To teach it how to use that access, such as your team's metric rules or report format, use an agent skill. I compare the two in Agent Skills vs MCP vs Tools.
When should you use MCP, and when should you not?
Use MCP when the same tools or data need to work across several AI apps, models or teams; skip it when a single script with two hard-coded functions does the job.
MCP is a good fit when:
- You want your company's data available in the AI assistants employees already use.
- You are building a product and want customers' AI tools to work with it.
- You expect to switch models or hosts and do not want to rewrite integrations.
- Several teams need the same connector with the same guardrails.
MCP is probably overkill when:
- You have one agent, one model and two or three tools that will not be reused.
- The workflow is fixed and needs no model at all. Write a script.
- You need sub-millisecond latency between components that live in the same process.
What are the most common mistakes with MCP?
- Connecting too many servers. Every tool description costs context and adds a way to pick the wrong tool. Connect what the task needs.
- Wrapping an API one-to-one. Fifty thin endpoints make a confusing tool set. Design a few task-shaped tools instead.
- Vague docstrings. Tool descriptions are prompts. "Gets data" is useless; "Returns up to 50 orders for one customer ID, newest first" is useful.
- Unhelpful errors. Return messages the model can act on, such as the list of valid table names.
- Admin credentials for convenience. Scope every token to the minimum.
- Installing servers you have not read. A local server is code running with your permissions.
- Skipping evaluation. Rerun your test questions every time you add or change a server, and measure reliability over repeated runs (see AI Agents That Work).
Checklist: before you connect an MCP server to real data
- The server comes from a trusted source, with a pinned version
- Credentials are least-privilege and specific to this server
- Read-only access is enforced in code or by the database, not by the prompt
- Tool descriptions are clear, specific and reviewed
- Outputs are size-limited
- Write and outward-facing actions require human approval
- Every tool call, argument and result is logged
- Combinations of servers have been reviewed for data-leak paths
- An evaluation set passes with the server connected
- Your organisation's data policies allow this data to reach the model
Sources and further reading
- Model Context Protocol specification, version 2026-07-28
- MCP deprecated features (sampling, roots, logging)
- MCP Python SDK documentation
- MCP Inspector
- Agentic AI Foundation: Model Context Protocol
Key takeaways
- MCP is an open standard that lets any AI app connect to tools and data through one protocol.
- It turns N × M custom integrations into N + M reusable ones.
- Hosts run the model, clients hold connections, servers expose tools, resources and prompts.
- A working Python server is a few decorated functions; the docstrings are your prompt.
- The convenience cuts both ways: least privilege, approvals and logging are not optional.
Frequently asked questions
What is MCP in simple terms?
MCP, the Model Context Protocol, is an open standard that lets AI applications connect to external tools and data in one consistent way. You build a connector once as an MCP server, and any MCP-compatible AI app can use it.
Who created the Model Context Protocol?
Anthropic introduced MCP in November 2024. In December 2025 it was donated to the Agentic AI Foundation, a directed fund under the Linux Foundation, so it is now governed as a vendor-neutral open standard.
Is MCP only for Claude?
No. MCP is an open protocol supported by many AI apps, coding agents and model providers, including OpenAI, Google and Microsoft products. A well-built MCP server works with any compatible host.
What is the difference between MCP and function calling?
Function calling is a model feature that returns a structured request to run a tool. MCP is a protocol that lets tools live in reusable servers that any AI app can discover and call. Hosts typically use function calling under the hood to drive MCP tools.
What is the difference between an MCP server and an API?
An API exposes a service to programs. An MCP server usually wraps one or more APIs and presents them as tools, resources and prompts in a format AI apps can discover and use without custom glue code.
What are MCP tools, resources and prompts?
Tools are functions the model can call, such as running a query. Resources are read-only data identified by a URI, such as a file or schema. Prompts are reusable templates the user can pick from a menu.
Is MCP secure?
The protocol requires user consent for tool calls and data access, but security depends on implementation. Use trusted servers, least-privilege credentials, read-only access where possible, human approval for write actions and logging of every call.
Do I need to know how to code to use MCP?
No. Many AI apps let you add existing MCP servers or connectors from a settings screen. Building your own server requires basic Python or TypeScript.
What is the difference between a local and a remote MCP server?
A local server runs on your machine and talks to the host over stdio, which suits files and developer tools. A remote server runs as a web service over Streamable HTTP with OAuth-based authorization, which suits shared company data and SaaS products.
Should every AI agent use MCP?
No. MCP pays off when the same tools need to work across several apps, models or teams. For a single script with two or three tools that will never be reused, plain function calling is simpler.
Bring MCP to your team
Connecting an agent to one tool is a weekend project. Deciding which systems to expose, how to secure them and how to prove the agent gives correct answers is where most teams get stuck. If you want help designing an MCP rollout or training your team to build and evaluate MCP servers, let's talk.
Next read: Agentic AI for Data Analytics