Skip to content

tomopay/demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tomopay End-to-End Demo

License: MIT Demo

A runnable end-to-end demonstration of the full Tomopay payment loop: server-side gateway (@tomopay/gateway) + buyer client (@tomopay/client) communicating over an in-memory MCP transport.

What it demonstrates

  • Free tool passthrough — tools without a price execute immediately, no payment flow triggered
  • Transparent auto-pay — when a paid tool returns PAYMENT_REQUIRED, the client auto-detects the challenge, signs a payment proof, and retries without any changes to your agent code
  • Multi-tool payments — two paid tools at different prices (translate at $0.01, summarize at $0.05)
  • Budget trackingclient.getSpendingStats() returns per-session and daily spend totals
  • Receipt flow — every successful paid call returns a _receipt block alongside the tool result

How to run

npm install
npm run demo

Requires Node.js 18+.

Expected output

=== Tomopay End-to-End Demo ===

Server and client connected

--- Test 1: Free tool (echo) ---
  Result: Echo: Hello world!
  Free tool works — no payment needed

--- Test 2: Paid tool (translate, $0.01) ---
  Auto-paying $0.01 for "translate" via mock
  Result: [Translated to Spanish]: Hello world
  Paid tool works — payment handled transparently

--- Test 3: Paid tool (summarize, $0.05) ---
  Auto-paying $0.05 for "summarize" via mock
  Result: Summary of "The quick brown fox jumps over the lazy dog. This ...": This is a key point.
  Second paid tool works

--- Test 4: Spending stats ---
  Total spent: $0.06
  Today: $0.06
  Calls: 2
  Budget tracking works

=== All tests passed! ===
The full payment loop works:
  Agent calls tool -> Gateway returns PAYMENT_REQUIRED
  -> Client auto-detects -> Checks budget -> Signs payment
  -> Retries with proof -> Gateway verifies -> Tool executes
  -> Receipt returned -> Spending tracked

How the loop works

Agent calls tool
      │
      ▼
Gateway checks pricing table
      │
      ├─ No price set ──────────────────► Execute immediately (passthrough)
      │
      └─ Price set, no _payment arg ───► Return PAYMENT_REQUIRED + challenge
                                                    │
                                                    ▼
                                          Client receives challenge
                                                    │
                                          Check budget limits
                                                    │
                                          Sign payment proof
                                                    │
                                          Retry call with _payment arg
                                                    │
                                                    ▼
                                          Gateway verifies proof
                                                    │
                                          Execute tool, return result + receipt

See Also

About

End-to-end demo: AI agent paying an MCP tool via Tomopay

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors