Skip to content

Quick Start

Get your MCP server earning money in 5 minutes.

Prerequisites

1. Install the SDK

bash
npm install @payre/pay

2. Get Your Secret Key

Sign up at console.payre.dev and copy your secret key from the Developer Settings page.

Your key looks like: pyr_sk_live_xxxxxxxxxxxxxxxx

Set it as an environment variable:

bash
export PAYRE_SECRET_KEY=pyr_sk_live_xxxxxxxxxxxxxxxx

3. Add Charging to Your Tool

ts
import { PayrePay } from '@payre/pay';

const payre = new PayrePay({
  secretKey: process.env.PAYRE_SECRET_KEY,
});

// In your MCP tool handler:
async function handleSearch(params, request) {
  // Charge before executing
  const receipt = await payre.charge({
    apiKey: request.headers['x-payre-key'],
    tool: 'search',
    amount: 0.005,  // $0.005 per call
  });

  // Your tool logic runs after payment succeeds
  const results = await doSearch(params.query);

  return {
    content: [{ type: 'text', text: JSON.stringify(results) }],
    _meta: { receipt },  // optional: include receipt in response
  };
}

If the consumer doesn't have enough balance, charge() throws with code: 'insufficient_balance'. If the API key is invalid, it throws with code: 'invalid_api_key'.

4. Multiple Tools? Use Pricing

If your server has multiple tools with different prices:

ts
const pricing = payre.pricing({
  'search':   0.005,   // $0.005 per search
  'generate': 0.02,    // $0.02 per generation
  'analyze':  0.01,    // $0.01 per analysis
});

// In each tool handler:
const receipt = await pricing.charge({
  apiKey: request.headers['x-payre-key'],
  tool: 'search',  // price looked up automatically
});

5. Tell Your Users

Your users need to:

  1. Sign up at console.payre.dev as a consumer
  2. Top up their balance (minimum $5, via Stripe Checkout)
  3. Copy their API key (pyr_ck_live_xxx)
  4. Add the key to their MCP client config:
json
{
  "mcpServers": {
    "your-server": {
      "url": "https://your-server.com/mcp",
      "headers": {
        "X-Payre-Key": "pyr_ck_live_xxx"
      }
    }
  }
}

Or pass it as a header in curl:

bash
curl -X POST https://your-server.com/mcp \
  -H "Content-Type: application/json" \
  -H "X-Payre-Key: pyr_ck_live_xxx" \
  -d '{"method": "tools/call", "params": {"name": "search", "arguments": {"query": "hello"}}}'

6. Check Your Earnings

Go to console.payre.dev -> Developer Dashboard to see:

  • Total earnings and today's revenue
  • Revenue breakdown by tool
  • Recent charges with timestamps and amounts

What Happens on Failure?

ts
try {
  const receipt = await payre.charge({ apiKey, tool: 'search', amount: 0.005 });
  // Success -- execute your tool
} catch (err) {
  switch (err.code) {
    case 'insufficient_balance':
      // Consumer needs to top up
      return { error: 'Please top up your balance at console.payre.dev' };
    case 'invalid_api_key':
      // Bad or missing API key
      return { error: 'Invalid API key. Get one at console.payre.dev' };
    case 'payre_unavailable':
      // Payre API is down -- your choice: fail or give free access
      return doSearch(params.query);  // graceful degradation
  }
}

Next Steps