tutorial
Featured

Build MCP Server: Complete Guide from Zero to Earning

Learn how to build an MCP server in Python or TypeScript. Step-by-step tutorial with testing, deployment, and monetization. Start earning with MCPize.

MCPize Team
MCPize TeamCore Team
November 19, 20257 min read
Build MCP Server tutorial showing code editor with Python and TypeScript

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
Browse existing MCP servers for inspiration

Why Build MCP Servers Now?#

The timing matters. Here's what the data shows:

MCP Ecosystem Growth
MetricValue
Total MCP servers6,800+
Companies using MCPOpenAI, Google, Microsoft, Anthropic
Cloud deployment adoption70%+
Efficiency improvement reported75% 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:

FactorPython (FastMCP)TypeScript (SDK)
Setup time2 minutes4 minutes
Lines of code~40% lessMore explicit
Type safetyRuntimeCompile-time
Best forData/ML, rapid prototypingProduction apps, type-heavy codebases
TestingpytestJest/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.tool registers 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:

Development Time (minutes)

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.

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:

IssuePrevalence
Static secrets (hardcoded API keys)53%
Command injection vulnerabilities43%
Proper OAuth implementationOnly 8.5%

What to do:

  1. Never hardcode credentials — use environment variables
  2. Validate all inputs — assume everything is malicious
  3. Limit file access — only directories actually needed
  4. Use read-only database connections when possible
  5. 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#

MCP Server Pricing Models

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.

  1. Start small — One tool, well-tested
  2. Test thoroughly — MCP Inspector → Unit tests → Integration
  3. Deploy early — Get real feedback from users
  4. Iterate based on data — Usage metrics show what matters
Publish Your Server on MCPize Python Deep-Dive Tutorial TypeScript Deep-Dive Tutorial

Related guides:

Have questions? Join the MCPize Discord or explore the marketplace for inspiration.

Enjoyed this article?

Share it with your network

MCPize Team

MCPize Team

Core Team

The team behind MCPize - building the future of MCP server monetization.

Stay Updated

Get the latest MCP tutorials, product updates, and developer tips delivered to your inbox.

No spam, ever. Unsubscribe anytime.

Related Articles

Continue exploring similar topics

View all articles