# MCP

The Model Context Protocol lets an agent call tools and read data from external servers through one standard interface.

> MCP, the Model Context Protocol, is an open standard for connecting a harness to external servers that offer tools and data. It lets the agent reach systems beyond the repo.

Source: https://ai-sw-factory.mellicci.dev/fundamentals/mcp

**Diagram:** MCP lets the harness's client call servers, local or remote, that reach external systems.

- Model — asks for a tool
- → tool call
- Harness:
  - Built-in tools — files, shell
  - MCP client — routes to servers
- → MCP
- MCP servers:
  - Local server — started by harness
  - Remote server — over HTTP
- →
- External systems — issues, databases, docs

MCP standardises how a harness talks to something outside the repository: an issue tracker, a database, a documentation service. The harness acts as an MCP **client**. Each **MCP server** advertises its tools (and possibly resources and prompts), and the harness makes those tools available to the model next to the built-in ones.

A server runs either locally, started by the harness and reached over standard input and output (stdio), or remotely, reached over HTTP. From the model's side, an MCP tool looks like any other tool call.

<info title="The standard">

MCP is open and vendor-neutral — [modelcontextprotocol.io](https://modelcontextprotocol.io) ·
[current specification](https://modelcontextprotocol.io/specification/latest) ·
[reference SDKs and servers on GitHub](https://github.com/modelcontextprotocol).

</info>

## Why it exists

Built-in tools cover files and the shell. Without a standard, reaching an issue tracker means custom glue for each agent and each system, or copy-pasting text into the prompt. The agent then works from your paraphrase of the issue instead of the issue.

## How it works

**Diagram:** You configure servers once. Their tool definitions cost context (some agents load schemas only when needed), and every call passes the harness's permission checks before a server does the work with its own credentials.

- You configure — command or URL
- → session start
- Tools listed — names and schemas
- →
- Model calls one — fills in arguments
- →
- Harness checks — permission rules
- →
- Server works — own credentials

<warning>

An MCP server is code you run or a service you trust, and its output enters the context. Treat both as part of your attack surface; see the [Security model](https://ai-sw-factory.mellicci.dev/fundamentals/security-model).

</warning>

## Use it when

- **The agent needs live information that isn't in the repository** — issues and their acceptance
  criteria, internal docs and wikis, logs and metrics, database schemas, design files.
- **The agent must act on an external system** — comment on a pull request, update a ticket, query a
  staging database — through a typed, documented interface instead of improvised API calls.
- **Credentials should stay out of the agent's environment** — the server holds the tokens and
  exposes only the operations you chose.
- **The job is awkward to do reliably from a shell** — authenticated APIs, pagination, browser
  automation — and a tool with a schema makes each call predictable.
- **One integration should serve many agents and teams** — the protocol is shared, so the same server
  works across agents that speak MCP.
- **Access needs central control and an audit trail** — an organisation-run remote server can limit
  tools, log every call and rotate credentials in one place.

## Use something else when

- The information is stable and repo-local → [Instruction files](https://ai-sw-factory.mellicci.dev/fundamentals/instruction-files)
- A command-line tool already does the job and a procedure describes it → [Skills](https://ai-sw-factory.mellicci.dev/fundamentals/skills)
- You need a guarantee about what runs, not a new capability → [Hooks](https://ai-sw-factory.mellicci.dev/fundamentals/hooks)
- A side task would flood the context with tool output → [Subagents](https://ai-sw-factory.mellicci.dev/fundamentals/subagents)
- You need a couple of calls, once — a small script is cheaper than a server whose tool list is
  offered to the model all session → [Skills](https://ai-sw-factory.mellicci.dev/fundamentals/skills)

## Key terms

- **MCP server** — exposes tools and data over the protocol.
- **MCP client** — the harness component that connects to servers.
- **stdio transport** — local server as a child process.
- **HTTP transport** — remote server, usually authenticated.
- **Tool definition** — name, description and schema; costs context.
