By the end of this page you will have a FastMCP server whose 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.
You need an Algorand account for the server: it receives payments and pays the network fee of each call. The code below runs on LocalNet, where the examples fund accounts for you.

Write the server

localnet/paid_mcp_tool/server.py
Source: examples/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
Source: examples/localnet/paid_mcp_tool/client.py
In a second terminal:
The 153-character input is two blocks (2,000 microALGO), below the minimum, so the call cost 3,000. The transaction id and round differ on every run. The client side is covered in Pay from Python.

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().
ai-economy-sdk 0.4.x served priced tools without payment on Streamable HTTP and on SSE apps mounted under a path prefix. Use 0.5.0 or later. See Security.

What wrap() adds

  1. 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 a tools/call it reads the caller’s identity, computes the price, and passes the call through (price 0), answers 402, or verifies the attached payment and reserves it. JSON-RPC batches containing a tools/call are rejected with HTTP 400.
  2. SettleOnSuccessMiddleware, a FastMCP middleware. After the tool returns, it settles or releases the payment. It refuses, with PaymentRequiredError, 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. Without SettleOnSuccessMiddleware 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