How to Integrate Custom Tools into Claude Code with MCP Server in 5 Minutes¶
Target Audience
- Intermediate engineers looking to integrate custom tools with Claude Code
Key Points¶
- Launch an MCP server locally
- Call custom tools from Claude Code
- Integrate tools into existing workflows
Why This Matters Now¶
Since Claude Code 2.0, Model Context Protocol (MCP) support has standardized external tool integration. However, official documentation lacks concrete implementation steps, leaving many developers struggling with integration. This article presents a minimal working MCP server implementation.
Implementation Steps Overview¶
| Step | Content | Success Metric |
|---|---|---|
| 1 | Implement MCP server | Server starts successfully |
| 2 | Add Claude configuration | Tool recognized |
| 3 | Verify operation | Tool executes successfully |
Step 1: Implement Minimal MCP Server¶
Implement a minimal MCP server in TypeScript. Using @modelcontextprotocol/sdk, you can build a working server in just 10 lines.
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
const server = new Server({
name: 'my-tool',
version: '1.0.0',
}, { capabilities: { tools: {} } });
server.setRequestHandler('tools/list', async () => ({
tools: [{
name: 'echo',
description: 'Echo input text',
inputSchema: { type: 'object', properties: { text: { type: 'string' } } }
}]
}));
server.setRequestHandler('tools/call', async (request) => {
const { name, arguments: args } = request.params;
if (name === 'echo') return { content: [{ type: 'text', text: `Echo: ${args.text}` }] };
});
await server.connect(new StdioServerTransport());
Step 2: Update Claude Configuration¶
Register the MCP server in ~/.claude/claude_desktop_config.json. This configuration allows Claude Code to auto-start the server.
{
"mcpServers": {
"my-tool": {
"command": "node",
"args": ["/path/to/mcp-server.js"],
"env": {}
}
}
}
Step 3: Verify Execution from Claude Code¶
After restarting Claude Code, the new tool becomes available. Type /tools in the prompt to see the echo tool listed.
# Verification command
echo "test" | claude code --tool echo
Common Pitfalls and Solutions¶
| Symptom | Cause | Immediate Solution |
|---|---|---|
| Tool not displayed | Config file path error | Use absolute path |
| Server startup error | Node.js not installed | Install v20+ |
| Connection timeout | Port conflict | Use StdioTransport |