Claude Tools

Mastering MCP Servers for Claude: Building Custom Tools and Scaling Deployments

Supercharge Claude with custom MCP servers: build domain-specific tools, secure them like a pro, and scale for enterprise. Dive into this hands-on guide! (118 chars)

J

Jennifer Yu

Workflow Automation Specialist

December 11, 2025 min read
Share:

Why MCP Servers Are a Game-Changer for Claude Users

Hey there, Claude enthusiasts! If you're knee-deep in the Anthropic ecosystem—whether you're a dev wielding the Claude API, a business user automating workflows, or just tinkering with AI agents—you've probably hit Claude's limits on out-of-the-box capabilities. Enter Model Context Protocol (MCP) servers: the secret sauce for extending Claude with custom, domain-specific tools. Think real-time database queries, proprietary API integrations, or even niche calculations that Claude couldn't dream of without help.

In this post, we'll master MCP from scratch. We'll build a simple server, amp it up with custom tools, lock it down securely, and deploy it at scale. Along the way, I'll compare approaches (like naive vs. production-ready setups) to help you pick the right path. By the end, you'll have actionable code to plug into your Claude projects. Let's roll!

MCP 101: How It Fits into the Claude Ecosystem

MCP servers act as intermediaries between Claude and your external resources. Claude's tool use (via the Messages API) sends structured requests over HTTP/WebSockets, and your MCP server responds with context or actions. It's more flexible than basic tool calls because MCP handles stateful interactions, caching, and complex workflows.

Quick Comparison: MCP vs. Standard Claude Tools

FeatureStandard Tool CallsMCP Servers
SetupPrompt-defined functionsDedicated server with full control
StateStateless per callPersistent sessions, caching
ScalabilityAPI-limitedHorizontal scaling, custom logic
Use CasesSimple math/APIsEnterprise integrations, agents
OverheadLowMedium (but worth it)

MCP shines for Claude Opus/Sonnet in agentic flows, like chaining tools in n8n or custom Slack bots.

Building Your First MCP Server: A Node.js Quickstart

Let's start simple. We'll use Node.js with Express for a basic MCP endpoint that echoes requests (perfect for testing Claude's tool integration).

Prerequisites

  • Node.js 18+
  • Claude API key (from console.anthropic.com)

Install deps:

npm init -y
npm install express cors @anthropic-ai/sdk

Here's the core server (server.js):

import express from 'express';
import cors from 'cors';
import { Anthropic } from '@anthropic-ai/sdk';

const app = express();
app.use(cors());
app.use(express.json());

const PORT = process.env.PORT || 3000;

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

// MCP endpoint: Handles Claude's context requests
app.post('/mcp/context', async (req, res) => {
  const { sessionId, query, tools } = req.body;
  
  // Simulate a custom tool: e.g., 'weather' tool
  if (query.includes('weather')) {
    const mockData = { temperature: 72, condition: 'sunny' };
    res.json({ context: mockData, sessionId });
    return;
  }
  
  res.json({ context: 'No matching tool found', sessionId });
});

app.listen(PORT, () => {
  console.log(`MCP Server running on port ${PORT}`);
});

Run it: node server.js. Test with curl:

curl -X POST http://localhost:3000/mcp/context \
  -H "Content-Type: application/json" \
  -d '{"sessionId":"test","query":"What's the weather?"}'

Now, integrate with Claude. Prompt Claude to use your server:

from anthropic import Anthropic

client = Anthropic()

message = client.messages.create(
  model="claude-3-5-sonnet-20240620",
  max_tokens=1024,
  tools=[{
    "name": "get_context",
    "description": "Fetch context from MCP server",
    "input_schema": {
      "type": "object",
      "properties": {
        "query": {"type": "string"}
      }
    }
  }],
  messages=[{"role": "user", "content": "Get weather via MCP."}]
)
print(message.content)

Comparison: Vanilla Express vs. Fastify

  • Express: Beginner-friendly, huge ecosystem.
  • Fastify: 2x faster for high-throughput MCP (swap in 5 mins).

Boom—your first MCP tool! (Word count so far: ~450)

Crafting Custom Tools: From Basic to Domain-Specific

Time to level up. Custom tools make MCP Claude's superpower. Let's build three: a SQL query tool for engineering teams, an API fetcher for marketing, and a sentiment analyzer for HR.

1. SQL Query Tool (Engineering Playbook)

Securely query your DB without exposing creds to Claude.

Extend server.js:

// Add to tools array in prompt, but server-side:
app.post('/mcp/tools/sql-query', async (req, res) => {
  const { query, sessionId } = req.body;
  
  // Use a safe query lib like postgres.js
  const { sql } = await import('postgres');
  const db = sql`postgres://user:pass@localhost/mydb`;
  
  try {
    const results = await db`SELECT * FROM users WHERE ${sql(query)}`;
    res.json({ results, sessionId });
  } catch (e) {
    res.status(400).json({ error: 'Invalid query' });
  }
});

Pro Tip: Parameterize queries to prevent injection—Claude's XML tools help here.

2. External API Tool (Marketing/Sales)

Pull real-time data from Stripe or HubSpot.

app.post('/mcp/tools/api-fetch', async (req, res) => {
  const { url, method = 'GET', headers, body, sessionId } = req.body;
  
  const response = await fetch(url, { method, headers, body });
  const data = await response.json();
  res.json({ data, sessionId });
});

3. Sentiment Tool (HR Playbook)

Analyze feedback with a lightweight model.

// npm install compromise

import nlp from 'compromise';

app.post('/mcp/tools/sentiment', (req, res) => {
  const { text, sessionId } = req.body;
  const doc = nlp(text);
  const sentiment = doc.sentences().conjugations().out('array'); // Simplified
  res.json({ sentiment: 'positive', score: 0.8, sessionId });
});

Comparison: In-Prompt Tools vs. MCP Custom Tools

ScenarioIn-PromptMCP
Simple Calc✅ Fast❌ Overkill
Secure DB❌ Risky✅ Isolated
Stateful Agent⚠️ Token waste✅ Efficient

These tools slot perfectly into Claude agents or Zapier/Make integrations.

Securing Your MCP Server: Don't Skip This!

Security first—or regret later. MCP exposes your server to Claude's API calls.

Best Practices

  • Auth: Use API keys or JWT. Add middleware:
app.use((req, res, next) => {
  const token = req.headers.authorization?.split(' ')[1];
  if (token !== process.env.MCP_SECRET) {
    return res.status(401).json({ error: 'Unauthorized' });
  }
  next();
});
  • Rate Limiting: npm install express-rate-limit
const limiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 100 });
app.use('/mcp/', limiter);
  • Input Validation: Use Zod/Joi for schemas.
  • HTTPS Only: Enforce in prod.
  • Secrets: Env vars + Doppler/Vault.

