# Model Context Protocol (MCP): architecture and governance

URL: https://developertoolkit.ai/en/ecosystem/mcp/
Description: How MCP connects Claude Code, Codex, and Cursor to external tools and live data: transport trade-offs, read-only scoping, context cost, and team governance.

Model Context Protocol (MCP) is the open standard stewarded by the Agentic AI Foundation that lets Claude Code, Codex, and Cursor call external tools and read live data—issues, error monitors, browsers, and databases. Because every connected server expands both the prompt-injection surface and context consumption, treat each MCP server as a governed production dependency.

Someone pastes a community MCP snippet into a project README, half the team runs it with write access, nobody audited the publisher, and an agent edits a live customer ticket after reading an untrusted comment. This guide helps **developers** integrate MCP cleanly and equips **tech leads** to govern shared repository servers without blowing the context budget.

## How MCP fits into the agent architecture

An MCP **host** (your coding agent) opens client connections to one or more **servers**, each exposing **tools** (actions), **resources** (data), and **prompts**. Tool names and schemas load into model context so the agent can decide when to invoke them, and every returned payload consumes working context on subsequent turns.

### Choosing transport and integration layer

| Need | Preferred transport or layer | Why |
| --- | --- | --- |
| Hosted SaaS (GitHub, Sentry, Linear, Figma, Cloudflare, PostHog) | **Streamable HTTP** remote server with OAuth | Vendor-maintained auth, zero local secret files, no unmanaged child binaries (avoid legacy HTTP+SSE for new setups) |
| Local database, private filesystem, or internal tooling | **stdio** local process | Keeps local data off external endpoints while honoring local environment isolation |
| Tooling with a fast CLI already on `PATH` (such as `git` or `gh`) | **Direct CLI** over MCP | Zero always-on tool schema overhead and predictable stdout filtering |
| Repeatable engineering procedure without live state | **Agent Skill** (`SKILL.md`) | Loads instructions on demand with no server or credential surface |

### Where project configs live across tools

Project-level MCP configs belong in version control without embedded credentials:

| Agent | Committed project config | Trust and approval posture |
| --- | --- | --- |
| **Claude Code** | `.mcp.json` at repository root | Prompts the developer to approve project servers; supports tool-level `deny` rules in `.claude/settings.json` |
| **Codex** | `.codex/config.toml` (`[mcp_servers.*]`) | Loaded only after the project is explicitly trusted; supports per-server `enabled_tools` and `disabled_tools` |
| **Cursor** | `.cursor/mcp.json` | Managed alongside workspace MCP settings and per-server authentication prompts |

