Claude Code MCP Server Setup and Practical Use Cases
Claude Code MCP Server Setup and Practical Use Cases. A practical guide with code examples.
What Is MCP?
MCP (Model Context Protocol) is an open protocol for connecting AI assistants to external tools and data sources. Claude Code acts as an MCP client, enabling it to interact with databases, APIs, and various services through MCP servers.
Configuring MCP Servers
MCP server settings go in .claude/settings.json or ~/.claude/settings.json:
{
"mcpServers": {
"server-name": {
"command": "executable-command",
"args": ["arg1", "arg2"],
"env": {
"ENV_VAR": "value"
}
}
}
}
You can also add servers via the CLI:
claude mcp add server-name -- command arg1 arg2
Example 1: Database Integration
Set up an MCP server to run queries directly against PostgreSQL:
claude mcp add postgres-server -- npx -y @modelcontextprotocol/server-postgres postgresql://user:pass@localhost:5432/mydb
Once configured, you can query your database from within a Claude Code session:
> Count the new user registrations from the past week in the users table
> Show the daily trend in a table format
Claude Code automatically generates and executes SQL queries, then formats the results for you.
Example 2: GitHub Integration
The GitHub MCP server lets you manage issues and PRs directly from Claude Code:
claude mcp add github -- npx -y @modelcontextprotocol/server-github
Set up the token via environment variables:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx"
}
}
}
}
Here’s what you can do:
> List all open issues in the repository
> Look at Issue #42, create a fix branch, and implement the solution
> Once the fix is done, create a PR
Example 3: Filesystem Extension
An MCP server that provides safe access to a specific directory:
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem /path/to/allowed/directory
Example 4: Web Scraping
The Puppeteer MCP server enables web page fetching and interaction:
claude mcp add puppeteer -- npx -y @modelcontextprotocol/server-puppeteer
> Read the API documentation at https://example.com/api/docs
> and create a client library for that API
Example 5: Slack Integration
The Slack MCP server lets you read messages from channels and send notifications:
{
"mcpServers": {
"slack": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-slack"],
"env": {
"SLACK_BOT_TOKEN": "xoxb-xxxxxxxxxxxx"
}
}
}
}
> Check the latest messages in #dev
> Post today's progress update to #daily-report
Managing MCP Servers
List Registered Servers
claude mcp list
Remove a Server
claude mcp remove server-name
Setting the Scope
You can specify the configuration scope for MCP servers:
# Project-local (default)
claude mcp add --scope project db-server -- command
# User-global
claude mcp add --scope user db-server -- command
Building a Custom MCP Server
You can also create project-specific tools as custom MCP servers:
// my-mcp-server.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({
name: "my-project-tools",
version: "1.0.0",
});
// Define a custom tool
server.tool(
"deploy-staging",
"Deploy to the staging environment",
{ branch: z.string().describe("Branch name to deploy") },
async ({ branch }) => {
// Deployment logic
return {
content: [{ type: "text", text: `Deployed ${branch} to staging` }],
};
}
);
const transport = new StdioServerTransport();
await server.connect(transport);
Register it like this:
claude mcp add my-tools -- npx tsx my-mcp-server.ts
Security Considerations
1. Credential Management
Tokens and passwords in MCP server configs should be managed through environment variables or .env files. Never commit them to Git.
2. Limit Access Scope
Follow the principle of least privilege — for example, use a read-only database user for your database MCP server.
3. Use Local Settings
Store configs containing credentials in .claude/settings.local.json and add it to .gitignore.
Conclusion
MCP servers let you extend Claude Code’s capabilities across your entire project ecosystem. From database queries to GitHub workflows to Slack notifications, you can use Claude Code as the central hub of your development workflow. Start with the official MCP servers, then build custom ones as needed.
Free PDF: Claude Code Cheatsheet in 5 Minutes
Just enter your email and we'll send you the single-page A4 cheatsheet right away.
We handle your data with care and never send spam.
Level up your Claude Code workflow
50 battle-tested prompt templates you can copy-paste into Claude Code right now.
About the Author
Masa
Engineer obsessed with Claude Code. Runs claudecode-lab.com, a 10-language tech media with 2,000+ pages.
Related Posts
Safe Agent Harness Design for Claude Code and Codex: Permissions, Checks, and Rollback
Build a practical agent harness for Claude Code and Codex with policy, planning, verification, and recovery layers.
10 Powerful Subagent Patterns for Claude Code
Master Claude Code's subagent feature with 10 practical patterns. Learn how to use parallel processing, specialization, and context isolation to double your development speed.
Getting Started with Claude Code Agent SDK — Build Autonomous Agents Fast
Learn how to build autonomous AI agents with Claude Code Agent SDK. Covers setup, tool definitions, and multi-step execution with practical code examples.
Related Products
The Complete Claude Code Setup & Configuration Guide
From install to team-ready workflow.
A practical guide to installation, CLAUDE.md, hooks, MCP servers, permissions, IDE setup, and CI/CD workflows.
50 Battle-Tested Claude Code Prompt Templates
Copy, paste, ship. 50 production-ready prompts.
Use proven prompts for code review, refactoring, testing, documentation, debugging, architecture, and incident response.