summarize tool charges by input length, and a client that pays for a call and finds the payment on the indexer. Any MCP client with an Algorand wallet can then call your tools, with no accounts or API keys.
Write the server
localnet/paid_mcp_tool/server.py
summarize costs 1,000 microALGO per started block of 100 characters, with a minimum of 3,000 microALGO. The pricing function runs before the 402 is sent, so the caller is quoted the exact price for its input. The minimum stays above the 2,000 microALGO fee the server pays per call; see the fee floor.
Pay for a call
localnet/paid_mcp_tool/client.py
Configure PaymentGate
PaymentGate intercepts each tools/call. When the call has a price above 0 and no valid payment, it answers 402.
Every parameter, with types:
PaymentGate reference.
Choose a transport
gate.wrap(mcp, transport=...) returns an ASGI app. Serve it with any ASGI server, for example uvicorn.run(app, host="127.0.0.1", port=9201).
Always pass
transport=. Without it, wrap() still serves SSE, as 0.4 did, and emits a FutureWarning: the default will change to "streamable-http" in a future release. path= changes the endpoint path, and other keyword arguments go to FastMCP.http_app().
What wrap() adds
- The gate’s ASGI middleware. It inspects the JSON-RPC body of every HTTP
POST, whatever its path or transport. Other requests and non-tool messages (initialize,tools/list) pass through. For atools/callit reads the caller’s identity, computes the price, and passes the call through (price 0), answers402, or verifies the attached payment and reserves it. JSON-RPC batches containing atools/callare rejected with HTTP400. SettleOnSuccessMiddleware, a FastMCP middleware. After the tool returns, it settles or releases the payment. It refuses, withPaymentRequiredError, any priced call that did not pass through the gate, so a transport the gate does not wrap cannot serve paid tools for free.
Mount the app yourself
To mount the MCP app inside a larger Starlette or FastAPI app, install both layers. WithoutSettleOnSuccessMiddleware the gate refuses priced calls with HTTP 500.
Register tools with a decorator
AIEconomySDK bundles a FastMCP server and a PaymentGate; each tool is registered with its own pricing function.
pricing_func receives the tool arguments and the caller’s verified address (or None). A function that accepts only args also works; one that accepts neither raises ConfigurationError when the tool is registered. build_app(transport=...) forwards to PaymentGate.wrap(). See the AIEconomySDK reference.
Next
- Pricing and passes: per-tool, dynamic and bulk prices, prepaid access.
- Go to MainNet: USDC, keys, fee funding and several workers.