Claude Code MCP Integration Guide: Connecting Your Agent to Any Tool or API
Claude Code MCP Integration Guide: Connecting Your Agent to Any Tool or API
TL;DR: MCP (Model Context Protocol) lets Claude Code connect to databases, APIs, file systems, and custom tools through a standardized server interface. Setting Server interface. Setting up your first MCP server takes about 15 minutes and unlocks Claude Code's ability to query live data, run searches, and interact with services beyond your local filesystem.
What Is MCP and Why Does It Matter for Claude Code?
Anthropic officially introduced the Model Context Protocol in November 2024 as an open standard. The official MCP documentation provides a complete reference for server architecture, client integration, and protocol specification across SDKs in Python, TypeScript, Java, and Go.
MCP (Model Context Protocol) is an open standard developed by Anthropic that defines how AI agents discover and interact with external tools, data sources, and APIs. Think of it as the USB-C for AI tooling — one protocol that any MCP-compatible client (Claude Code, Claude Desktop, Cursor, etc.) can use to connect to any MCP-compatible server.
Claude Code uses MCP tools for: - Querying databases (PostgreSQL, SQLite, vector stores) during coding sessions - Searching codebases beyond the current file context (semantic search, grep) - Running shell commands with structured output - Accessing external APIs (GitHub, Jira, PagerDuty) without manual credential management - Reading and writing files with explicit permission boundaries
If you've been using Claude Code without MCP, you're limited to its built-in capabilities — which are powerful, but can't access your database schema, query your production logs, or search your documentation.
Your First MCP Server: Creating a Custom MCP Server for Claude Code
The simplest way to add MCP capabilities is to create a custom server. Here's a minimal Python MCP server that adds database query and web search tools:
class="language-python"># mcp_server.py from mcp.server import Server, NotificationOptions from mcp.server.models import InitializationOptions import mcp.server.stdio import mcp.types as types import sqlite3, json, urllib.requestserver = Server(“claude-code-tools”)
@server.list_tools() async def handle_list_tools() -> list[types.Tool]: return [ types.Tool( name=“query_database”, description=“Run SQL queries against the project database”, inputSchema={ “type”: “object”, “properties”: { “query”: {“type”: “string”, “description”: “SQL query to execute”} }, “required”: [“query”] } ), types.Tool( name=“search_web”, description=“Search the web for current information”, inputSchema={ “type”: “object”, “properties”: { “q”: {“type”: “string”, “description”: “Search query”} }, “required”: [“q”] } ) ]
@server.call_tool() async def handle_call_tool(name: str, arguments: dict) -> list[types.TextContent]: if name == “query_database”: db”: db_path = arguments.get(“db_path”, “data.db”) conn = sqlite3.connect(db_path) result = conn.execute(arguments[“query”]).fetchall() conn.close() return [types.TextContent(type=“text”, text=json.dumps(result, default=str))]
elif name == “search_web”: query = urllib.parse.quote(arguments[“q”]) url = f”https://api.duckduckgo.com/?q={query}&format=json” with urllib.request.urlopen(url) as response: data = json.loads(response.read()) return [types.TextContent(type=“text”, text=json.dumps(data, indent=2))]
async def main(): async with mcp.server.stdio.stdio_server() as (read_stream, write_stream): await server.run( read_stream, write_stream, InitializationOptions( server_name=“claude-code-tools”, server_version=“0version”0.1.0”, capabilities=server.get_capabilities( notification_options=NotificationOptions(), experimental_capabilities={} ) ) )
if name == “main”: import asyncio asyncio.run(main())
The import namespacing above uses mcp from the modelcontextprotocol pip package. Install it with:
class="language-bash">pip install modelcontextprotocol
Configuring Claude Code to Use Your MCP Server
Claude Code reads MCP servers from .claude/mcp.json in your project root (you can also configure globally in ~/.claude/mcp.json):
class="language-json">{
"mcpServersver": {
""claude
"command": "python",
"args": ["mcp_server.py"],
"env": {}
},
"github": {
"command": "npx",
"args": ["-y", "@anthropic/mcp-server-github"],
"env": {
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
}
},
"filesystem": {
"command": "npx",
"args": ["-y", "@anthropic/mcp-server-filesystem", "/path/to/project"]
}
}
}
Once configured, Claude Code auto-discovers these servers on startup. When you prompt it with a task that could benefit from a tool, it asks for permission before calling the MCP tool.
Pre-Built MCP Servers
You don't have to build everything from scratch. Anthropic and the community maintain a growing ecosystem:
| Server | What It Does | Install |
|---|---|---|
| GitHub | PRs, issues, code search, reviews | npx -y @anthropic/mcp-server-github |
| Filesystem | Read/write files with path restrictions | npx -y @anthropic/mcp-server-filesystem |
| PostgreSQL | Query databases with schema introspection | npx -y @anthropic/mcp-server-postgres |
| Puppeteer | Browser automation, screenshots, web scraping | npx -y @anthropic/mcp-server-puppeteer |
| Memory | Persistent knowledge graph across sessions | npx -y @anthropic/mcp-server-memory |
| Brave Search | Web and local search via Brave API | npx -y @anthropic/mcp-server-brave-search |
For a deeper look at how evaluation platforms like Braintrust integrate with tools like MCP, check out our Braintrust review.
Real Workflow: Debugging a Production Issue with MCP
Anthropic has also demonstrated code execution via MCP as a paradigm where agents write and run code to load tools on demand, filter data before it reaches the model, and execute complex logic in a single step — cutting context usage significantly.
Here's a concrete example showing the power of multiple MCP servers working together:
- Claude Code detects a bug in your React component
- It queries PostgreSQL (via MCP) to check if the underlying data looks correct
- It searches GitHub (via MCP) for recent PRs that touched this component
- It reads the relevant log files (via Filesystem MCP)
- It suggests a fix and runs the test suite
All of this happens in one session, with Claude Code autonomously switching between tools as needed. Without MCP, you'd be context-switching between a terminal, database client, browser, and IDE — copy-pasting results back to Claude Code manually.
What This Means for You
MCP isn't just about technical capability — it fundamentally changes how you work with AI coding agents. Here's what to do about it:
- Start with one MCP server this week. Pick the most painful manual task in your daily workflow — database queries, log inspection, or documentation search — and build a custom MCP server for it. The 15-minute setup from this guide gets you from zero to a working tool. Once you see how it changes Claude Code's usefulness, you'll want more.
- Check your MCP server security boundaries before connecting production data. Claude Code sends tool call context to Anthropic's API. If your MCP server accesses production databases, configure it to return aggregated or redacted results. Use environment variables for credentials — never hardcode tokens in mcp.json files that could be committed to version control.
- Invest in orchestration over individual model quality. MCP lets Claude Code orchestrate multiple tools in a single session — database, GitHub, filesystem, web search. The value of your agent setup grows with the number of tools it can coordinate, not with which foundation model you choose. Build your MCP tool ecosystem first, optimize model selection second.
For a deeper look at evaluating multi-agent systems that use MCP, see the official MCP documentation and Anthropic's engineering blog on code execution via MCP.
Security Considerations
MCP servers run locally on your machine, not in Anthropic's cloud. Claude Code sends tool call requests to your local MCP server process, which executes them and returns results. This means:
- Your credentials, tokens, and secrets stay on your machine (environment variables passed to MCP servers)
- Claude Code never sees raw credentials — only the results of tool calls
- You control which directories a filesystem server can access
- Each MCP server can have its own permission model
However, Claude Code does send the context necessary for the tool call (e.g., "what's the name of the database you need to query?") to Anthropic's API. If you're working with PII or proprietary data, configure MCP servers to return redacted or sampled results.
FAQ
Do I need to install anything special special to use MCP with Claude Code?
MCP support is built into Claude Code v0.2.0+. You just need the MCP server processes configured in .claude/mcp.json.
Can I run multiple MCP servers simultaneously? Yes. Claude Code discovers and uses all configured MCP servers. It picks the right tool based on the context.
Are MCP servers running continuously? Claude Code only? No — MCP is an open protocol. Any MCP-compatible client (Claude Desktop, Cursor, VS Code extensions) can use the same servers.
What happens if an MCP server crashes? Claude Code catches the error, reports the failure, and continues without that tool. The other MCP servers remain available.
Can I share MCP servers across a team?
Yes. The .claude/mcp.json file can be checked into version control. Environment variables for sensitive config (tokens, DB credentials) should be set per-developer.
Quick Start Checklist
- Install the MCP SDK: Run
pip install modelcontextprotocolto get the Python SDK. See the official MCP documentation for setup guides in Python, TypeScript, Java, and Go. - Register MCP servers in
.claude/mcp.json: Start with the community MCP server repository for ready-made PostgreSQL, GitHub, and Filesystem servers. - Test with a real workflow: Pick a routine task (database query, code review, documentation search) and verify Claude Code discovers and uses your MCP tools within your first session.
- Add security boundaries: Configure filesystem path restrictions and environment-variable-based credentials for each MCP server. Review the Anthropic engineering blog on code execution via MCP for security best practices.
The Bottom Line
MCP transforms Claude Code from a file-reading AI into a fully tooled development agent. The 15-minute setup to add a database or GitHub server pays for itself the first time Claude Code diagnoses a production bug by querying your database, reading error logs, and checking recent deploys — all in one session.
With Anthropic doubling down on MCP infrastructure (today's Stainless acquisition signals exactly this), the ecosystem will only get richer. Build your MCP servers now while the protocol is stabilizing, and you'll have a durable advantage when enterprise MCP adoption accelerates.
For more on debugging AI agents that use tools like MCP, see our AI debugging guide and evaluation pipeline build log.
← Back to all posts