Loading...
Master MCP server development from scratch. Create custom Claude Desktop integrations with TypeScript/Python in 60 minutes using production-ready patterns.
What you'll achieve: Create your first MCP server connecting Claude to external systems. Deploy production-ready integrations with proper security, testing, and state management.
MCP functions as a universal integration standard for AI applications. Think of it as USB-C for AI systems. Anthropic launched MCP in November 2024 to solve integration complexity. The protocol standardizes how Claude connects with tools, databases, and APIs. This eliminates the need for custom integrations per platform.
The protocol implements a client-host-server architecture efficiently. Claude Desktop acts as the host coordinating connections. Each server maintains a 1:1 relationship with clients. This design ensures security boundaries remain intact. Transport mechanisms evolved from stdio to Streamable HTTP in March 2025.
MCP servers expose three primary abstractions to AI. Tools are executable functions requiring human approval before execution. Resources provide contextual data through URI-identified content. Prompts offer reusable templates standardizing common workflows. Each component serves specific integration purposes effectively.
JSON-RPC 2.0 forms the protocol's messaging foundation. This enables language-agnostic implementations with readable debugging. The MCP ecosystem is growing rapidly with community contributions.
# TypeScript Setup
npm init -y
npm install @modelcontextprotocol/sdk@1.18.1
npm install zod typescript tsx --save-dev
# Python Setup
pip install mcp fastmcp pydantic --break-system-packages
pip install python-dotenv pytest --break-system-packages
// src/index.ts - TypeScript Server
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: "custom-integration-server",
version: "1.0.0",
capabilities: {
tools: true,
resources: true,
prompts: true
}
});
// Python equivalent: src/server.py
from mcp.server.fastmcp import FastMCP
from pydantic import Field
mcp = FastMCP("Custom Integration Server")
// TypeScript Tool Implementation
server.tool("database_query",
{
description: "Execute parameterized database queries safely",
inputSchema: {
query: z.string().min(1).max(1000),
params: z.array(z.any()).optional()
}
},
async ({ query, params }) => {
// Validate and sanitize inputs
const sanitized = parameterize(query, params);
// Execute with connection pooling
const result = await pool.query(sanitized);
return {
content: [{
type: "text",
text: JSON.stringify(result.rows, null, 2)
}]
};
}
);
// Redis State Management
import Redis from 'ioredis';
const redis = new Redis({
host: process.env.REDIS_HOST,
port: 6379,
maxRetriesPerRequest: 3
});
// Session middleware
server.use(async (context, next) => {
const sessionId = context.headers['x-session-id'];
context.state = await redis.get(sessionId) || {};
await next();
await redis.setex(sessionId, 3600,
JSON.stringify(context.state));
});
// OAuth 2.1 Implementation with PKCE
import { generateCodeChallenge } from './auth';
server.tool("authenticate",
{
description: "Initiate OAuth flow with PKCE",
inputSchema: {
client_id: z.string(),
scope: z.string()
}
},
async ({ client_id, scope }) => {
const verifier = generateRandomString(128);
const challenge = await generateCodeChallenge(verifier);
// Store verifier securely
await storeVerifier(verifier);
const authUrl = buildAuthUrl({
client_id,
challenge,
challenge_method: 'S256',
scope
});
return {
content: [{
type: "text",
text: `Authenticate at: ${authUrl}`
}]
};
}
);
// ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"custom-integration": {
"command": "node",
"args": ["/absolute/path/to/dist/index.js"],
"env": {
"DATABASE_URL": "${DATABASE_URL}",
"REDIS_HOST": "localhost",
"API_KEY": "${API_KEY}"
}
}
}
}
# Launch MCP Inspector
npx @modelcontextprotocol/inspector node dist/index.js
# Test specific tools
curl -X POST http://localhost:5173/test \
-H "Content-Type: application/json" \
-d '{"tool": "database_query", "params": {...}}'
# Monitor real-time messages
# Inspector UI shows all JSON-RPC communication
Database servers require connection pooling and query optimization. Postgres MCP Pro demonstrates production patterns effectively. Connection pools maintain 10-50 concurrent connections typically. Query analysis prevents expensive operations automatically. Schema introspection enables intelligent query generation consistently.
Health monitoring checks connection status every 30 seconds. Automatic reconnection handles network interruptions gracefully. Transaction support ensures data consistency across operations. These patterns apply to MongoDB, MySQL, and other databases. Production deployments handle thousands of queries hourly reliably.
API servers implement rate limiting and retry logic. GitHub's server manages 80+ tools with authentication. Rate limiting uses token bucket algorithms effectively. Each tool respects API quotas preventing service disruption. Exponential backoff handles temporary failures automatically.
GraphQL servers demonstrate efficient data fetching strategies. Schema introspection maps operations to MCP tools. Batching reduces round trips improving performance significantly. Caching layers decrease API calls by 70% typically. These optimizations enable responsive AI interactions consistently.
Enterprise servers prioritize security and compliance requirements. Coinbase AgentKit demonstrates secure wallet management patterns. Multi-factor authentication protects sensitive operations effectively. Audit logging tracks all tool invocations comprehensively. Role-based access control limits tool availability appropriately.
Cloudflare maintains 10+ specialized servers demonstrating scalability. Each server handles specific domain responsibilities clearly. Load balancing distributes requests across server instances. Monitoring dashboards track performance metrics continuously. These patterns support thousands of concurrent users reliably.
Optimize server response times targeting sub-100ms latency. Implement caching reducing database queries by 60%. Use connection pooling maintaining persistent connections efficiently. Index database queries improving lookup speeds dramatically. Profile code identifying bottlenecks using performance tools.
Batch operations when processing multiple requests simultaneously. Stream large responses preventing memory exhaustion issues. Implement pagination for resource-heavy operations appropriately. These optimizations improve user experience significantly. Production servers achieve 50ms average response times.
Monitor memory usage preventing gradual degradation patterns. Implement garbage collection triggers during idle periods. Clear unused cache entries using LRU eviction policies. Limit concurrent operations preventing memory spikes occurring. Profile heap usage identifying memory leak sources.
Set maximum payload sizes preventing oversized requests. Implement circuit breakers protecting against cascading failures. Use worker threads for CPU-intensive operations effectively. These strategies maintain stable performance consistently. Production deployments handle 10,000+ daily requests reliably.
Deploy servers using containerization ensuring consistency everywhere. Docker images package dependencies eliminating version conflicts. Kubernetes orchestrates scaling based on load automatically. Health checks ensure only healthy instances receive traffic. Rolling updates enable zero-downtime deployments consistently.
Serverless deployments reduce operational overhead significantly. AWS Lambda handles scaling automatically without management. Cloudflare Workers provide edge computing reducing latency. Azure Functions integrate with enterprise systems seamlessly. Choose architecture matching your scaling requirements appropriately.
Implement comprehensive logging capturing all significant events. Structure logs using JSON enabling efficient querying. Include correlation IDs tracking requests across systems. Monitor error rates identifying issues before escalation. Alert on anomalies requiring immediate attention promptly.
Track custom metrics measuring business-specific outcomes effectively. Response times indicate user experience quality directly. Tool usage patterns reveal feature adoption rates. Error distributions highlight problematic code paths clearly. Dashboards visualize trends enabling proactive optimization continuously.
GitHub's official MCP server demonstrates comprehensive API integration. The server exposes 80+ tools covering repository management. Authentication uses OAuth with fine-grained permissions. Rate limiting respects GitHub's API quotas automatically. Caching reduces API calls improving response times.
Repository operations include creation, cloning, and management. Issue tracking tools enable workflow automation effectively. Pull request tools streamline code review processes. Webhook integration enables real-time event processing. This server handles enterprise-scale operations reliably.
Postgres MCP Pro showcases advanced database integration patterns. Connection pooling maintains optimal resource utilization continuously. Query optimization prevents expensive operations automatically. Transaction support ensures data consistency properly. Health monitoring detects issues proactively.
The server supports full CRUD operations comprehensively. Schema introspection enables intelligent query generation. Prepared statements prevent SQL injection attacks. Streaming supports large result sets efficiently. Production deployments handle millions of queries daily.
Slack's MCP server enables sophisticated workflow automation. Message posting respects channel permissions appropriately. Thread management maintains conversation context effectively. File sharing handles attachments securely. User mention resolution works across workspaces.
Workflow triggers respond to specific events automatically. Approval flows route requests requiring authorization. Notification systems alert relevant team members promptly. Analytics track automation effectiveness measuring ROI. These capabilities transform team productivity significantly.
Implement cross-cutting concerns using middleware patterns effectively. Authentication middleware validates tokens before processing. Logging middleware captures request/response pairs comprehensively. Rate limiting middleware prevents abuse protecting resources. Error handling middleware standardizes error responses consistently.
Chain middleware functions creating processing pipelines efficiently. Order matters when composing middleware stacks. Early termination prevents unnecessary processing occurring. Context passing enables data sharing between layers. These patterns improve code maintainability significantly.
Enable real-time feedback during long operations effectively. Server-Sent Events provide unidirectional streaming simply. WebSocket connections enable bidirectional communication when needed. Chunked transfer encoding streams HTTP responses progressively. Choose appropriate mechanism based on requirements.
Implement progress indicators keeping users informed continuously. Stream partial results as processing completes incrementally. Handle connection interruptions gracefully resuming automatically. Buffer management prevents memory exhaustion occurring. These techniques improve perceived performance dramatically.
Essential commands and configurations for MCP server development
Install MCP SDK with current stable version 1.18.1
Install Python MCP with FastMCP framework v1.2.0+
Debug servers with visual testing interface
Claude Desktop configuration file location
Available transport mechanisms - use http for remote
Target latency for optimal user experience
Continue learning with these related tutorials and guides
Implement enterprise-grade security for MCP servers. Master OAuth flows, token management, and audit logging in production environments.
View ResourceComprehensive testing approaches for MCP servers. Learn unit, integration, and load testing techniques ensuring reliability.
View ResourceBuild production database connectors with MCP. Connect Postgres, MongoDB, and MySQL with proper pooling and optimization.
View ResourceLearn how to deploy MCP at scale with custom server implementations.
View ResourceDiagnose and fix common MCP performance issues. Memory leaks, slow responses, and connection problems solved.
View ResourceUnderstand MCP protocol internals completely. JSON-RPC implementation details and transport mechanism comparisons.
View ResourceNew guides are being added regularly.
Check back soon for trending content and recent updates!