Configures Model Context Protocol (MCP) servers for Claude Code, including transport types (stdio, SSE, HTTP), scope levels (user/project), and server capabilities (prompts, resources, tools). Use when integrating external tools, data sources, or workflows with Claude.
Complete guide for configuring Model Context Protocol (MCP) servers to extend Claude Code with external tools, data sources, and workflows.
Model Context Protocol (MCP) is an open standard for connecting AI applications to external systems. Think of it as "USB-C for AI" - a universal connector that enables Claude to access:
graph LR
A[Claude Code Client] --> B{MCP Protocol}
B --> C[Filesystem Server]
B --> D[GitHub Server]
B --> E[Slack Server]
B --> F[Custom Server]
C --> G[Local Files]
D --> H[GitHub API]
E --> I[Slack API]
F --> J[Your Service]
MCP Server (Provider):
MCP Client (Consumer):
Use case: Local command-line tools and scripts
{
"mcpServers": {
"filesystem": {
"command": "node",
"args": ["./build/index.js"],
"env": {}
}
}
}
Characteristics:
Best for:
Use case: HTTP-based streaming connections
{
"mcpServers": {
"remote-api": {
"url": "https://api.example.com/mcp",
"transport": "sse",
"headers": {
"Authorization": "Bearer ${API_TOKEN}"
}
}
}
}
Characteristics:
Best for:
Use case: RESTful API integrations
{
"mcpServers": {
"rest-api": {
"url": "https://api.example.com/mcp",
"transport": "http",
"headers": {
"X-API-Key": "${API_KEY}"
}
}
}
}
Characteristics:
Best for:
Location: ~/.config/claude/mcp.json (macOS/Linux) or %APPDATA%\claude\mcp.json (Windows)
{
"mcpServers": {
"github": {
"command": "uvx",
"args": ["mcp-server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx"
}
},
"google-calendar": {
"command": "node",
"args": ["./servers/calendar/index.js"],
"env": {
"GOOGLE_CLIENT_ID": "xxx",
"GOOGLE_CLIENT_SECRET": "xxx"
}
}
}
}
Use when:
Location: .mcp/config.json (project root)
{
"mcpServers": {
"project-db": {
"command": "npx",
"args": ["@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "${DATABASE_URL}"
}
},
"figma": {
"command": "node",
"args": ["./mcp/figma-server.js"],
"env": {
"FIGMA_ACCESS_TOKEN": "${FIGMA_TOKEN}"
}
}
}
}
Use when:
Purpose: Reusable prompt templates and workflows
// MCP Server exposes prompts
{
prompts: [
{
name: "code-review",
description: "Comprehensive code review workflow",
arguments: [
{ name: "file_path", required: true },
{ name: "focus_areas", required: false }
]
}
]
}
Use cases:
Purpose: Access to external data sources
// MCP Server exposes resources
{
resources: [
{
uri: "file:///project/src/**/*.ts",
name: "TypeScript Source Files",
mimeType: "text/typescript"
},
{
uri: "db://postgres/users",
name: "User Database",
mimeType: "application/json"
}
]
}
Use cases:
Purpose: Callable functions and operations
// MCP Server exposes tools
{
tools: [
{
name: "search_codebase",
description: "Search across project files",
parameters: {
query: { type: "string", required: true },
file_pattern: { type: "string", required: false }
}
}
]
}
Use cases:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory"],
"env": {}
}
}
}
Capabilities: Read/write local files, list directories, search content
{
"mcpServers": {
"github": {
"command": "uvx",
"args": ["mcp-server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
}
}
}
}
Capabilities: Search repositories, read files, create issues, manage PRs
{
"mcpServers": {
"slack": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-slack"],
"env": {
"SLACK_BOT_TOKEN": "${SLACK_BOT_TOKEN}",
"SLACK_TEAM_ID": "${SLACK_TEAM_ID}"
}
}
}
}
Capabilities: Send messages, read channels, search conversations
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "postgresql://user:pass@localhost:5432/db"
}
}
}
}
Capabilities: Query tables, analyze schema, execute SQL
{
"mcpServers": {
"gdrive": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-gdrive"],
"env": {
"GOOGLE_CLIENT_ID": "${GOOGLE_CLIENT_ID}",
"GOOGLE_CLIENT_SECRET": "${GOOGLE_CLIENT_SECRET}"
}
}
}
}
Capabilities: Read documents, search files, manage folders
Use environment variables for sensitive data:
{
"mcpServers": {
"api-service": {
"command": "node",
"args": ["./server.js"],
"env": {
"API_KEY": "${API_KEY}",
"API_SECRET": "${API_SECRET}"
}
}
}
}
Best practices:
${VAR_NAME} syntax for substitution.env file (gitignored).env (project root):
# MCP Server Credentials
GITHUB_TOKEN=ghp_xxxxxxxxxxxxx
SLACK_BOT_TOKEN=xoxb-xxxxxxxxxxxxx
DATABASE_URL=postgresql://localhost:5432/mydb
FIGMA_TOKEN=figd_xxxxxxxxxxxxx
API_KEY=xxxxxxxxxxxxx
Load in shell (before running Claude Code):
export $(cat .env | xargs)
claude
// my-mcp-server.ts
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server(
{
name: "my-custom-server",
version: "1.0.0",
},
{
capabilities: {
tools: {},
resources: {},
prompts: {},
},
}
);
// Register tools
server.setRequestHandler("tools/list", async () => ({
tools: [
{
name: "custom_operation",
description: "Performs custom operation",
inputSchema: {
type: "object",
properties: {
input: { type: "string" },
},
},
},
],
}));
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "custom_operation") {
const result = performOperation(request.params.arguments.input);
return { result };
}
});
// Start server
const transport = new StdioServerTransport();
await server.connect(transport);
{
"mcpServers": {
"my-server": {
"command": "node",
"args": ["./my-mcp-server.js"],
"env": {}
}
}
}
| Server | Purpose | Transport |
|---|---|---|
@modelcontextprotocol/server-filesystem | File access | stdio |
@modelcontextprotocol/server-github | GitHub API | stdio |
@modelcontextprotocol/server-slack | Slack integration | stdio |
@modelcontextprotocol/server-postgres | PostgreSQL | stdio |
@modelcontextprotocol/server-gdrive | Google Drive | stdio |
{
"mcpServers": {
// Group by category
// Version Control
"github": { "command": "uvx", "args": ["mcp-server-github"] },
// Communication
"slack": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-slack"] },
// Data Sources
"postgres": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-postgres"] },
"filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem"] }
}
}
// Custom server with proper error handling
server.setRequestHandler("tools/call", async (request) => {
try {
const result = await performOperation(request.params.arguments);
return { result };
} catch (error) {
return {
error: {
code: "OPERATION_FAILED",
message: error.message,
},
};
}
});
Issue: Server not connecting
# Check server is installed
npx @modelcontextprotocol/server-filesystem --version
# Test server directly
echo '{"jsonrpc":"2.0","id":1,"method":"initialize"}' | npx @modelcontextprotocol/server-filesystem /tmp
Issue: Environment variables not loading
// Verify variable is set
{
"command": "sh",
"args": ["-c", "echo $GITHUB_TOKEN && node server.js"]
}
Issue: Permission denied
# Check file permissions
chmod +x ./my-mcp-server.js
# Verify allowed directories
# Filesystem server only accesses specified paths
Enable verbose logging:
{
"mcpServers": {
"debug-server": {
"command": "node",
"args": ["--inspect", "./server.js"],
"env": {
"DEBUG": "mcp:*"
}
}
}
}
For detailed information on:
resources/mcp-architecture.mdresources/popular-servers.mdscripts/test-mcp-connection.jsscripts/mcp-config-template.json