Model Context Protocol (MCP)
The Model Context Protocol (MCP) is an open standard that connects AI applications to tools and data through one interface. Architecture, uses, and code.
The Model Context Protocol (MCP) is an open standard for connecting AI applications to external tools, data sources, and workflows. Before MCP, every AI application needed its own custom integration for every service it used, so ten assistants and ten services meant up to a hundred separate connectors. With MCP, a service is wrapped once as an MCP server, and any MCP-compatible application can use it. Anthropic introduced the protocol in November 2024 and in December 2025 donated it to the Agentic AI Foundation, a fund under the Linux Foundation that Anthropic co-founded with Block and OpenAI. Hosts including Claude, ChatGPT, VS Code, Cursor, and Gemini CLI support it, and it has become the standard way for AI agents and large language models (LLMs) to reach the outside world.
How MCP Works#
The MCP specification defines three roles that exchange JSON-RPC 2.0 messages. The host is the AI application the user works in, such as a chatbot, an IDE, or an agent. Inside the host, one client manages the connection to each server, and each server exposes a set of capabilities. Local servers run as subprocesses and talk over standard input and output (stdio), while remote servers use Streamable HTTP. Since the 2026-07-28 revision, the core protocol is stateless: each request carries its own protocol version and client capabilities, the old initialize handshake and session IDs are gone, and any server instance behind a load balancer can answer any request.
Servers offer three kinds of capabilities:
- Tools: Functions the model can call, each described by a name, a description, and a JSON Schema for its arguments, such as
create_issueorrun_query. Tools can return text, images, or structured data. - Resources: Read-only context identified by URIs, such as files, database schemas, or log excerpts, which the application can attach to the model's context.
- Prompts: Reusable message templates that users pick explicitly, often surfaced as slash commands.
Servers can also ask the user for missing input in the middle of a task through elicitation. Optional extensions add more: Tasks handles long-running operations that a client polls for results, and MCP Apps lets a tool return an interactive interface, the approach to generative UI that renders charts and forms inside the conversation.
Building an MCP Server#
The official MCP Python SDK turns a typed Python function into a tool and generates its JSON Schema from the type hints. Wrapping Ultralytics YOLO26 prediction this way gives any MCP host object detection: the tool returns Results.summary(), a list with each object's class name, confidence, and box coordinates that the model can reason over. Here an in-process client discovers and calls the tool the same way a host would:
import asyncio
from mcp import Client
from mcp.server.mcpserver import MCPServer
from ultralytics import YOLO
model = YOLO("yolo26n.pt")
server = MCPServer("vision")
@server.tool()
def detect(image_url: str) -> list[dict]:
"""Detect objects in an image and return each object's class, confidence, and box."""
results = model(image_url)
return results[0].summary()
async def main():
"""Discover the server's tools and call one, as an MCP host does."""
async with Client(server) as client:
tools = await client.list_tools()
print(tools.tools[0].name, tools.tools[0].input_schema)
result = await client.call_tool("detect", {"image_url": "https://ultralytics.com/images/bus.jpg"})
print(result.structured_content)
asyncio.run(main())The first print shows the tool's name and the input schema a host's model sees, which requires one string argument, image_url, and the second shows the detection list returned as structured content.
MCP vs. Related Concepts#
- Function calling: The model's ability to emit a structured request for a tool. MCP standardizes how tools are discovered, described, and executed across applications, and the host converts MCP tool definitions into the model's native function-calling format.
- APIs: A REST or GraphQL API serves one service's clients. An MCP server often wraps such an API and adds the names, descriptions, and schemas a model needs to use it without custom code.
- Retrieval-augmented generation (RAG): A technique for grounding answers in retrieved documents. MCP is one way to deliver that retrieval, through a search tool or attached resources.
- Agent2Agent (A2A) protocol: Connects agents to other agents so they can delegate whole tasks. MCP connects an agent to the tools and data it uses directly.
- Agent skills: Folders of instructions and scripts that an agent loads into its context when a task calls for them. Skills teach an agent how to do a task, and MCP servers give it live access to the systems involved, so agents commonly use both.
Real-World Applications#
- Agentic coding: Coding agents connect to GitHub, issue trackers, databases, and browsers through MCP servers, so asking why a login fails lets the agent pull error logs, read the authentication code, and check open issues in one session.
- Enterprise assistants: Connectors to document stores, chat, ticketing, and CRM systems let an assistant answer questions from company data and file updates on the user's behalf.
- Visual inspection: An agent calls a detection tool on a camera image, queries an inventory server for replacement parts when it finds a damaged component, and drafts a maintenance ticket, turning a single prediction into a complete automation workflow.
- Data analytics: Database servers expose read-only query tools, so analysts can ask questions in plain language and get answers computed from live tables.
Security Considerations#
An MCP tool can run arbitrary code with the user's credentials, so each connection extends what the model can do and what an attacker can reach. Tool results and resources can carry prompt injection, text that tries to make the model call other tools or leak data, and a malicious server can hide instructions in its own tool descriptions, an attack known as tool poisoning. Remote servers authenticate users with OAuth-based authorization, and careful hosts limit each server to the permissions it needs, run local servers in sandboxes, and add guardrails such as approval prompts before sensitive actions. The specification requires hosts to obtain explicit user consent before invoking any tool and to treat tool descriptions as untrusted unless they come from a trusted server.










