15-minute tutorial

Build an MCP Server: Complete Tutorial (Python & TypeScript)

Learn how to build MCP servers from scratch using FastMCP for Python or the TypeScript SDK. Deploy with one command and start earning on the MCPize marketplace.

97M+
Monthly SDK Downloads
5,500+
MCP Servers Registered
85%
Revenue Share
15min
Time to First Server

Why Build MCP Servers in 2025?

Model Context Protocol (MCP) has become the standard for connecting AI applications to external data and tools. In 2025, the ecosystem has exploded with adoption from major players. When you build an MCP server, you tap into a rapidly growing market of AI developers looking for integrations.

Industry Adoption

  • OpenAI adopted MCP (March 2025)
  • Google DeepMind integration (April 2025)
  • Claude, Cursor, VS Code native support

Monetization Opportunity

  • 85% revenue share on MCPize
  • Flexible pricing tiers (Free/Pro/Enterprise)
  • Monthly payouts via Stripe Connect

Developer Experience

  • FastMCP 2.0 for rapid Python development
  • TypeScript SDK with full type safety
  • One-command deploy with MCPize CLI

Building an MCP server today positions you at the forefront of the AI tools ecosystem. Whether you want to create internal tools for your organization or build a public server to monetize on the marketplace, now is the perfect time to build MCP servers.

Prerequisites

Before you start building your MCP server, make sure you have the following tools installed on your system. The MCP server tutorial below assumes you have these prerequisites ready.

For Python Development

  • Python 3.10+

    FastMCP requires Python 3.10 or higher

  • uv or pip

    Package manager for dependencies (uv recommended)

  • FastMCP 2.0

    pip install fastmcp

For TypeScript Development

  • Node.js 18+

    LTS version recommended for stability

  • TypeScript 5+

    For type safety and better DX

  • @modelcontextprotocol/sdk

    Official TypeScript SDK

MCPize Account & CLI

To deploy and monetize your MCP server, you will need a free MCPize account and the CLI tools installed.

terminal
$npm install -g @mcpize/cli
$mcpize login

Initialize Your Project with MCPize CLI

The fastest way to create an MCP server is using the MCPize CLI. It scaffolds a complete project with best practices, configuration files, and example code. You can build MCP servers in Python or TypeScript.

Step 1: Create a New Project

Run the init command and follow the interactive prompts

terminal
$mcpize init my-mcp-server
? Select language: (Use arrow keys)
> Python (FastMCP)
TypeScript
? Server name: my-mcp-server
? Description: My awesome MCP server
Creating project structure...
Installing dependencies...
Project created successfully!

Step 2: Project Structure

The CLI generates a complete project with all necessary files

my-mcp-server/
├── src/server.py       # Main server code
├── mcpize.yaml         # MCPize config
├── pyproject.toml      # Dependencies
└── README.md

mcpize.yaml Configuration

Server metadata, pricing, and deployment settings

name: my-mcp-server
runtime: python3.11
entrypoint: src/server.py

plans:
  - name: Free
    price: 0
    limits: { requests_per_month: 1000 }
  - name: Pro
    price: 9
    limits: { requests_per_month: 50000 }

Build MCP Server in Python (FastMCP)

FastMCP is the recommended way to build MCP servers in Python. It provides a simple decorator-based API that lets you focus on your tool logic rather than protocol details. This MCP server Python tutorial shows you how to create a server with tools, resources, and prompts.

Python MCP Server (FastMCP)

Clean, minimal MCP server with tools and resources

# server.py - FastMCP MCP Server
from fastmcp import FastMCP

mcp = FastMCP("my-server")

@mcp.tool()
def get_weather(city: str) -> dict:
    """Get current weather for a city."""
    # Your API call here
    return {"city": city, "temp": 22, "condition": "sunny"}

@mcp.tool()
def calculate(a: float, b: float, op: str = "add") -> float:
    """Perform calculation: add, sub, mul, div."""
    ops = {"add": a + b, "sub": a - b, "mul": a * b, "div": a / b}
    return ops.get(op, a + b)