Consult the [Model Context Protocol specification](https://modelcontextprotocol.io) alongside the official [Claude Code](https://code.claude.com/docs), [OpenAI Codex](https://developers.openai.com/codex), and [Cursor](https://cursor.com/docs) documentation for current protocol revisions, OAuth flows, and CLI commands.

## A four-step team workflow for adding MCP servers

A personal config experiment affects one developer. A committed project config executes on every teammate's laptop and CI runner, so it deserves the same review bar as a runtime package.

1. **Verify provenance first.** Confirm the official publisher in the MCP registry and on the vendor's documentation before trusting any URL or package name. Reject typosquatted or abandoned community wrappers when an official hosted Streamable HTTP server exists.

2. **Default strictly to read-only.** Enable the server's own read-only endpoint or flag first (such as read-only URLs or restricted database modes). Where a server lacks a server-side switch, block write tools on the client side via allowlists or `deny` policies.

3. **Commit secret-free project configuration.** Keep `.mcp.json`, `.codex/config.toml`, and `.cursor/mcp.json` completely free of API keys. Prefer per-developer OAuth for remote servers and environment-variable references for local or token-based servers.

4. **Gate config files with `CODEOWNERS`.** Route every MCP configuration pull request through platform engineering or a tech lead who verifies publisher identity, transport, read-only posture, and data reach.

```text
# MCP servers are dependencies: platform owners approve every change
/.mcp.json            @acme/platform-owners
/.codex/config.toml   @acme/platform-owners
/.cursor/mcp.json     @acme/platform-owners
```

## Verifying MCP hygiene, security, and context cost

You do not need to watch every tool invocation to prove an MCP setup matches policy. Four checks produce durable evidence:

- **Resolved config parity:** Inspect what each agent actually resolved (transport, URL, headers, tool filters) and diff it against the reviewed repository file so silently ignored keys surface immediately.
- **Context budget delta:** Measure session context before and after adding a server. Large API surfaces can consume tens of thousands of tokens if schemas are dumped upfront; prefer servers with compact tool sets or dynamic tool search, and trim unused servers aggressively.
- **Automated security & harness checks:** Scan third-party MCP definitions inside an isolated sandbox for tool poisoning and prompt injection, and run `npx @wondelai/harness-audit` (see [the harness audit](/en/harness-audit/)) to catch inline secrets or unsafe MCP configs locally and in CI.
- **Explicit tool-call reporting:** On sensitive workflows, require the agent to list every MCP tool invoked in order; any write call during a read-only audit fails the check automatically.

**Copy-paste prompt: audit connected MCP servers**

```text
List every MCP server connected in this session and every tool each exposes.
Classify each tool as read-only or state-changing (files, tickets, repositories,
databases, cloud resources). Compare against .mcp.json, .codex/config.toml, and
.cursor/mcp.json, flagging: (1) servers absent from committed config, (2) write
tools enabled on servers meant to be read-only, (3) inline credentials, and
(4) servers duplicating a CLI already available on PATH. Output a table plus
recommended removals. Modify nothing.
```

## What breaks when teams connect MCP servers

**Indirect prompt injection through fetched data.** Symptom: an agent reads an external GitHub issue, Sentry log, or web page via MCP and follows attacker-planted instructions. Recovery: enforce read-only server scopes by default, isolate sensitive credentials, and never load a contributor's `.mcp.json` in CI workflows holding secrets (`pull_request_target`, `issue_comment`). See [the agent threat model](/en/org/agent-threat-model/).

**Tool-selection confusion and context starvation.** Symptom: the agent calls the wrong tool or forgets repository instructions mid-session after connecting five overlapping servers. Recovery: remove any server untouched for a week, replace redundant wrappers with direct CLIs, and keep only high-leverage live integrations active.

**Committed project configs silently ignored.** Symptom: a teammate pulls the repository and sees zero project servers. Recovery: confirm the file sits at the exact path expected (`.mcp.json` at repo root for Claude Code, not under `.claude/`), approve project servers in Claude Code, and mark the workspace trusted in Codex.

**Protocol or transport mismatch across tools.** Symptom: a remote server connects in one coding agent and fails in another, or a CLI flag registers a URL as a broken stdio binary. Recovery: verify Streamable HTTP transport declaration explicitly, check protocol version support against each agent's official docs, and confirm resolved config after adding any server.

## Official docs and next steps

For current protocol revisions, server cards, OAuth registration, and agent CLI syntax, consult [modelcontextprotocol.io](https://modelcontextprotocol.io) alongside the [Claude Code](https://code.claude.com/docs), [OpenAI Codex](https://developers.openai.com/codex), and [Cursor](https://cursor.com/docs) documentation.

- [Agent ecosystem overview](/en/ecosystem/) — Decide whether a capability belongs in AGENTS.md, a skill, a hook, MCP, or a plugin.
- [Agent threat model](/en/org/agent-threat-model/) — Model prompt injection, tool poisoning, and blast radius across external connectors.
- [Agent identity and secrets](/en/org/agent-identity-and-secrets/) — Scope credentials and eliminate personal tokens from shared agent workflows.
- [Context windows and budgets](/en/workflows/context/context-windows/) — Understand how tool schemas and returned payloads degrade reasoning depth.
- [Permissions and sandboxing](/en/workflows/harness/permissions-and-sandboxing/) — Combine client deny rules, sandboxes, and managed policies into defense in depth.
- [Harness audit guide](/en/workflows/harness/harness-audit-guide/) — Check repository MCP hygiene and secret boundaries in under two seconds.
