MCP: External Connections
Scope. This lesson is the Claude Code workflow: registering MCP servers in.mcp.jsonor withclaude mcp add, the/mcpcommand, auth patterns, and recipes. For the protocol design (the three primitives, JSON-RPC handshake, transports) and how to author an MCP server that any agent can consume, see MCP: Model Context Protocol (protocol + agent architecture).Product facts change. Server packages, URLs and options move quickly (as of October 2026). Several early reference servers have been archived. Always take the install command from the server's own README, and treat the names below as placeholders for the pattern.
After this lesson, you will be able to:
- Register MCP servers for a project in `.mcp.json`, or with `claude mcp add`, to give Claude Code access to systems such as GitHub, a database or an issue tracker
- Pick the right authentication pattern for a server: OAuth, an API key in the environment, or a token in a header
- Use the `/mcp` command and `claude mcp list` to inspect and debug server connections
- Keep MCP context small, and treat everything a server returns as untrusted input
Before you start
#What MCP Is (in Claude Code)
Concretely: the protocol covers tools, resources, and prompts. In Claude Code you register MCP servers, and Claude calls their tools like any other tool.
Your prompt
↓
Claude Code (orchestrator)
↓
MCP Tool Call (e.g., github.list_issues)
↓
MCP Server (local process, container, or remote HTTP endpoint)
↓
External API (GitHub, a database, an issue tracker, ...)
#Registering MCP Servers
.mcp.json file at the project root, committed to git so the whole team gets the same list. Do not put an mcpServers block in settings.json; that is an old tutorial pattern.{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "<postgres-mcp-package>", "${READ_ONLY_DATABASE_URL}"]
},
"tracker": {
"type": "http",
"url": "https://mcp.example.com/mcp"
}
}
}
You can also add a server from the terminal, and the scope option decides who gets it:
claude mcp add --transport http tracker https://mcp.example.com/mcp
claude mcp add --scope project postgres -- npx -y <postgres-mcp-package>
claude mcp list # servers and their status
Each server is keyed by name. Two common transports:
command+args: a local subprocess (a stdio server)type: "http"+url: a remote server, the usual shape for hosted integrations
A project-scoped server asks for your approval the first time, because running a server means running code. Read what it will run before you approve.
#Popular MCP Servers
| Kind of server | Use For |
|---|---|
| Source control (GitHub, GitLab) | Issues, PRs, repo search |
| Chat (Slack) | Read messages, post to channels |
| Issue trackers (Linear, Jira) | Project management, tickets |
| Docs and knowledge (Notion) | Knowledge base queries |
| Design (Figma) | Design file inspection |
| Databases (Postgres, SQLite) | Direct queries (be careful with permissions) |
| Error tracking (Sentry) | Errors, release queries |
| Payments (Stripe) | Payment data (read-only recommended) |
| Search | Web search through a search API |
Availability, package names and URLs change, so find current ones in each vendor's documentation or in the MCP server registry, and check the maintainer. Only install servers you trust.
#Authentication Patterns
| Pattern | Use For | Example |
|---|---|---|
| OAuth flow | Interactive user login | Hosted servers: sign in through the browser from /mcp |
| API key in env | Personal or team use, simple | A token in an environment variable |
| Pre-configured creds | Automation, CI/CD | Token supplied as a CI secret |
| Token in a header | Remote servers that take a bearer token | A header value read from an environment variable |
For sensitive credentials (production DB connection strings, payment API keys), prefer:
- Environment variable references such as
${DATABASE_URL}in.mcp.json - Personal
.envfiles loaded into the server's process - Secret managers (1Password CLI, AWS Secrets Manager) integrated via env
NEVER commit raw credentials to a file that is tracked in git.
#The /mcp Command
> /mcp
Opens a list of your MCP servers and their status, and lets you sign in to servers that use OAuth (illustrative output):
✓ github (connected) 18 tools
✓ postgres (connected) 7 tools
⚠ tracker (needs auth) Sign in from this menu
✗ chat (failed to start) Check the command and its logs
claude mcp list shows the same servers, claude mcp get <name> shows one server's configuration, and claude mcp remove <name> removes it. Menu options differ between versions, so /help and the MCP docs are the source of truth.#Keeping MCP Context Small
Every MCP tool has a name, a description and a schema, and those take up space in the model's context. A server with dozens of tools can use a lot of it before you have typed anything. To keep it small:
- Connect only the servers a project needs, and remove the ones you stopped using
- Prefer servers that expose a handful of well-described tools over servers that expose everything
- Recent versions can load tool definitions on demand instead of all up front; check the MCP documentation for how your version does it (as of October 2026)
Fewer, better tools also means Claude picks the right one more often.
#Connection Health and Startup
Claude Code connects to your servers when a session starts. If one is slow or broken, the others should still work, but you should confirm it.
- Run
/mcpafter startup and check that every server you expect is connected - A server that fails to start usually has a wrong command, a missing environment variable, or an expired sign-in
- Test a server on its own first (
claude mcp list) before you blame the model
#Common MCP Recipes
#Query Postgres for analysis
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "<postgres-mcp-package>", "${READ_ONLY_DATABASE_URL}"]
}
}
}
Then:
> Using the postgres server, query the top 10 users by signup count last week.
Note: use a READ-ONLY role for safety. Never give Claude write access to production databases.
#File issues from code review
{
"mcpServers": {
"tracker": {
"type": "http",
"url": "https://mcp.example.com/mcp"
}
}
}
Then:
> I just reviewed the auth module and found 3 issues. File them as tickets in the security project.
#Slack notifications on PR open
Combine MCP and a hook. The hook script runs a short non-interactive Claude call that is allowed to use only the Slack tool:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [{ "type": "command", "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/announce-pr.sh" }]
}
]
}
}
#!/usr/bin/env bash
# .claude/hooks/announce-pr.sh: runs after any Bash command, acts only on gh pr create
cmd=$(jq -r '.tool_input.command // empty')
case "$cmd" in
*"gh pr create"*)
claude -p "Use the slack tool to post to #engineering that a PR was opened in $(basename "$PWD")." \
--allowedTools "mcp__slack" >/dev/null 2>&1 ;;
esac
exit 0
mcp__<server>__<tool>, and you can allow a whole server with mcp__<server>.#Key Takeaways
- MCP is Claude Code's tool ecosystem. Register servers in
.mcp.json(shared) or withclaude mcp add, and Claude calls their tools like any other - Auth via environment variables (
${API_KEY}); never hardcode in committed files /mcpandclaude mcp listare your first stop when something stops working- Keep context small: connect only the servers you need
- A server is code you run and its output is untrusted text. Check the maintainer, scope the credential, and read-only by default
#Quick Check
You want Claude Code to query your production DB to analyze user signup trends. Best setup?
You want Claude Code to read tickets from an issue tracker AND post status updates to Slack. Which side of the conversation do MCP servers sit on?
A teammate sets up a Postgres MCP server and points it at the production `DATABASE_URL`. What's the right policy?