Build MCP Server: Complete Guide from Zero to Earning
TL;DR: Build an MCP server from scratch using Python + FastMCP for rapid development or TypeScript for production apps. This complete MCP development guide covers testing, deployment, and monetization. Top servers earn $500-2,000/month on MCPize.
The MCP ecosystem exploded in 2025. Over 6,800 servers now exist. Companies like OpenAI, Google, and Microsoft adopted the protocol. And developers who got in early are earning real money — some pulling $500-2,000/month from a single well-designed server.
This isn't hype. It's what happens when you create an MCP server that solves a real problem.
This MCP server tutorial takes you from zero to a published, monetizable server. Not just code that runs locally — a real product that earns revenue. Whether you choose Python or TypeScript, by the end you'll have built an MCP server from scratch that's tested, deployed, and ready for users.
What makes this guide different:
- Both Python AND TypeScript paths (most guides cover only one)
- Real deployment, not just "run locally"
- Actual monetization strategies with examples
- Based on patterns from successful production servers
Why Build MCP Servers Now?#
The timing matters. Here's what the data shows:
| Metric | Value |
|---|---|
| Total MCP servers | 6,800+ |
| Companies using MCP | OpenAI, Google, Microsoft, Anthropic |
| Cloud deployment adoption | 70%+ |
| Efficiency improvement reported | 75% of companies |
The demand curve is steep. AI agents need tools. MCP is how they get them. Every useful integration you build has a potential audience of millions of AI users.
The business case is simple:
- Users pay for tools that save them time
- You build once, earn recurring revenue
- MCPize handles hosting, billing, distribution
- You keep 85% of what you earn
Choose Your Path: Python or TypeScript#
Both languages have first-class MCP support. Your choice depends on your background and goals:
| Factor | Python (FastMCP) | TypeScript (SDK) |
|---|---|---|
| Setup time | 2 minutes | 4 minutes |
| Lines of code | ~40% less | More explicit |
| Type safety | Runtime | Compile-time |
| Best for | Data/ML, rapid prototyping | Production apps, type-heavy codebases |
| Testing | pytest | Jest/Vitest |
My recommendation: If you're just starting, use Python with FastMCP. The decorator syntax eliminates boilerplate and gets you to a working server fastest. You can always port to TypeScript later.
Prerequisites#
Before building, you need:
For Python:
python --version # 3.10+
pip install fastmcp
For TypeScript:
node --version # 18+
npm install @modelcontextprotocol/sdk zod
That's it. No complex setup. No cloud accounts required for development.
Build Your First MCP Server (Python)#
Here's the complete pattern. One file, ~25 lines, fully functional:
from fastmcp import FastMCP
mcp = FastMCP("MyServer")
@mcp.tool
def calculate(expression: str) -> str:
"""Evaluate a math expression safely."""
try:
# Only allow safe operations
allowed = set("0123456789+-*/(). ")
if not all(c in allowed for c in expression):
return "Error: Invalid characters"
return str(eval(expression))
except Exception as e:
return f"Error: {e}"
What's happening:
@mcp.toolregisters functions as tools Claude can call- Type hints (
str) become JSON Schema automatically - Docstrings become tool descriptions AI uses to understand capabilities
- Return values go back to the AI
Run it:
python server.py
That's a working MCP server. But a production server needs more.
Build Your First MCP Server (TypeScript)#
The TypeScript version is more explicit but offers compile-time safety:
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server(
{ name: "my-server", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [{
name: "calculate",
description: "Evaluate a math expression",
inputSchema: {
type: "object",
properties: { expression: { type: "string" } },
required: ["expression"]
}
}]
}));
Run it:
npx tsc && node dist/server.js
From Demo to Production: What Changes#
A demo server and a production server are different beasts. Here's what separates them:
Input Validation#
Production servers validate everything:
@mcp.tool
def search(query: str, limit: int = 10) -> str:
"""Search with validation."""
if len(query) < 2:
return "Error: Query too short"
if limit > 100:
limit = 100 # Cap to prevent abuse
# ... actual search logic
Error Handling#
Never expose internal errors to users:
@mcp.tool
def fetch_data(url: str) -> str:
"""Fetch data with proper error handling."""
try:
response = requests.get(url, timeout=10)
response.raise_for_status()
return response.text[:5000] # Cap response size
except requests.Timeout:
return "Error: Request timed out"
except Exception:
return "Error: Could not fetch data" # Don't leak internals
Logging#
Use stderr for debugging (stdout is for MCP protocol):
import sys
def log(message: str):
print(f"[DEBUG] {message}", file=sys.stderr)
Testing Your MCP Server#
Testing is non-negotiable. Here's the recommended strategy based on production patterns:
1. MCP Inspector (Visual Testing)#
npx @anthropic/mcp-inspector python server.py
Opens a browser UI where you can call tools interactively. Essential for development.
2. Unit Tests#
# test_server.py
import pytest
from server import calculate
def test_calculate_simple():
assert calculate("2 + 2") == "4"
def test_calculate_invalid():
result = calculate("import os")
assert "Error" in result
3. Integration Tests#
Test the full JSON-RPC cycle:
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | python server.py
Research shows comprehensive testing should include unit tests, schema validation, integration tests, and performance tests under load. Skipping any creates blind spots.
Deploy to Production#
Local testing is done. Time to deploy.
Docker (Recommended)#
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY server.py .
USER 1000:1000
CMD ["python", "server.py"]
Key patterns from production MCP servers:
- Minimal base images reduce attack surface
- Non-root user prevents privilege escalation
- Read-only filesystem where possible
- Secrets via environment variables, never in image
Cloud Deployment#
Over 70% of companies now use cloud-based MCP servers. AWS and Google Cloud dominate. For individual developers, platforms like MCPize handle the infrastructure entirely.
Security: What Gets Servers Rejected#
Security isn't optional. Here's what security research found about MCP servers in 2025:
| Issue | Prevalence |
|---|---|
| Static secrets (hardcoded API keys) | 53% |
| Command injection vulnerabilities | 43% |
| Proper OAuth implementation | Only 8.5% |
What to do:
- Never hardcode credentials — use environment variables
- Validate all inputs — assume everything is malicious
- Limit file access — only directories actually needed
- Use read-only database connections when possible
- Rotate API tokens regularly
import os
# Good: Environment variable
API_KEY = os.environ.get("API_KEY")
if not API_KEY:
raise ValueError("API_KEY not set")
# Bad: Hardcoded
# API_KEY = "sk-1234..." # Never do this
Monetization: Turn Your Server into Revenue#
This is where most guides stop. But building without monetizing is leaving money on the table.
Pricing Models That Work#
Subscription ($5-20/month)
- Best for: Tools used regularly
- Example: 21st.dev offers free tier, then $20/month
- Predictable revenue
Per-request (metered usage)
- Best for: API-heavy tools with variable usage
- Example: Bright Data, Exa.ai charge per underlying API call
- Scales with usage
One-time purchase ($10-50)
- Best for: Utilities, converters, simple tools
- Lower total revenue, no recurring relationship
Real Examples#
Companies already monetizing MCP servers include:
- Bright Data — MCP server for web scraping, per-usage billing
- Exa.ai — Search API via MCP, metered pricing
- Tavily — Research API, subscription tiers
The pattern: solve a real problem, charge fairly, use gateways for billing.
MCPize Revenue Share#
When you publish on MCPize:
- You set the price
- MCPize handles hosting, billing, distribution
- You keep 85% of revenue
- Monthly payouts to your account
The Publishing Checklist#
Before publishing, verify:
- All tools have clear descriptions
- Input validation prevents abuse
- Error messages are helpful, not leaky
- Tests pass (unit + integration)
- Security: no hardcoded secrets
- README explains what the server does
- Usage examples show common workflows
# mcpize.yaml
name: my-awesome-server
version: 1.0.0
description: "Clear, specific description of what this does"
runtime: python
pricing:
model: subscription
price: 9.99
tags:
- productivity
- automation
FAQ#
How long does it take to build a production MCP server?#
- Basic demo: 30 minutes
- Production-ready with tests: 2-4 hours
- Full-featured with multiple tools: 1-2 days
The investment is front-loaded. Once your patterns are set, adding tools is fast.
FastMCP or raw SDK?#
FastMCP for Python gives you decorators and automatic schema generation — faster development. Raw SDK gives more control but more boilerplate. For most cases, FastMCP is the right choice.
Do I need AI/ML knowledge?#
No. MCP servers are just APIs that AI can call. If you can write a REST endpoint, you can write an MCP tool.
What servers earn the most?#
Database connectors, productivity tools, and API wrappers for services without native MCP support. The key is solving a specific pain point well, not building a "does everything" tool.
Can I use external APIs?#
Yes. Many successful servers are wrappers around existing APIs — adding MCP interface to services that don't have one. Just handle rate limits and errors properly.
Next Steps#
You have the knowledge. Now build something.
- Start small — One tool, well-tested
- Test thoroughly — MCP Inspector → Unit tests → Integration
- Deploy early — Get real feedback from users
- Iterate based on data — Usage metrics show what matters
Related guides:
- What is MCP? — Protocol fundamentals
- MCP Tutorial — Hands-on beginner tutorial
- Monetize MCP Servers — Detailed pricing strategies
Have questions? Join the MCPize Discord or explore the marketplace for inspiration.



