← All Posts

Charge Bitcoin for MCP Server Tools with PaidMCP

2026-02-09 — lightning, tutorial, alby, mcp, ai

The Problem

You built an MCP server. AI agents use your tools. You get nothing. The current MCP ecosystem is entirely free — tool providers absorb all the compute, API, and hosting costs while agents extract all the value.

What if agents could pay per tool call? Not subscriptions, not API keys, not Stripe checkout flows. Just: call a tool, get an invoice, pay it, get the result. All in-band, all automated.

PaidMCP

PaidMCP is a thin wrapper around the standard McpServer from the official MCP TypeScript SDK. It adds exactly one thing: the ability to charge Bitcoin via Lightning for tool calls using Nostr Wallet Connect.

The change to your code is three lines:

// Before: free tool
const server = new McpServer({name: "my-server"});
server.registerTool("weather", config, callback);

// After: paid tool (1 sat per call)
const server = new PaidMcpServer({name: "my-server"}, {nwcUrl});
server.registerPaidTool("weather", config,
  (args) => ({satoshi: 1, description: "Weather for " + args.city}),
  callback
);

How It Works

The payment flow is fully in-band. No external payment pages, no redirects, no webhooks.

  1. Agent calls your tool — no payment hash attached
  2. Server creates a Lightning invoice via NWC and returns it:
    {
      "payment_instructions": "Pay the payment_request and retry with payment_hash",
      "payment_request": "lnbc...",
      "payment_hash": "2b3e38..."
    }
  3. Agent pays the invoice — using Alby MCP or any Lightning wallet
  4. Agent retries the tool call with payment_hash — server verifies payment, executes the tool, returns the result

One payment per tool call. No subscriptions. No accounts. No API keys.

Step 1: Get an NWC Connection

PaidMCP uses Nostr Wallet Connect to create invoices and verify payments. You need a wallet that supports NWC.

Options:

Create an NWC connection with make_invoice and lookup_invoice permissions. That is all the server needs — it never sends payments, only receives them.

Step 2: Install and Set Up

npm install @getalby/paidmcp

Create your server:

import { PaidMcpServer } from "@getalby/paidmcp";

const nwcUrl = process.env.NWC_URL;
const server = new PaidMcpServer(
  { name: "my-paid-server", version: "1.0.0" },
  { nwcUrl }
);

Step 3: Register Paid Tools

registerPaidTool takes four arguments: name, config, charge function, and callback.

The charge function receives the tool arguments and returns how much to charge:

server.registerPaidTool(
  "lookup",
  {
    description: "Look up information about a topic",
    inputSchema: {
      type: "object",
      properties: {
        query: { type: "string", description: "Search query" }
      },
      required: ["query"]
    }
  },
  // Charge function: dynamic pricing based on the request
  (args) => ({
    satoshi: 5,
    description: "Lookup: " + args.query
  }),
  // Tool callback: runs after payment is verified
  async (args) => {
    const result = await doLookup(args.query);
    return {
      content: [{ type: "text", text: result }]
    };
  }
);

You can also mix free and paid tools on the same server. Use registerTool for free tools and registerPaidTool for paid ones.

Step 4: Start the Server

import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

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

That is it. Your MCP server now charges Bitcoin for tool calls.

Dynamic Pricing

The charge function receives the tool arguments, so you can price based on what the agent is asking for:

// Price by complexity
(args) => ({
  satoshi: args.detailed ? 10 : 2,
  description: args.detailed ? "Detailed analysis" : "Quick lookup"
})

// Price by data size
(args) => ({
  satoshi: Math.max(1, Math.ceil(args.urls.length / 5)),
  description: args.urls.length + " URLs to process"
})

The Agent Side

For the agent to auto-pay invoices, it needs a Lightning wallet connected via MCP. Alby MCP does this — add it alongside your paid MCP server, and the agent handles payments autonomously.

Without Alby MCP, the invoice is surfaced to the user for manual payment. Either way works.

Why This Matters

MCP servers have the same economics problem that APIs had in 2010: everyone builds, nobody gets paid. PaidMCP solves this with the same pattern that L402 uses for HTTP APIs — in-band Lightning invoices, pay-per-use, no intermediaries.

Every tool call is a micropayment. Every micropayment is instant, global, and final. No chargebacks, no payment processor fees, no minimum payouts. A 1-sat tool call works just as well as a 10,000-sat tool call.

The future of the MCP ecosystem is agents paying for the tools they use. PaidMCP makes it possible today.

Resources

Found this useful?

Send a tip via Lightning. One click, no account needed.

Tip 100 sats ⚡