agentleFS
CloudflareKnown publishercloudflare/mpp-proxy/AGENTS.md

mpp-proxy

AGENTS.md65 starsChanged 9 months agoApache-2.0View on GitHub

Context for AI coding agents helping users set up this MPP payment-gated proxy template. A Cloudflare Worker that adds payment gating to any origin using the Machine Payments Protocol (MPP). With Bot Management Filtering: Requires Bot Management for Enterprise to enable bot filtering. When enabled, humans can pass through free while likely automated traffic must pay. This is optional and enhances the base functionality. This template is currently wired to the Tempo payment method via mppx. When a user asks…

  • Reads credentials
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

27 rules. About 0 are common, 14 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When a user asks for help setting up the proxy, follow this discovery process.

    line 22
  2. Very specific:

    If not logged in, guide them to run npx wrangler login.

    line 30
  3. Distinctive:

    If they have multiple accounts, note them for Step 2.

    line 32
  4. Distinctive:

    Ask: "Which domain do you want to add payment gating to?"

    line 38
  5. Distinctive:

    If the user has multiple Cloudflare accounts, also ask: "Which account is this domain on?"

    line 40
  6. Very specific:

    Ask: "Do you have Bot Management enabled on {domain}?"

    line 48
  7. Very specific:

    Ask: "What path on {domain} do you want to charge for?"

    line 65
  8. Distinctive:

    If the user provides multiple paths at once, queue them and configure each in sequence.

    line 67
  9. Very specific:

    Ask: "What amount should {path} cost?"

    line 73
  10. Very specific:

    Ask: "What description should users see for {path}?"

    line 81
  11. Very specific:

    Ask: "What bot score threshold should {path} use?"

    line 87
  12. Very specific:

    If the user selects a preset or specific bot names, resolve them using the Bot Registry below and write the resulting IDs to …

    line 107
  13. Very specific:

    Ask: "Any more paths on {domain} to protect?"

    line 120
  14. Distinctive:

    If yes, repeat Step 4

    line 122
  15. Distinctive:

    If the user does not have a wallet address yet, they can use the default dead address for smoke testing:

    line 153
  16. Distinctive:

    Write the complete configuration for this MPP template.

    line 190
  17. Very specific:

    Use amount, not price

    line 240
  18. Very specific:

    Do not configure FACILITATOR_URL or NETWORK.

    line 241
  19. Very specific:

    If Tempo RPC access requires authentication, also set an authenticated RPC URL so server-side verification and transaction broadcast do not …

    line 262
  20. Distinctive:

    Use when the origin is a traditional server

    line 302
  21. Distinctive:

    Use when the origin is another public service or Worker you do not want to modify

    line 311
  22. Distinctive:

    Use when the origin is another Worker in the same account and you want the best performance

    line 320
  23. Distinctive:

    Use this registry when converting human-readable bot names to detection IDs.

    line 348
  24. Distinctive:

    Remove the route from the old Worker

    line 452
  25. Very specific:

    Use npx wrangler tail to inspect request metadata after deployment.

    line 486
  26. Very specific:

    Before running npm run deploy, verify:

    line 511
  27. Distinctive:

    If using Bot Management Filtering:

    line 524

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

mpp-proxy Setup Guide for AI Agents

Context for AI coding agents helping users set up this MPP payment-gated proxy template.

What is mpp-proxy?

A Cloudflare Worker that adds payment gating to any origin using the Machine Payments Protocol (MPP).

  • Protected routes return 402 Payment Required with WWW-Authenticate: Payment
  • Clients retry with Authorization: Payment
  • Successful responses include Payment-Receipt
  • The proxy also issues a JWT cookie valid for 1 hour so browsers and agents can reuse access without paying again on every request

With Bot Management Filtering: Requires Bot Management for Enterprise to enable bot filtering. When enabled, humans can pass through free while likely automated traffic must pay. This is optional and enhances the base functionality.

This template is currently wired to the Tempo payment method via mppx.


Interactive Setup Flow

When a user asks for help setting up the proxy, follow this discovery process.

Step 1: Verify Cloudflare Authentication

npx wrangler whoami

If not logged in, guide them to run npx wrangler login.

If they have multiple accounts, note them for Step 2.


Step 2: Select Domain

Ask: "Which domain do you want to add payment gating to?"

If the user has multiple Cloudflare accounts, also ask: "Which account is this domain on?"

Save the domain. It scopes the rest of setup.


Step 3: Check for Bot Management (Optional Enhancement)

Ask: "Do you have Bot Management enabled on {domain}?"

Explain why:

With Bot Management enabled, the proxy can implement a default-closed model for bots: likely human traffic passes free, while likely automated traffic must pay. You can also allow specific bots like Googlebot or verified AI assistants through for free.

Without Bot Management, the proxy still works perfectly. All traffic to protected routes must pay.

AnswerEffect
YesEnable Bot Management prompts in Step 4
NoSkip threshold/exception prompts in Step 4

Step 4: Configure Protected Paths (Iterative)

Ask: "What path on {domain} do you want to charge for?"