Comparison: Basic vs. Enterprise Security

  • Basic: API key + CORS.
  • Enterprise: OAuth2, WAF (Cloudflare), audit logs.

Scaling Deployments: Local to Kubernetes

Solo dev? Dockerize. Team? Kubernetes.

Option 1: Docker + Vercel/Render (Easy Scale)

Dockerfile:

FROM node:18-alpine
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "server.js"]
EXPOSE 3000

Deploy: vercel --prod (serverless, auto-scales).

Option 2: AWS Lambda (Cost-Effective)

Use serverless framework for FaaS.

Option 3: Kubernetes (Enterprise)

For high-traffic agents:

# k8s-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mcp-server
spec:
  replicas: 3
  template:
    spec:
      containers:
      - name: mcp
        image: yourrepo/mcp:latest
        ports:
        - containerPort: 3000
        env:
        - name: ANTHROPIC_API_KEY
          valueFrom:
            secretKeyRef:
              name: claude-secrets
              key: api-key

apiVersion: v1
kind: Service
metadata:
  name: mcp-service
spec:
  ports:
  - port: 80
    targetPort: 3000
  selector:
    app: mcp-server

kubectl apply -f k8s-deployment.yaml

Comparison: Deployment Options

PlatformCostScaleEase
VercelLowAuto⭐⭐⭐⭐⭐
AWS LambdaPay-per-useEvent-driven⭐⭐⭐⭐
K8sHigherInfinite⭐⭐⭐

Monitor with Prometheus/Grafana for Claude traffic spikes.

Real-World Example: HR Playbook with MCP

Imagine an HR agent: Claude analyzes resumes via MCP sentiment + SQL for matches.

Prompt snippet:

<tool_use>
  <name>sql-query</name>
  <input>SELECT * FROM candidates WHERE skills LIKE '%Python%'</input>
</tool_use>
<tool_use>
  <name>sentiment</name>
  <input>{"text": "Loves team collab!"}</input>
</tool_use>

Claude chains them seamlessly. Deploy via n8n for workflows.

Wrapping Up: Your MCP Journey Starts Now

You've got the blueprint: build, secure, deploy. MCP turns Claude into a custom powerhouse—far beyond stock models like GPT or Gemini. Start with the Node.js example, tweak for your domain (sales leads? Legal docs?), and scale as needed.

Questions? Drop 'em in the comments. Check claudedirectory.com for more Claude tools, prompts, and API guides. Happy building!

(Total words: 1428)

The #1 Newsletter in AI

Stay ahead of the AI curve

The most important updates, news, and content — delivered in one weekly newsletter.

No spam. Unsubscribe anytime. Privacy policy

MCP Servers
Claude Tools
Custom Tools
Claude Extensions
Deployment
ai-agents
J

About Jennifer Yu

Workflow Automation Specialist

Jennifer covers workflow strategy, no-code platforms, and clear implementation guidance for teams adopting automation.

Comments (0)