@mcp.resource("config://settings")
def get_settings() -> str:
    """Server configuration."""
    return "max_requests: 100\nversion: 1.0.0"

if __name__ == "__main__":
    mcp.run()

Key Concepts

@mcp.tool()

Tools are functions the AI can call to perform actions. FastMCP automatically generates the JSON schema from your type hints and docstrings.

@mcp.resource()

Resources expose data the AI can read. Use URI patterns like "config://settings" or "file://path/to/data" to organize your resources.

@mcp.prompt()

Prompts are reusable templates that help users interact with your server. They can include parameters for customization.

Important: stdio Transport

When building an MCP server for stdio transport (local development with Claude Desktop):

  • !Never log to stdout - it breaks JSON-RPC communication
  • !Use stderr for debugging: print(..., file=sys.stderr)
  • !Or use Python logging configured to write to stderr

Build MCP Server in TypeScript

The TypeScript SDK provides full control over your MCP server implementation with complete type safety. This MCP server TypeScript tutorial covers creating a server using the official @modelcontextprotocol/sdk package.

TypeScript MCP Server

Clean MCP server with type-safe tools

// server.ts - TypeScript MCP Server
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";

const server = new Server(
  { name: "my-server", version: "1.0.0" },
  { capabilities: { tools: {} } }
);

// Define tools
server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [{
    name: "get_weather",
    description: "Get weather for a city",
    inputSchema: {
      type: "object",
      properties: { city: { type: "string" } },
      required: ["city"]
    }
  }]
}));

// Handle tool calls
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  const { name, arguments: args } = request.params;
  if (name === "get_weather") {
    return {
      content: [{ type: "text", text: `Weather in ${args?.city}: 22°C, sunny` }]
    };
  }
  throw new Error(`Unknown tool: ${name}`);
});

// Start server
const transport = new StdioServerTransport();
await server.connect(transport);

TypeScript vs Python: When to Choose

Choose Python (FastMCP) when:

  • - You want rapid prototyping and development
  • - Your team is more familiar with Python
  • - You are integrating with Python libraries (ML, data science)
  • - You prefer decorator-based, concise syntax

Choose TypeScript when:

  • - You need full type safety and IDE support
  • - Your team works primarily in JavaScript/TypeScript
  • - You are building complex enterprise applications
  • - You want maximum control over the protocol

Test with Claude Desktop

Before deploying your MCP server, test it locally with Claude Desktop. This lets you verify your tools work correctly and iterate quickly on your implementation. Claude Desktop connects to local MCP servers via stdio transport.

Step 1: Configure Claude Desktop

Add your server to the Claude Desktop configuration file

Edit the Claude Desktop config file at:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "my-mcp-server": {
      "command": "python",
      "args": ["/path/to/server.py"]
    }
  }
}

Step 2: Use mcpize dev for Hot Reload

The MCPize CLI provides a development server with automatic reloading

terminal
$cd my-mcp-server
$mcpize dev
Starting development server...
Hot reload enabled
Server running at stdio://my-mcp-server
Watching for file changes...

Step 3: Test Your Tools

Open Claude Desktop and interact with your server

After restarting Claude Desktop, your server tools will be available. Try prompts like:

"What time is it in Tokyo?"

"Calculate the price for 5 items at $29.99 each with 15% discount"

"Show me the server settings"

Claude will automatically detect and use the appropriate tools from your MCP server.

Deploy to MCPize (One Command)

Once your MCP server is tested locally, deploy it to MCPize with a single command. MCPize handles hosting, scaling, SSL, monitoring, and provides a production-ready HTTP endpoint. The deploy MCP server process takes less than a minute.

Deploy Your Server

terminal
$mcpize deploy
Packaging server...
Uploading to MCPize...
Building container...
Deploying to edge network...
Deployment successful!
Your server is live at:
https://my-mcp-server.mcpize.run
MCP Endpoint:
https://my-mcp-server.mcpize.run/mcp

