Lesson 25
MCP Integration
AI-generated
MCP Integration
Understand what MCP is and why it matters
Configure MCP servers in Claude Code
Use MCP tools from external services
Access MCP resources (files, databases, APIs)
Know the security considerations of MCP
Model Context Protocol (MCP) is an open standard that lets AI assistants connect to external tools and data sources. With MCP, Claude Code can access databases, APIs, file systems, and services beyond what comes built in.
Think of MCP as a plugin system. Someone builds an MCP server that exposes capabilities. You configure Claude Code to connect to that server. Now Claude has new tools.
This lesson teaches you how to use MCP with Claude Code.
MCP servers can provide three things:
Tools - Actions Claude can take. A Slack MCP server might provide send_message and search_channels tools. A database server might provide query and insert tools.
Resources - Data Claude can read. A file system server provides file contents. A GitHub server provides repository data. Resources appear like files Claude can access.
Prompts - Pre-built instructions. Some MCP servers include prompts that help Claude use the tools effectively.
When you connect an MCP server, its tools appear alongside Claude Code's built-in tools. Claude can use them just like Bash or Edit.
MCP servers are configured in your settings file.
Project-level (recommended):
Create .claude/mcp.json in your project:
User-level:
Add to ~/.claude/settings.json:
Configuration fields:
command - The executable to run
args - Arguments passed to the command
env - Environment variables for the server
cwd - Working directory (optional)
Several MCP servers are widely used:
Filesystem:
Provides file read/write access. Useful for accessing directories outside your project.
PostgreSQL:
Provides SQL query capabilities against your database.
Slack:
Send messages, search channels, read history.
GitHub:
Manage issues, PRs, repositories.
Brave Search:
Web search capabilities.
Once configured, MCP tools appear as available actions. Use them naturally:
Claude invokes the MCP tool just like a built-in tool. You see the tool name and inputs, and can approve or deny.
Listing available tools:
Claude lists the connected servers and their tools.
MCP resources appear as readable content:
Resources provide context without you having to copy-paste data into the conversation.
MCP tools follow the same permission system as built-in tools.
Allow rules:
Deny rules:
In auto mode:
MCP tools are evaluated by the safety classifier just like Bash commands. Risky operations still require approval.
In default mode:
Claude asks before using MCP tools unless you have allow rules.
MCP is an open protocol. You can build custom servers for internal tools.
Basic server structure:
An MCP server is a process that speaks JSON-RPC over stdio. You implement handlers for:
list_tools - Return available tools
call_tool - Execute a tool
list_resources - Return available resources
read_resource - Return resource content
SDKs exist for Python, TypeScript, and other languages to simplify implementation.
Example use cases:
Internal API wrapper
Custom database interface
Proprietary system integration
Company-specific workflow tools
Building custom servers is advanced but powerful for enterprise integration.
MCP servers have significant access. Consider carefully:
Server trust:
Only run MCP servers you trust. A malicious server could expose data or take harmful actions.
Environment variables:
Secrets like API keys go in the MCP config. Keep your settings file private.
Permission rules:
Use deny rules to block dangerous MCP operations:
Network access:
MCP servers may make network requests. Audit what servers connect to.
Scope appropriately:
Use project-level MCP config when possible. Avoid exposing production credentials globally.
Server does not start:
Check that the command exists and is executable:
Tools not appearing:
Restart Claude Code after changing MCP config:
Permission errors:
Check environment variables are set correctly and the server has necessary access.
Debug mode:
Check Claude Code logs for MCP connection errors:
Database exploration:
Cross-system workflow:
External file access:
Research and search:
MCP is an open protocol for connecting AI to external tools
Configure MCP servers in .claude/mcp.json or settings.json
Servers provide tools (actions), resources (data), and prompts
Common servers include filesystem, database, Slack, and GitHub
MCP tools follow the same permission system as built-in tools
Use deny rules to block dangerous operations
Only run trusted MCP servers
Restart Claude Code after changing MCP config
Set up a simple MCP server:
Create .claude/mcp.json in your project:
Create the test directory: mkdir -p /tmp/mcp-test
Add a test file: echo "Hello from MCP" > /tmp/mcp-test/greeting.txt
Start Claude Code in your project.
Ask: what MCP servers are connected?
Ask: read the greeting.txt file from the MCP filesystem
Ask: write a new file called test.txt with any content
Verify the file was created: cat /tmp/mcp-test/test.txt
Delete the MCP config and test directory when done.
This exercise shows MCP server configuration and usage.
https://code.claude.com/docs/en/mcp - Claude Code MCP documentation
https://modelcontextprotocol.io/introduction - MCP protocol specification
https://code.claude.com/docs/en/mcp#using-mcp-servers - Server configuration guide