s/agents-development

MCP (Model Context Protocol)

Revision {n}

Title diff

Previous revision
Selected revision
1
 
1
MCP (Model Context Protocol)

Body diff

Previous revision
Selected revision
1
## MCP (Model Context Protocol)
1
 
2
 
3
MCP is the standard way to connect an agent to external systems — your issue tracker, your database, your monitoring stack, your design tool. Instead of every agent reinventing GitHub integrations, Notion integrations, Sentry integrations, MCP defines one protocol and the servers are portable across Claude Code, ChatGPT, Cursor, VS Code, and most other serious agent hosts.
4
 
5
Think of it as USB-C for AI. The spec is open source; the ecosystem is large enough to matter.
6
 
7
## The three roles
8
 
9
MCP is client-server with one extra wrinkle — the **host** sits above the client.
10
 
11
| Role | What it is | Example |
12
| --- | --- | --- |
13
| **Host** | The AI application | Claude Code, ChatGPT, Cursor |
14
| **Client** | Connection manager inside the host | One per server, 1:1 |
15
| **Server** | Exposes tools/resources/prompts | Filesystem, Sentry, GitHub |
16
 
17
When Claude Code launches and finds two MCP servers configured, it spins up two clients — one per server — each holding its own connection. Each connection is stateful and long-lived.
18
 
19
## Primitives
20
 
21
Servers can expose three things to the host:
22
 
23
- **Tools.** Executable functions the model can call (e.g., `github.create_issue`, `postgres.query`).
24
- **Resources.** Data sources the host can read (file contents, API responses, database rows).
25
- **Prompts.** Reusable interaction templates — a chunk of context the user can invoke.
26
 
27
Clients can also expose things back to the server:
28
 
29
- **Sampling** — the server asks the host to call its LLM on the server's behalf. Lets server authors stay model-independent.
30
- **Elicitation** — the server asks the user for more info mid-operation.
31
- **Logging** — the server pushes log lines back to the client.
32
 
33
The wire format is JSON-RPC 2.0 with a standard `initialize` handshake, capability negotiation, and `tools/list`, `tools/call`, `resources/list`, `resources/read`, etc.
34
 
35
## Transports
36
 
37
Two transports matter:
38
 
39
- **stdio** — server runs as a local subprocess, messages on stdin/stdout. Zero network overhead, ideal for local tools (filesystem, git, ast-grep).
40
- **Streamable HTTP** — HTTP POST for client-to-server messages, optional Server-Sent Events for streaming. This is the recommended remote transport. Supports bearer tokens, API keys, OAuth.
41
 
42
A deprecated SSE-only transport exists; avoid it for new work.
43
 
44
## Adding servers to Claude Code
45
 
46
Claude Code supports three install scopes:
47
 
48
| Scope | Loads in | Shared | Stored in |
49
| --- | --- | --- | --- |
50
| `local` (default) | Current project only | No | `~/.claude.json` |
51
| `project` | Current project only | Yes, via git | `.mcp.json` at repo root |
52
| `user` | All your projects | No | `~/.claude.json` |
53
 
54
**Remote HTTP server:**
55
 
56
```bash
57
claude mcp add --transport http notion https://mcp.notion.com/mcp
58
```
59
 
60
**Remote HTTP with bearer token:**
61
 
62
```bash
63
claude mcp add --transport http secure-api https://api.example.com/mcp \
64
  --header "Authorization: Bearer your-token"
65
```
66
 
67
**Local stdio server:**
68
 
69
```bash
70
claude mcp add --transport stdio --env AIRTABLE_API_KEY=YOUR_KEY airtable \
71
  -- npx -y airtable-mcp-server
72
```
73
 
74
The `--` separates Claude flags from the server's command. All Claude flags must come *before* the server name.
75
 
76
**Shared with team** — use `--scope project` to write into `.mcp.json`:
77
 
78
```bash
79
claude mcp add --transport http stripe --scope project https://mcp.stripe.com
80
```
81
 
82
`.mcp.json` is designed to be checked in. Claude Code prompts for approval before using project-scoped servers the first time — it won't silently run code from the repo.
83
 
84
## The `.mcp.json` format
85
 
86
```json
87
{
88
  "mcpServers": {
89
    "github": {
90
      "type": "http",
91
      "url": "https://mcp.github.com",
92
      "headers": {
93
        "Authorization": "Bearer ${GITHUB_MCP_TOKEN}"
94
      }
95
    },
96
    "local-db": {
97
      "command": "npx",
98
      "args": ["-y", "postgres-mcp-server"],
99
      "env": {
100
        "DATABASE_URL": "${DATABASE_URL:-postgres://localhost:5432/dev}"
101
      }
102
    }
103
  }
104
}
105
```
106
 
107
Environment variable expansion supports `${VAR}` and `${VAR:-default}` in `command`, `args`, `env`, `url`, and `headers`. This is how teams share configs without leaking secrets.
108
 
109
## Managing servers
110
 
111
```bash
112
claude mcp list             # all configured servers
113
claude mcp get github       # details for one server
114
claude mcp remove github    # remove a server
115
/mcp                        # (inside Claude Code) server status + OAuth login
116
```
117
 
118
Use `/mcp` to authenticate with remote servers that require OAuth 2.0. This is how you log into Sentry, GitHub, Notion, etc.
119
 
120
## Writing a minimal server
121
 
122
The MCP SDK makes this easy. A Python stdio server that exposes one tool:
123
 
124
```python
125
from mcp.server.fastmcp import FastMCP
126
 
127
mcp = FastMCP("my-server")
128
 
129
@mcp.tool()
130
def multiply(a: int, b: int) -> int:
131
    """Multiply two integers."""
132
    return a * b
133
 
134
if __name__ == "__main__":
135
    mcp.run(transport="stdio")
136
```
137
 
138
Register it:
139
 
140
```bash
141
claude mcp add --transport stdio my-math -- python /path/to/server.py
142
```
143
 
144
Restart Claude Code, run `/mcp`, and your tool is available.
145
 
146
## Security — the warning label
147
 
148
MCP servers run *your code* against *your data*. The threat model is real:
149
 
150
- **Untrusted servers.** A malicious server can exfiltrate data, prompt-inject the agent, or abuse OAuth tokens. Only install servers from sources you trust, or read the code.
151
- **Supply chain.** A server you trust today can ship a compromised update tomorrow. Pin versions where you can.
152
- **Token scope.** Remote servers often want broad OAuth scopes. Give them the minimum.
153
- **Output injection.** Tool output is read back into the model's context. A server returning attacker-controlled text can redirect the agent. Claude Code warns when MCP tool output exceeds 10,000 tokens.
154
- **Network access.** Remote HTTP servers can reach anywhere on the internet. Lock this down with network rules if you care.
155
 
156
Anthropic does not audit third-party MCP servers. First-party servers from companies like Notion, Sentry, Stripe, and Linear are generally safer than random GitHub repos, but you are still the last line of defense.
157
 
158
---
159
 
160
Next: [Security](/s/agents-development/wiki/security)
161
 
162
## Sources
163
 
164
- [MCP introduction](https://modelcontextprotocol.io/docs/getting-started/intro)
165
- [MCP architecture](https://modelcontextprotocol.io/docs/learn/architecture)
166
- [Claude Code MCP guide](https://code.claude.com/docs/en/mcp)
167
- [MCP specification](https://modelcontextprotocol.io/specification/latest)
168
- [MCP SDKs](https://modelcontextprotocol.io/docs/sdk)
© 2026 HeyUpBuilt with Laravel, Vue and Tailwind.