Model Context Protocol (MCP) enables Claude Code plugins to integrate with external services and APIs by providing structured tool access. Use MCP integration to expose external service capabilities as tools within Claude Code.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/anthropics/claude-code/llms.txt
Use this file to discover all available pages before exploring further.
What is MCP?
MCP allows you to:- Connect to external services (databases, APIs, file systems)
- Provide 10+ related tools from a single service
- Handle OAuth and complex authentication flows
- Bundle MCP servers with plugins for automatic setup
Configuration Methods
Plugins can bundle MCP servers in two ways:Method 1: Dedicated .mcp.json (Recommended)
Create.mcp.json at plugin root:
- Clear separation of concerns
- Easier to maintain
- Better for multiple servers
Method 2: Inline in plugin.json
AddmcpServers field to plugin.json:
- Single configuration file
- Good for simple single-server plugins
MCP Server Types
stdio (Local Process)
Execute local MCP servers as child processes. Best for local tools and custom servers. Configuration:- File system access
- Local database connections
- Custom MCP servers
- NPM-packaged MCP servers
- Claude Code spawns and manages the process
- Communicates via stdin/stdout
- Terminates when Claude Code exits
SSE (Server-Sent Events)
Connect to hosted MCP servers with OAuth support. Best for cloud services. Configuration:- Official hosted MCP servers (Asana, GitHub, etc.)
- Cloud services with MCP endpoints
- OAuth-based authentication
- No local installation needed
- OAuth flows handled automatically
- User prompted on first use
- Tokens managed by Claude Code
HTTP (REST API)
Connect to RESTful MCP servers with token authentication. Configuration:- REST API-based MCP servers
- Token-based authentication
- Custom API backends
- Stateless interactions
WebSocket (Real-time)
Connect to WebSocket MCP servers for real-time bidirectional communication. Configuration:- Real-time data streams
- Bidirectional communication
- Push notifications
- Live updates
Environment Variables
$
Use for portable paths to bundled servers:User Environment Variables
Access user’s environment variables:.env file:
Using MCP Tools
In Commands
Reference MCP tools in command files:In Agents
List MCP tools in agent tools array:MCP tool names are automatically available when the MCP server is configured.
Example Configurations
File System MCP Server
.mcp.json:
read_filewrite_filelist_directorycreate_directorydelete_file
PostgreSQL MCP Server
.mcp.json:
queryschematablesdescribe_table
GitHub MCP Server
.mcp.json:
create_issuelist_prscreate_prmerge_prget_filecommit_changes
Custom API Server
.mcp.json:
Custom MCP Servers
Creating a Custom Server
Bundle a custom MCP server with your plugin: Directory structure:servers/custom-server.js):
Authentication Patterns
OAuth (SSE Servers)
Handled automatically by Claude Code:Token-Based (HTTP Servers)
User provides token via environment variable:.env:
API Key (Query Parameter)
Best Practices
Use Portable Paths
Always use $ for server paths
Environment Variables
Never hardcode credentials, use $ syntax
Dedicated Config
Use .mcp.json for cleaner separation
Document Tools
List available MCP tools in plugin README
Security Considerations
- Least privilege: Grant minimum necessary permissions
- Input validation: Validate all user inputs before passing to MCP tools
- Secure credentials: Use environment variables, never hardcode
- HTTPS/WSS: Use secure protocols for network servers
- Audit logs: Log MCP server operations for security review
Troubleshooting
Server Not Starting
Issue: MCP server fails to start Solutions:- Check command path with $
- Verify server binary exists and is executable
- Check environment variables are set
- Review server logs:
claude --debug
Tools Not Available
Issue: MCP tools don’t appear Solutions:- Verify server started successfully
- Check server name matches configuration
- Ensure server exposes tools correctly
- Restart Claude Code session
Authentication Failures
Issue: OAuth or token authentication fails Solutions:- For OAuth: Clear cached credentials and re-authenticate
- For tokens: Verify $ is set correctly
- Check token hasn’t expired
- Review authentication headers
Connection Timeouts
Issue: Network MCP servers timeout Solutions:- Check network connectivity
- Verify URL is correct and accessible
- Increase timeout if needed
- Check firewall settings
Next Steps
MCP SDK Docs
Learn more about MCP protocol and creating servers
Example Servers
Browse official MCP server implementations