Skip to main content

Provider-agnostic payment layer for MCP (Model Context Protocol) tools and agents.

Project description

PayMCP

Provider-agnostic payment layer for MCP (Model Context Protocol) tools and agents.

paymcp is a lightweight SDK that helps you add monetization to your MCP-based tools, servers, or agents. It supports multiple payment providers and integrates seamlessly with MCP's tool/resource interface.


🔧 Features

  • ✅ Add @price(...) decorators to your MCP tools to enable payments
  • 🔁 Choose between different payment flows (elicit, confirm, etc.)
  • 🔌 Pluggable support for providers like Walleot, Stripe, and more
  • ⚙️ Easy integration with FastMCP or other MCP servers

🧭 Payment Flows

The payment_flow parameter controls how the user is guided through the payment process. Choose the strategy that fits your use case:

  • PaymentFlow.TWO_STEP (default)
    Splits the tool into two separate MCP methods.
    The first step returns a payment_url and a next_step method for confirmation.
    The second method (e.g. confirm_add_payment) verifies payment and runs the original logic.
    Supported in most clients.

  • PaymentFlow.ELICITATION Sends the user a payment link when the tool is invoked. If the client supports it, a payment UI is displayed immediately. Once the user completes payment, the tool proceeds.

  • PaymentFlow.PROGRESS
    Shows payment link and a progress indicator while the system waits for payment confirmation in the background. The result is returned automatically once payment is completed.

  • PaymentFlow.OOB (Out-of-Band)
    Not yet implemented.

All flows require the MCP client to support the corresponding interaction pattern. When in doubt, start with TWO_STEP.


🚀 Quickstart

Install the SDK from PyPI:

pip install mcp paymcp

Initialize PayMCP:

from mcp.server.fastmcp import FastMCP, Context
from paymcp import PayMCP, price, PaymentFlow
import os

mcp = FastMCP("AI agent name")
PayMCP(
    mcp,  # your FastMCP instance
    providers={
        "stripe": {"apiKey": os.getenv("STRIPE_API_KEY")},
    },
    payment_flow=PaymentFlow.TWO_STEP #or ELICITATION / PROGRESS
)

Providers: alternative styles (optional)

Instances instead of config (advanced):

import os
from paymcp.providers import WalleotProvider, StripeProvider

PayMCP(
    mcp,
    providers=[
        WalleotProvider(api_key=os.getenv("WALLEOT_API_KEY")),
        CoinbaseProvider(api_key=os.getenv("COINBASE_API_KEY")),
    ],
)
# Note: right now the first configured provider is used.

Custom provider (minimal):
Any provider must subclass BasePaymentProvider and implement create_payment(...) and get_payment_status(...).

from paymcp.providers import BasePaymentProvider

class MyProvider(BasePaymentProvider):

    def create_payment(self, amount: float, currency: str, description: str):
        # Return (payment_id, payment_url)
        return "unique-payment-id", "https://example.com/pay"

    def get_payment_status(self, payment_id: str) -> str:
        return "paid"

PayMCP(mcp, providers=[MyProvider(api_key="...")])

Use the @price decorator on any tool:

@mcp.tool()
@price(amount=0.19, currency="USD")
def add(a: int, b: int, ctx: Context) -> int:
    # `ctx` is required by the PayMCP tool signature — include it even if unused
    return a + b

Demo server: For a complete setup, see the example repo: python-paymcp-server-demo.


🪟 Optional: WebView (STDIO)

Open the payment link in a native window when your MCP server is connected via the stdio transport (typical for local/desktop installs).

  • Install: pip install paymcp[webview] (or pdm add paymcp[webview]).
  • What it does: when a priced tool is invoked, PayMCP opens a lightweight in-app webview to the provider's payment_url so the user can complete checkout without leaving the client.
  • Scope: applies only to stdio connections on the user's machine.
  • Notes: requires a desktop environment.

🧩 Supported Providers


📄 License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paymcp-0.2.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paymcp-0.2.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file paymcp-0.2.0.tar.gz.

File metadata

  • Download URL: paymcp-0.2.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.6 CPython/3.10.14 Darwin/24.3.0

File hashes

Hashes for paymcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ca905db74d5e239ff5f8ffd8fc1f6d3290fbdfad3618312b6a1f3af08dcf93eb
MD5 57617a1b39655a0908472281259e46df
BLAKE2b-256 c6ce762a2d5a2cde2d89d43bb94e708d28e63b94c686755917210d39b48342d3

See more details on using hashes here.

File details

Details for the file paymcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: paymcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.6 CPython/3.10.14 Darwin/24.3.0

File hashes

Hashes for paymcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7b4ee74350f4e18727f0670edb87cee2cc91a43c6835f8d135d5dbffd3a5fef
MD5 2031171615130eee848d05b7855b0235
BLAKE2b-256 3d87369ce68fa4a4f3b5ee060588842908dd2cc882cba66ae049acd863053577

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page