Streamable HTTP

MCPize automatically converts your server to use Streamable HTTP transport - the production standard for remote MCP servers. No code changes required.

Global Edge Network

Your server is deployed to multiple regions worldwide for low latency. Automatic failover and load balancing ensure high availability.

Built-in Monitoring

Real-time metrics, logs, and alerts are available in your MCPize dashboard. Track requests, errors, latency, and usage across all your servers.

Ready to Deploy?

Sign up for a free MCPize account and deploy your first MCP server in minutes. No credit card required.

Deploy Your First Server

Publish to Marketplace

After deploying your MCP server, publish it to the MCPize marketplace to make it discoverable by thousands of developers. Publishing adds your server to the directory with searchable metadata, documentation, and pricing.

Publish Command

terminal
$mcpize publish
Validating mcpize.yaml...
Generating documentation...
Creating marketplace listing...
Server published successfully!
View your listing:
https://mcpize.com/mcp/my-mcp-server

What Gets Published

  • Server name, description, and category from mcpize.yaml
  • Auto-generated API documentation from tool schemas
  • Pricing tiers and usage limits
  • README.md content for detailed documentation
  • Example prompts and use cases

Marketplace Visibility Tips

  • Write clear, descriptive tool names and descriptions
  • Include relevant tags for better search discovery
  • Provide example prompts showing real use cases
  • Offer a free tier to attract initial users
  • Keep documentation up-to-date with new features

Monetize Your MCP Server

MCPize makes it easy to earn money from your MCP server. Set up pricing tiers, track revenue, and receive monthly payouts. With 85% revenue share, your earnings scale with your user base.

Revenue Share Model

85%

You keep 85% of all subscription revenue. MCPize takes 15% to cover hosting, billing infrastructure, and platform maintenance.

  • Monthly payouts via Stripe Connect
  • $100 minimum payout threshold
  • Real-time earnings dashboard

Recommended Pricing Tiers

Free$0/mo

1,000 requests/month - great for discovery

Pro$9-29/mo

50,000 requests/month - individual developers

Enterprise$49-199/mo

Unlimited requests - teams and businesses

Earnings Example

SubscribersPlanMonthly RevenueYour Earnings (85%)
50Pro ($19/mo)$950$665
100Pro ($19/mo)$1,900$1,330
200Mixed tiers$4,500$3,150
500Mixed tiers$12,000$8,400

* Actual earnings depend on your pricing and subscriber mix. Popular servers with quality tools can grow to 500+ subscribers within 6-12 months.

Best Practices for Building MCP Servers

Follow these best practices to build reliable, secure, and user-friendly MCP servers that provide great experiences and attract subscribers.

Tool Design

Use descriptive names: "get_user_profile" is better than "fetch" or "getData"
Write detailed docstrings: Include purpose, parameters, and return types
Use typed parameters: Let the AI know exactly what input is expected
Return structured data: JSON objects are easier for AI to parse than plain text

Error Handling

Validate inputs: Check parameters before processing and provide clear error messages
Handle edge cases: What if the API is down? What if data is missing?
Use proper error types: MCP defines error codes - use them appropriately
Log errors to stderr: Never to stdout (breaks stdio transport)

Performance

Use async operations: Dont block on I/O - use async/await
Cache expensive operations: Store results that dont change frequently
Set timeouts: External API calls should have reasonable timeouts
Limit response sizes: Paginate or truncate large datasets

Security

Never expose secrets: Use environment variables for API keys
Validate all inputs: Sanitize user-provided data to prevent injection
Scope permissions: Request only the minimum access needed
Audit logging: Log security-relevant events for review

Frequently Asked Questions

Get answers to common questions about building MCP servers, deployment, and monetization.

Ready to Build Your MCP Server?

Join thousands of developers building and monetizing MCP servers on MCPize. Create your free account and deploy your first server in 15 minutes.

No credit card required. Free tier available.