MCP Servers
Table of Contents
1. Introduction
Model Context Protocol (MCP) servers extend Claude Code with external tools and capabilities beyond the built-in functionality. MCP provides a standardized way for Claude to interact with external systems.
1.1. What MCP Servers Provide
- File system access - Read/write files with specific permissions
- API integrations - Connect to external services
- Database connections - Query and manipulate data
- Development tools - IDE integration, build systems, testing frameworks
- External services - Web search, documentation lookup, code analysis
1.2. Configuration Locations
1.2.1. Project Scope (.mcp.json)
Located at project root, version-controlled, shared with team.
Use for:
- Servers needed by the project
- Team-shared integrations
- Project-specific tools
1.2.2. User Scope (~/.claude.json)
Located in home directory, personal, not version-controlled.
Use for:
- Personal tools and preferences
- API keys and credentials
- Experimental servers
1.3. Server Types
1.3.1. stdio (Standard Input/Output)
Process-based communication:
{
"type": "stdio",
"command": "/path/to/executable",
"args": ["arg1", "arg2"]
}
Most common type, works with any language that can read stdin/write stdout.
1.3.2. SSE (Server-Sent Events)
HTTP streaming:
{
"type": "sse",
"url": "https://api.example.com/mcp"
}
For cloud-hosted MCP servers.
1.3.3. HTTP
Traditional HTTP requests:
{
"type": "http",
"url": "https://api.example.com/mcp"
}
For REST-style MCP servers.
2. Project MCP Servers
Configuration for team-shared MCP servers in this project.
Important: Update the paths below to match your actual MCP server locations before tangling.
2.1. Full Configuration
{
"mcpServers": {
"emacs": {
"type": "stdio",
"command": "/path/to/mcp-emacs/venv/bin/python",
"args": [
"/path/to/mcp-emacs/src/mcp_emacs/server.py"
],
"env": {}
},
"filesystem": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/kyeongsoo/Projects/mandoo180.github.io"
]
}
}
}
2.2. Customization Instructions
Before tangling, edit the paths:
- Emacs MCP Server:
command: Path to Python in your mcp-emacs virtualenvargs[0]: Path to your mcp-emacs server.py
- Filesystem Server:
args[2]: Path to your project root (already set correctly)
2.3. Server Descriptions
2.3.1. Emacs MCP Server
Provides deep Emacs integration for context-aware coding assistance.
Installation:
# Clone the MCP Emacs server git clone https://github.com/your-org/mcp-emacs.git cd mcp-emacs # Create virtual environment and install python -m venv venv source venv/bin/activate pip install -e . # Start Emacs daemon if not already running emacs --daemon
Configuration:
Update the paths in .mcp.json above to point to:
- Your mcp-emacs installation directory
- The Python executable in the venv
- The server.py script path
Capabilities:
Buffer Operations:
get_buffer_content- Read buffer contentslist_buffers- List all open buffersopen_file- Open files in Emacsget_current_context- Get cursor position and context
LSP Integration:
lsp_hover- Get documentation at cursorlsp_diagnostics- Get errors and warningslsp_completion- Get code completionslsp_definition- Jump to definitionslsp_references- Find all referenceslsp_rename- Rename symbolslsp_format- Format codelsp_code_actions- Get available fixeslsp_document_symbols- Get file outlinelsp_workspace_symbols- Search for symbols
Project Management:
list_projects- List known projectsget_current_project- Get active projectswitch_project- Switch to different project
Org-Mode:
org_agenda_todos- Get TODO items from agendaorg_capture- Create capture entriesorg_get_file_todos- Get TODOs from specific file
File Proposals:
propose_file_change- Propose edits with ediff reviewapply_proposed_change- Apply after reviewreject_proposed_change- Reject and clean up
Compilation:
compile_project- Run build commandget_compilation_errors- Get structured error listrecompile- Re-run last compilationkill_compilation- Stop running compilation
Use Cases:
- Context-aware code explanations (knows your cursor position)
- Emacs-specific assistance (knows your config, buffers, projects)
- LSP-powered refactoring (rename, format, fix)
- Org file management (capture TODOs, manage agenda)
- Safe file editing with ediff review
2.3.2. Filesystem Server
Provides safe filesystem access restricted to the project directory.
Installation: No installation needed - uses npx to run on-demand.
Configuration: The server is restricted to the project root directory specified in args[2].
Capabilities:
- Read files within allowed paths
- Write files with proper permissions
- List directory contents
- Get file metadata (size, modified time, etc.)
- Safe operations (can't escape allowed paths)
Security:
- Access restricted to specified directory
- No access outside project root
- Safe for team sharing in version control
- Prevents accidental system file access
Use Cases:
- Project-scoped file operations
- Safe file manipulation
- Directory traversal within project
- Metadata queries
Configuration:
Update args[2] to your project's absolute path. The current value is already set for this project.
3. User MCP Servers (Examples)
These configurations would go in ~/.claude.json for personal use. They are not tangled by default - add them manually if desired.
3.1. User Configuration Structure
User MCP servers go in ~/.claude.json:
{
"mcpServers": {
"server-name": {
"type": "stdio",
"command": "command",
"args": ["args"]
}
}
}
3.2. Popular MCP Servers
3.2.1. GitHub
Interact with GitHub repositories, PRs, and issues.
{
"github": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_TOKEN": "your-token-here"
}
}
}
Capabilities:
- List and search repositories
- Create and manage issues
- Review and comment on pull requests
- Search code across repositories
- Manage branches and commits
Setup:
- Create GitHub personal access token
- Set
GITHUB_TOKENenvironment variable - Add to
~/.claude.json
3.2.2. Perplexity
Web research and real-time information.
{
"perplexity": {
"type": "sse",
"url": "https://api.perplexity.ai/mcp",
"env": {
"PERPLEXITY_API_KEY": "your-key-here"
}
}
}
Capabilities:
- Web search with citations
- Up-to-date information
- Technical documentation lookup
- Research assistance
3.2.3. Sequential Thinking
Enhanced reasoning and problem-solving.
{
"sequential-thinking": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sequential-thinking"
]
}
}
Capabilities:
- Break down complex problems
- Step-by-step reasoning
- Structured problem solving
- Task decomposition
3.2.4. Context7
Access to up-to-date technical documentation.
{
"context7": {
"type": "sse",
"url": "https://api.context7.com/mcp",
"env": {
"CONTEXT7_API_KEY": "your-key-here"
}
}
}
Capabilities:
- Latest framework documentation
- API references
- Package documentation
- Version-specific docs
3.2.5. Brave Search
Privacy-focused web search.
{
"brave-search": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-brave-search"
],
"env": {
"BRAVE_API_KEY": "your-key-here"
}
}
}
Capabilities:
- Web search
- News search
- Image search
- Video search
3.2.6. PostgreSQL
Database access and queries.
{
"postgres": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres"
],
"env": {
"POSTGRES_CONNECTION_STRING": "postgresql://user:pass@localhost:5432/dbname"
}
}
}
Capabilities:
- Execute SQL queries
- Inspect database schema
- Manage tables and data
- Database introspection
Security: Only use in personal config, never commit credentials.
4. Adding New MCP Servers
4.1. Via CLI
Claude Code provides commands to add MCP servers:
# Add stdio server claude mcp add myserver npx -y @scope/server-name arg1 arg2 # Add SSE server claude mcp add --transport sse myserver https://api.example.com/mcp # Add HTTP server claude mcp add --transport http myserver https://api.example.com/mcp
4.2. Manual Configuration
- Edit configuration file:
- Project:
.mcp.json - User:
~/.claude.json
- Project:
Add server entry:
{ "mcpServers": { "existing-server": { ... }, "new-server": { "type": "stdio", "command": "/path/to/command", "args": ["arg1", "arg2"], "env": { "VAR": "value" } } } }- Restart Claude Code or reload project
- Enable server in settings if
enableAllProjectMcpServersisfalse
4.3. Finding MCP Servers
- MCP Server Directory (mcpcat.io)
- MCP GitHub Organization
- NPM MCP Packages
- Community forums and discussions
5. Server Development
Want to create a custom MCP server? Here's the process.
5.1. MCP Protocol Overview
MCP uses JSON-RPC 2.0 over stdio, SSE, or HTTP:
- Client (Claude Code) sends request
- Server processes and responds
- Protocol handles bidirectional communication
5.2. Creating a Server
5.2.1. 1. Choose Transport
- stdio: Best for local tools, any language
- SSE: For cloud-hosted servers
- HTTP: For REST-style services
5.2.2. 2. Implement Protocol
Minimal server structure:
from mcp.server import Server, NotificationOptions
from mcp.server.models import InitializationOptions
import mcp.server.stdio
import mcp.types as types
# Create server
server = Server("my-server")
# Define capabilities
@server.list_tools()
async def list_tools() -> list[types.Tool]:
return [
types.Tool(
name="my_tool",
description="What this tool does",
inputSchema={
"type": "object",
"properties": {
"param": {"type": "string"}
}
}
)
]
@server.call_tool()
async def call_tool(name: str, arguments: dict) -> list[types.TextContent]:
if name == "my_tool":
result = do_something(arguments["param"])
return [types.TextContent(type="text", text=result)]
# Run server
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="my-server",
server_version="1.0.0"
)
)
5.2.3. 3. Define Tools
Each tool needs:
- name: Unique identifier
- description: When/how to use it
- inputSchema: JSON Schema for parameters
- handler: Function that executes the tool
5.2.4. 4. Test Locally
# Test stdio server echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | python server.py # Should respond with tool list
5.2.5. 5. Package and Distribute
- Python: PyPI package
- Node: NPM package
- Other: Docker image or binary
5.3. MCP SDK Libraries
Official SDKs:
- Python:
pip install mcp - TypeScript:
npm install @modelcontextprotocol/sdk
Community SDKs:
- Go, Rust, Java, and more
6. Troubleshooting
6.1. MCP Server Not Working
Symptom: MCP tools not available or server fails to start
Solutions:
- Verify paths: Check paths in
.mcp.jsonare correct and absolute - Test command: Run the command manually in terminal
- Check logs: Look at Claude Code logs for error messages
- Verify runtime: Ensure Python/Node/etc is available
- Check permissions: Ensure files are executable (
chmod +x) - Restart: Restart Claude Code after config changes
6.2. Server Starts But Tools Don't Work
Symptom: Server connects but tools fail or give errors
Solutions:
- Check tool implementation: Verify tool handler works
- Validate input: Ensure arguments match inputSchema
- Test independently: Run server and send test requests
- Check dependencies: Verify all required packages installed
- Review logs: Check both server and Claude Code logs
6.3. Permission Denied Errors
Symptom: Server can't access files or resources
Solutions:
- Filesystem scope: Check allowed paths in filesystem server config
- File permissions: Verify files are readable/writable
- Environment variables: Ensure credentials are set
- API keys: Check API keys are valid and have correct permissions
6.4. Server Connection Timeout
Symptom: Server takes too long to start or respond
Solutions:
- Check server startup: Ensure server starts quickly
- Network issues: For SSE/HTTP servers, check network connectivity
- Resource constraints: Server might be resource-heavy
- Increase timeout: Adjust timeout settings if available
6.5. Multiple Servers Conflict
Symptom: Tools with same name from different servers
Solutions:
- Rename tools: Use prefixes (
github_search,local_search) - Disable servers: Disable conflicting servers selectively
- Namespace tools: Update server to namespace tool names
7. Security Considerations
7.1. Principle of Least Privilege
- Grant minimum necessary access
- Restrict filesystem to project directory
- Use read-only access when possible
- Isolate sensitive operations
7.2. Credential Management
- Never commit API keys to
.mcp.json - Use environment variables for secrets
- Store credentials in
~/.claude.json(user-level) - Rotate keys regularly
7.3. Code Execution Risks
MCP servers execute code:
- Review server code before using
- Trust official servers
- Be cautious with community servers
- Sandbox when possible
7.4. Network Security
For SSE/HTTP servers:
- Use HTTPS only
- Validate certificates
- Be aware of data transmission
- Consider VPN for sensitive data
8. Best Practices
8.1. Project vs User Servers
Project (.mcp.json):
- Essential project tools
- Safe for version control
- No credentials
- Team-shared functionality
User (~/.claude.json):
- Personal preferences
- Servers with credentials
- Experimental servers
- User-specific tools
8.2. Documentation
For each server, document:
- What it does
- How to install
- Required credentials
- Security considerations
- Example usage
8.3. Testing
Before committing project MCP config:
- Test on your machine
- Test with team members
- Verify cross-platform compatibility
- Document setup steps
8.4. Maintenance
- Keep servers updated
- Monitor for security issues
- Remove unused servers
- Review permissions regularly
9. Related Configuration
- Settings - Enable/disable MCP servers
- Slash Commands - Commands can use MCP tools
- Agent Skills - Skills can use MCP tools