If the user provides multiple paths at once, queue them and configure each in sequence.

For each path, ask:

4.1 Amount

Ask: "What amount should {path} cost?"

Format: 0.01, 0.10, 1.00, etc.

Important: this template stores the value as amount, not price.

4.2 Description

Ask: "What description should users see for {path}?"

Example: Access to premium content for 1 hour

4.3 If Bot Management is enabled

Ask: "What bot score threshold should {path} use?"

Offer exactly these three options:

OptionThresholdMeaning
11Very strict - only verified humans pass free
22Strict - only clear human traffic passes free
30 (Recommended)30Balanced - likely automated traffic must pay, humans pass free

Then ask: "Any bots that should get FREE access to {path}?"

Offer these presets:

PresetBots IncludedUse When
Googlebot + BingBotGooglebot, BingBotAllow major crawlers
Above + AI assistantsAbove + ChatGPT-User, Claude-User, Perplexity-User, Meta-ExternalFetcherAllow AI assistant citations
None(empty)All bots must pay

If the user selects a preset or specific bot names, resolve them using the Bot Registry below and write the resulting IDs to except_detection_ids.

Example:

"except_detection_ids": [
  120623194, // Googlebot
  117479730  // BingBot
]

4.4 More paths

Ask: "Any more paths on {domain} to protect?"

  • If yes, repeat Step 4
  • If no, continue

Step 5: Wallet and Tempo Configuration

Ask these together:

  1. "What wallet address should receive payments (PAY_TO)?"
  2. "Use Tempo testnet or production?"

Map the answer to config like this:

User ChoiceTEMPO_TESTNET
Testnettrue
Productionfalse

Then ask:

  1. "Which token address should clients pay in (PAYMENT_CURRENCY)?"

Recommended default for demos:

0x20c000000000000000000000b9537d11c60e8b50

That is the default PathUSD address used by this template for Tempo testnet demos.

If the user does not have a wallet address yet, they can use the default dead address for smoke testing:

0x000000000000000000000000000000000000dEaD

Deployment Phase

Now that config is complete, discover infrastructure and deploy.

Step 6: Discover Existing Workers and Routes

npx wrangler deployments list
npx wrangler routes list --zone {domain}

This reveals:

  • what Workers are already deployed
  • whether another Worker already owns routes on the domain

Determine deployment mode:

