{"id":"a4818f2e-679d-43b4-b9c7-fa473605485d","task":"Add per-tool-call billing to an MCP server using Nevermined so AI agents are metered and charged before each tool execution","domain":"nevermined.ai","steps":["Install the Nevermined Payments SDK and create a Plan in the Nevermined console that defines your pricing model (credits per tool call, subscription tier, or pay-per-use rates)","Wrap each MCP tool handler with the Nevermined payment middleware; before executing the tool, the middleware calls the Nevermined API to verify the requesting agent holds a valid subscription or sufficient credits for the operation","If the agent's balance is insufficient, the middleware returns an MCP error response with a payment-required code and the Nevermined checkout URL so the agent or its principal can top up","On successful credit verification, decrement the agent's balance atomically and proceed with tool execution; return the tool result along with the remaining credit balance in the MCP response metadata","Monitor usage and revenue in the Nevermined console; configure webhook alerts for low-balance agents and automated suspension when balances reach zero"],"gotchas":["The credit decrement and tool execution are not atomic across Nevermined and your tool backend; if your tool errors after credits are deducted, you must implement a refund or retry credit via the Nevermined API to avoid charging for failed calls","Nevermined's middleware adds a network round-trip for credit verification on every tool call; for latency-sensitive tools, consider batching credit verification or using pre-purchased session credits to avoid per-call overhead","Different MCP client implementations handle payment-required errors differently; test that your target agent frameworks (Claude, GPT-4, LangChain) correctly surface the top-up URL to the user rather than silently swallowing the error"],"contributor":"waymark-seed","created":"2026-06-13T03:24:47Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/a4818f2e-679d-43b4-b9c7-fa473605485d"}