DEV Community

Cover image for How to Monetize Your MCP Server
Angel Pichardo
Angel Pichardo

Posted on

How to Monetize Your MCP Server

Overview

Developers love MCP servers. They are lightweight, powerful, and the community is growing fast.

But there’s one major gap:
Most MCP servers are free to use. How can you build a premium MCP server?

This guide shows you how to add payments to any MCP server using PayMCP + any provider. We’ll use Walleot as the provider in this example.

What You’ll Build

✔ A working MCP server with one tool (Luma AI)

✔ Users paying before your tool runs

✔ Support for all official payment modes

✔ A reusable structure for monetizing any MCP tool

Prerequisites

Before you start, make sure you have:

  • Python 3.10+ installed
  • API keys:
  • Basic familiarity with Python async functions

New to MCP? Check out the MCP introduction first.

How It Works

Here's the payment flow when a user calls your tool:

payment flow

Why this architecture?

  • Secure: API keys stay on your server (never exposed to users)
  • Scalable: Stateless design, no payment session management
  • Compatible: Works with Claude Desktop, ChatGPT, and all MCP clients

Base MCP Server

Let’s first build a simple video generation tool:

from mcp.server.fastmcp import FastMCP, Context

mcp = FastMCP("Video generator")

@mcp.tool()
async def generate(prompt: str, ctx: Context):
    """Generate a short AI video from a text prompt."""
    # Your video generation logic here
    video_url = await your_video_function(prompt)
    return f"Video generated! Watch it here: {video_url}"

if __name__ == "__main__":
    mcp.run(transport="streamable-http")
Enter fullscreen mode Exit fullscreen mode

This is a standard MCP server. Now let’s add payments!

Add Payments

Install:

pip install paymcp lumaai python-dotenv
Enter fullscreen mode Exit fullscreen mode

Create a .env file with your API keys:

# .env file
WALLEOT_API_KEY=your_walleot_api_key_here
LUMA_API_KEY=your_luma_api_key_here
PRICE_USD=0.60
Enter fullscreen mode Exit fullscreen mode

⚠️ Security Note: Never commit .env files to git. Add them to .gitignore immediately.

Update Your Server

import os
from mcp.server.fastmcp import FastMCP, Context
from paymcp import PayMCP, Mode, price
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Initialize MCP server
mcp = FastMCP("Video generator")

# Add PayMCP (this is where the magic happens)
PayMCP(
    mcp,
    providers={"walleot": {"apiKey": os.getenv("WALLEOT_API_KEY")}},
    mode=Mode.RESUBMIT  # Recommended: stateless, reliable
)

# Your video generation function
async def generate_video(prompt: str) -> str:
    """Generate video using Luma AI."""
    from lumaai import AsyncLumaAI
    import asyncio

    client = AsyncLumaAI(auth_token=os.getenv("LUMA_API_KEY"))

    # Create generation
    generation = await client.generations.create(
        prompt=prompt,
        model="ray-2"
    )

# The tool—now with payments!
@mcp.tool()
@price(0.60, "USD")  # ← This line adds payment gating
async def generate(prompt: str, ctx: Context):
    """Generates a short AI video and returns a download URL.

    Cost: $0.60 per video generation
    Processing time: 1-3 minutes
    """
    video_url = await generate_video(prompt)

    return f"""Video generated successfully!

WATCH VIDEO: {video_url}

Right-click to download as MP4
Link valid for 24 hours from Luma AI"""

if __name__ == "__main__":
    mcp.run(transport="streamable-http")
Enter fullscreen mode Exit fullscreen mode

🎉 That's it! You just monetized your MCP tool with a few lines of code:

  1. Import PayMCP, Mode, and price
  2. Call PayMCP() with your Walleot API key
  3. Add @price(0.60, "USD") to your tool

Why RESUBMIT Mode?

  • No server-side state management
  • Works with all MCP clients (Claude, ChatGPT, etc.)
  • Handles long-running tasks gracefully
  • Automatically retries when payment completes

You can switch modes anytime:

PayMCP(
    mcp,
    providers={"walleot": {"apiKey": os.getenv("WALLEOT_API_KEY")}},
    mode=Mode.TWO_STEP  # or ELICITATION, PROGRESS, DYNAMIC_TOOLS
)
Enter fullscreen mode Exit fullscreen mode

Learn more about payment modes →

Try it yourself: Full demo here!

Conclusion

Monetizing an MCP server does not require billing dashboards, OAuth issues, or rebuilding your tools from the ground up. With PayMCP and Walleot, you can keep your MCP server exactly as it is and simply add payments when needed.

You just accomplished:

✔ Building a fully working MCP server

✔ Adding pricing with a single line of code

✔ Supporting every official payment mode

✔ Creating a reusable structure for future paid tools

This is how developers turn a cool side project into a sustainable product.

Whether you are building AI video generators, research tools, or anything in between, you can now get paid when your MCP tools deliver value.

Join the Walleot Community

Have questions or want to show off what you’ve built?

Join the Walleot developer community on Discord and X/Twitter. Let’s build the future of paid MCP tools together!

Top comments (0)