SituationRecommended Mode
Origin is a traditional serverStandard Proxy Mode
Origin is an external API or serviceExternal Origin Mode
Origin is another Worker in the same accountService Binding Mode
Existing Worker already owns domain/*External Origin Mode or Service Binding Mode

Step 7: Generate wrangler.jsonc

Write the complete configuration for this MPP template.

Basic example:

{
  "routes": [
    { "pattern": "example.com/premium/*", "zone_name": "example.com" },
  ],
  "vars": {
    "PAY_TO": "0x000000000000000000000000000000000000dEaD",
    "TEMPO_TESTNET": true,
    "PAYMENT_CURRENCY": "0x20c000000000000000000000b9537d11c60e8b50",
    "PROTECTED_PATTERNS": [
      {
        "pattern": "/premium/*",
        "amount": "0.01",
        "description": "Access to premium content for 1 hour",
      },
    ],
  },
}

With Bot Management Filtering:

{
  "routes": [
    { "pattern": "example.com/content/*", "zone_name": "example.com" },
  ],
  "vars": {
    "PAY_TO": "0x000000000000000000000000000000000000dEaD",
    "TEMPO_TESTNET": true,
    "PAYMENT_CURRENCY": "0x20c000000000000000000000b9537d11c60e8b50",
    "PROTECTED_PATTERNS": [
      {
        "pattern": "/content/*",
        "amount": "0.25",
        "description": "Content access for 1 hour",
        "bot_score_threshold": 30,
        "except_detection_ids": [120623194, 117479730],
      },
    ],
  },
}

Notes:

  • Use amount, not price
  • Do not configure FACILITATOR_URL or NETWORK; those were x402-era concepts and are not used by this repo anymore
  • This repo uses Tempo through mppx

Step 8: Set Secrets

This repo requires two secrets.

Set the JWT secret:

openssl rand -hex 32 | npx wrangler secret put JWT_SECRET

Set the MPP challenge secret:

openssl rand -hex 32 | npx wrangler secret put MPP_SECRET_KEY

If Tempo RPC access requires authentication, also set an authenticated RPC URL so server-side verification and transaction broadcast do not fall back to https://rpc.tempo.xyz/:

printf '%s' 'https://user:pass@rpc.mainnet.tempo.xyz/' | npx wrangler secret put TEMPO_RPC_URL

Step 9: Deploy

npm run deploy

Step 10: Verify

curl https://{domain}/__mpp/health
# Should return: {"status":"ok",...}

curl https://{domain}/__mpp/config
# Should show token, wallet suffix, and protected patterns

For a real payment test, use the MPP CLI:

npx mppx https://{domain}/__mpp/protected

Deployment Modes

Standard Proxy Mode (DNS-based)

  • The proxy owns the route, e.g. api.example.com/*
  • Protected paths require MPP payment; everything else passes through
  • Use when the origin is a traditional server
User -> mpp-proxy -> Origin Server

External Origin Mode

  • The proxy owns the route and rewrites requests to ORIGIN_URL
  • Use when the origin is another public service or Worker you do not want to modify
"ORIGIN_URL": "https://my-existing-service.example.com"

Service Binding Mode

  • The proxy calls the origin Worker through ORIGIN_SERVICE
  • Use when the origin is another Worker in the same account and you want the best performance
"services": [{ "binding": "ORIGIN_SERVICE", "service": "my-origin-worker" }]

Bot Management Filtering Reference

Requires Bot Management for Enterprise.

When enabled:

  • humans can pass for free
  • excepted bots can pass for free
  • everyone else must pay

Threshold Reference

ThresholdMeaningUse Case
1Very strict - only verified humans pass freeMaximum monetization
2Strict - only clear human traffic passes freeHigh-value APIs
30Balanced - likely automated must pay, humans pass freeRecommended default

Bot Registry Reference

Use this registry when converting human-readable bot names to detection IDs.

Google

Bot NameDetection IDNotes
Googlebot120623194Google Search
Google-CloudVertexBot133730073Google AI training

Microsoft

Bot NameDetection IDNotes
BingBot117479730Microsoft Bing

OpenAI

Bot NameDetection IDNotes
GPTBot123815556OpenAI training
ChatGPT-User132995013ChatGPT browsing mode
ChatGPT agent129220581ChatGPT agents/plugins
OAI-SearchBot126255384OpenAI Search

Anthropic

Bot NameDetection ID
ClaudeBot33563859
Claude-SearchBot33564301
Claude-User33564303

Perplexity

Bot NameDetection ID
PerplexityBot33563889
Perplexity-User33564371

Meta

Bot NameDetection ID
Meta-ExternalAgent124581738
Meta-ExternalFetcher132272919
FacebookBot33563972

Configuration Reference

Required vars

VariableDescription
PAY_TOWallet address receiving payment
TEMPO_TESTNETTempo testnet toggle
PAYMENT_CURRENCYToken address clients pay in
PROTECTED_PATTERNSArray of protected path configs

Required secrets

VariableDescription
JWT_SECRETSecret for auth cookies
MPP_SECRET_KEYSecret for signing MPP challenges
TEMPO_RPC_URLOptional authenticated Tempo RPC URL

Protected pattern schema

{
  pattern: string
  amount: string
  description: string
  bot_score_threshold?: number
  except_detection_ids?: number[]
}

Optional vars

VariableDescription
ORIGIN_URLExternal origin URL
ORIGIN_SERVICEService binding to another Worker

Debug endpoints

  • /__mpp/health - health check
  • /__mpp/config - sanitized runtime config
  • /__mpp/protected - built-in paid route for testing

Common Issues

Another Worker already owns the route

Wrangler may fail with a route conflict.

Fix:

  1. Identify the existing route owner with npx wrangler routes list --zone <domain>
  2. Remove the route from the old Worker
  3. Redeploy this proxy

Alternative: keep the old Worker live and point ORIGIN_URL at it.

JWT_SECRET or MPP_SECRET_KEY not set

Protected routes will fail with 500 until both secrets are created.

402 works but content fails

The payment layer is fine; the origin is failing. Test the origin directly.

Homepage shows the built-in demo instead of the origin

This repo ships with public/index.html for demos. If you want the root path to proxy to your origin, comment out or remove the assets block in wrangler.jsonc.

Bot Management Filtering warning about cf.botManagement

This means Bot Management data is not available.

Causes:

  • Bot Management for Enterprise is not enabled
  • the request is from local development, where bot signals are unavailable

Human traffic still gets 402

Check that:

  1. bot_score_threshold is set
  2. Bot Management is enabled on the zone
  3. The score is actually above the threshold

Use npx wrangler tail to inspect request metadata after deployment.


Testing Locally

echo "JWT_SECRET=$(openssl rand -hex 32)" > .dev.vars
echo "MPP_SECRET_KEY=$(openssl rand -hex 32)" >> .dev.vars
npm run dev

curl http://localhost:8787/__mpp/health
curl http://localhost:8787/__mpp/protected

Then try an MPP client flow:

npx mppx http://localhost:8787/__mpp/protected

Pre-Deploy Checklist

Before running npm run deploy, verify:

  • routes matches the correct domain and path
  • PAY_TO is set correctly
  • PAYMENT_CURRENCY is set correctly
  • TEMPO_TESTNET matches testnet vs production intent
  • PROTECTED_PATTERNS uses amount, not price
  • JWT_SECRET exists
  • MPP_SECRET_KEY exists
  • TEMPO_RPC_URL is set if your Tempo RPC requires authentication
  • assets is commented out if you want full proxy behavior at /
  • ORIGIN_SERVICE or ORIGIN_URL is configured if DNS-based origin routing is not correct

If using Bot Management Filtering:

  • Bot Management is enabled
  • bot_score_threshold is set on relevant paths
  • except_detection_ids are resolved correctly

Additional Resources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.