# 13. The Model Context Protocol

What MCP is and why it exists. Hosts, clients and servers; tools, resources and prompts; stdio and Streamable HTTP transports; security considerations; and how agents and workflows use it.

Source: https://glamorous-boar.cloudvent.net/learn/mcp/

---

## The problem

Every AI application wants to reach the same things: GitHub, Slack, databases, file systems, calendars, internal APIs. Without a standard, each app writes its own integration for each service: an *M × N* problem. The **Model Context Protocol (MCP)**, introduced by Anthropic in 2024 as an open standard, turns it into *M + N*: services expose an **MCP server** once, and any **MCP client** can use it. People often call it "USB-C for AI applications".

## Architecture

- **Host**: the AI application the user interacts with (a desktop assistant, an IDE, an agent platform).
- **Client**: the component inside the host that holds a connection to one server.
- **Server**: a program that exposes capabilities over the protocol.

Messages are JSON-RPC 2.0. A session starts with a handshake in which both sides agree on the protocol version and capabilities.

### What servers expose

| Primitive | Controlled by | Example |
|---|---|---|
| **Tools** | The model (it decides to call them) | `create_issue`, `run_query`, `send_message` |
| **Resources** | The application (it decides what to load) | Files, records, documents identified by URI |
| **Prompts** | The user (templates they pick) | *Summarise this PR* |

Clients can also offer capabilities to servers, such as **sampling** (the server asks the client's model to generate text) and **elicitation** (the server asks the user for input).

Tools are the most widely used primitive: each has a name, a description and a JSON Schema for its input, exactly like function calling (chapter 3). An MCP client simply turns a server's tool list into tool definitions for its model.

### Transports

- **stdio**: the host starts the server as a local subprocess and talks over standard input/output. Simple, local, common for desktop tools (`npx some-mcp-server`).
- **Streamable HTTP**: the server is an HTTP endpoint; responses can be plain JSON or streamed. Used for remote and shared servers. (It superseded the older HTTP+SSE transport.)

Remote servers typically authenticate with bearer tokens or OAuth.

## Security considerations

MCP makes it easy to give a model powerful tools, so the usual agent risks apply, sharpened:

- **Trust the server**: a stdio server runs with your privileges; a malicious one can do anything you can.
- **Tool descriptions are prompts**: a server can hide instructions in a tool description (tool poisoning).
- **Tool results are untrusted data**: they can carry indirect prompt injection.
- **Least privilege**: expose only the tools needed (include/exclude lists); scope tokens narrowly.
- **Isolate secrets**: do not leak the host's environment variables into server processes.
- **Network checks**: block requests to private and metadata addresses; check `Host` headers on servers to prevent DNS rebinding.

## MCP and workflows

MCP works in both directions for a workflow platform:

- As a **client**, an agent can use any MCP server's tools alongside native ones.
- As a **server**, a workflow (with typed inputs and outputs) becomes a single, well-described tool that other agents can call. A complex, tested, evaluated pipeline (RAG with reranking and guardrails) is then reusable by Claude, Cursor or another agent as one reliable step.

## Try it in AgenticMind

- **MCP Server** node: connect over stdio or Streamable HTTP, filter tools, prefix names; feed an Agent's `tools`.
- **MCP Call** node: call one MCP tool directly, no model.
- **Expose as MCP tool**: any project becomes a tool at `/api/mcp`, its Manual Inputs becoming the input schema; protect it with `AGENTICMIND_MCP_TOKEN`.
- `agenticmind mcp-serve graph.json`: serve graph files over stdio.
- Template *Agent with MCP tools*.

See [MCP](/mcp/).

<Alert variant="tip" title="Key takeaways" text="MCP is an open protocol that lets any AI host use any tool server: tools, resources and prompts over stdio or Streamable HTTP. It removes per-app integrations, but every server is code you trust and every tool result is untrusted text. A workflow platform can be both a client and a server."/>
