Set up Model Context Protocol servers for Claude Code
✓Works with OpenClaudeYou are an MCP (Model Context Protocol) server configuration expert. The user wants to set up and configure MCP servers to extend Claude Code's capabilities with custom tools and resources.
What to check first
- Verify Node.js version is 16+ with
node --version - Check if
@modelcontextprotocol/sdkis available in your project or install it withnpm install @modelcontextprotocol/sdk - Confirm Claude Code supports MCP by checking the
.mcp-server.jsonconfiguration file location in your workspace root
Steps
- Create
.mcp-server.jsonin your project root to define server configurations - Install the MCP SDK package:
npm install @modelcontextprotocol/sdk(if not present) - Build your MCP server file (e.g.,
mcp-server.jsormcp-server.ts) with Tool and Resource handlers - Define
toolsarray with name, description, and inputSchema for each tool you expose - Define
resourcesarray with URI patterns and content handlers if sharing files/data - Add server entry to
.mcp-server.jsonwith command to start your server process - Test the server locally with
node mcp-server.jsand verify it starts without errors - Reload Claude Code or run the MCP server discovery to register tools and resources
Code
// mcp-server.js - Basic MCP Server Setup
const { Server } = require('@modelcontextprotocol/sdk/server');
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio');
const server = new Server({
name: 'my-custom-server',
version: '1.0.0',
});
// Define tools that Claude Code can call
server.setRequestHandler('tools/list', async () => {
return {
tools: [
{
name: 'calculate_sum',
description: 'Adds two numbers together',
inputSchema: {
type: 'object',
properties: {
a: { type: 'number', description: 'First number' },
b: { type: 'number', description: 'Second number' },
},
required: ['a', 'b'],
},
},
{
name: 'fetch_weather',
description: 'Fetches current weather for a location',
inputSchema: {
type: 'object',
properties: {
location: { type: 'string', description: 'City name' },
},
required: ['location'],
},
},
],
};
});
// Implement tool execution handlers
server.setRequestHandler('tools/call', async (request) => {
const { name, arguments: args } = request.params;
if (name === 'calculate_sum') {
return {
content: [
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Claude Code Skills
Other Claude Code skills in the same category — free to download.
CLAUDE.md Writer
Write effective CLAUDE.md project configuration files for Claude Code
Custom Slash Commands
Create custom slash commands for Claude Code workflows
Hooks Configuration
Configure Claude Code hooks for automated pre/post actions
Skills Writer
Write custom Claude Code skill files with proper format
Memory Setup
Configure Claude Code persistent memory system
Permissions Config
Configure Claude Code permission settings and tool access
Agent SDK Setup
Build custom agents with Claude Agent SDK
Context Management
Optimize context window usage in Claude Code conversations
Want a Claude Code skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.