@getalby/paidmcp
Version:
Charge for your MCP Server tools using Nostr Wallet Connect
29 lines (28 loc) • 1.14 kB
JavaScript
import { McpServer, } from "@modelcontextprotocol/sdk/server/mcp.js";
import "websocket-polyfill";
import { NWCWallet } from "./wallets/nwc_wallet.js";
import { paidConfig } from "./schema.js";
import { paidCallback } from "./callbacks.js";
import { MemoryStorage } from "./storage/memory_storage.js";
export class PaidMcpServer extends McpServer {
_wallet;
_storage;
constructor(serverInfo,
/**
* @property nwcUrl the connection secret for your wallet - ideally receive-only
* @property storage configure storage for paid, unused tool access (default: in-memory)
*/
paidArgs, options) {
super(serverInfo, options);
this._wallet = new NWCWallet(paidArgs.nwcUrl);
this._storage = paidArgs.storage || new MemoryStorage();
}
/**
* Registers a paid tool with a config object, charge callback and tool callback.
*
* @param charge configure how much to charge based on the request
*/
registerPaidTool(name, config, charge, cb) {
return this.registerTool(name, paidConfig(config), paidCallback(cb, charge, this._wallet, this._storage));
}
}