
Tollbooth Sample
io.github.lonniev由 GitHub 账号 lonniev 发布v0.5.0更新于 Nov 4, 2026
Educational Weather Stats MCP Service — Tollbooth DPYC monetization sample
概览
一个示例天气统计 MCP 服务,封装 Open-Meteo,并按次以比特币闪电网络积分计费,用于演示 Tollbooth DPYC 变现方案。
- 可以做什么
- 按经纬度查询当前天气、多日预报和历史天气
- 查询积分余额、通过闪电网络购买积分并查看发票状态
- 在花费积分前预览工具价格与约束规则的影响
- 申请被 Authority 接纳,并获取 DPYC 入门说明、税率、成员与网络公告信息
- 查看服务健康状态与约束配置
- 适用场景
- 适合想端到端体验带付费机制的 MCP 服务,或把它当作模板,将自己的 API 包装成 Tollbooth DPYC 付费工具。若只是查询天气,免费的 Open-Meteo API 更简单。
- 运行要求
- 通过 streamable HTTP 访问的远程端点,需要 OAuth 登录。付费工具需要用以太坊闪电网络购买的积分余额,以及连接可证明持有的 Nostr 密钥对(npub);在本地 STDIO 模式下付费工具会被拒绝。
安装
在 SourceWeft 中
- 打开 控制台中的 Tollbooth Sample,将其添加到工作区。
- 连接 所需的 凭据。它们会被私密存储,绝不会在公开页面上展示。
- 为需要使用其工具的对话启用该服务。
Web executable,通过 Streamable HTTP。 远程服务在工作区中配置后即可从网页运行时运行。
交给智能体安装
把这段提示词粘贴到 Claude Code、Codex、Cursor 等智能体,或 SourceWeft 对话中。智能体会读取该服务器的安装指南,先向你展示发布者、端点和登录方式,经你同意后再把它添加到你的客户端。密钥不会写进任何命令。
阅读 https://sourceweft.com/mcp/io.github.lonniev%2Ftollbooth-sample/install.md,并按其中说明把这个 MCP 服务器接入我的客户端。修改任何配置之前,先告诉我它的发布者、端点和登录方式,等我确认。不要把 API 密钥写进命令或我会提交的文件;问我密钥应从哪里获取。其他 MCP 客户端
把它添加到你客户端的 mcpServers 配置中。 客户端会在首次连接时完成 OAuth 登录。
{
"mcpServers": {
"tollbooth-sample": {
"type": "http",
"url": "https://tollbooth-sample.fastmcp.app/mcp"
}
}
}README
tollbooth-sample
Educational Weather Stats MCP Service — the reference implementation for building Tollbooth DPYC monetized API services with Bitcoin Lightning micropayments.
This service wraps the free Open-Meteo weather API
and gates paid tool calls through the Tollbooth
credit system using the @runtime.paid_tool() decorator. Domain tools contain
only business logic; debit, rollback, balance warnings, and constraint evaluation
are handled automatically by the OperatorRuntime. Standard DPYC tools
(balance, purchase, Secure Courier, Oracle, pricing, constraints) are delegated
to the wheel via register_standard_tools().
Build your own operator — the bootstrap-dpyc-operator skill
This repo doubles as a Claude Code plugin. The bootstrap-dpyc-operator skill turns your
existing REST API, stdio MCP, or HTTP MCP into a monetized DPYC Operator MCP: it clones this
template live, wraps your domain logic, and generates a deploy-ready project. You keep writing
business logic — the SDK handles payments, identity, vault, audit, and pricing.
Install it in Claude Code:
Then ask Claude to "make my API a paid DPYC operator" — the skill activates automatically by
its description. It never touches your original code (it emits a sibling <slug>-mcp/ project)
and reads this repo's live wheel pin on every run, so it can't go stale.
See skills/bootstrap-dpyc-operator/ for the skill and its
reference guides (canonical pattern, source adapters, sessions & vaults, onboarding checklist).
The DPYC Economy
DPYC stands for Don't Pester Your Customer. It's a philosophy and protocol for API monetization that eliminates mid-session payment popups, subscription nag screens, and KYC friction.
How it works
-
Pre-funded balances — Users buy credits via Bitcoin Lightning before using tools. Each tool call silently debits from their balance. No interruptions, no "please upgrade" modals.
-
Nostr keypair identity — Users are identified by a Nostr public key (
npub), not an email or password. One keypair per role, managed by the user. No account creation forms. -
UUID-keyed tool identity — Every tool is a
ToolIdentityobject with a deterministic UUID v5 derived from a capability name. Pricing hints come from thecategoryfield:Actual prices are set dynamically by the operator's pricing model in Neon.
-
Rollback on failure — If the downstream API fails after a debit, credits are automatically rolled back via a compensating tranche. The user never pays for a failed call.
-
Social Contract — The DPYC ecosystem is a voluntary community bound by transparent, auditable economic rules, with a Certification Chain that cascades trust from the root:
- Citizens — Users who consume API services
- Operators — Developers who run MCP services (like this one)
- Authorities — Certify operators and collect a small tax on purchases
- First Curator — The root of the chain, mints the initial cert-sat supply
How Tollbooth Monetization Works
ToolIdentity and the frozen tool_id
Each domain tool is registered as a ToolIdentity with a frozen tool_id
(an opaque UUID), a capability name, a category (pricing hint), and an intent
description. Mint the UUID once at the tool's birth — run
capability_uuid("get_current_weather") at a REPL (or uuid.uuid4()), then
paste the result as a literal constant and never change it again. Freezing the
literal is what lets you rename a capability later without orphaning its pricing
rows in Neon. Do not call capability_uuid(...) at runtime; the identity
must live in exactly one place:
The @runtime.paid_tool() decorator
Every paid tool is a single decorator away from full DPYC monetization.
The decorator takes the tool's frozen tool_id constant and handles debit,
balance checks, constraint evaluation, rollback on failure, and low-balance
warnings automatically. Your tool function contains only domain logic:
That is the complete paid tool. No manual debit calls, no try/except rollback blocks, no balance-warning plumbing. The decorator:
- Looks up the tool's pricing from the
ToolIdentityregistry by UUID - Extracts
npubfrom the function arguments for billing - Checks that the connection proves that npub (a signed request, or an OAuth connection that holds it)
- Debits before calling your function (walking the tool's constraint chain from the pricing model)
- Rolls back automatically if your function raises an exception
- Appends a low-balance warning to the response when funds are running low
Key patterns
register_standard_tools(mcp, "weather", runtime, …) — Registers all
standard DPYC tools (balance, purchase, payment, pricing, Secure Courier,
Oracle, constraints) from the tollbooth-dpyc wheel, mounts oracle
delegations under <slug>_oracle_*, and returns the slug-prefixed
@tool decorator. Capture the return so you can use the same decorator
for your own paid tools — every wire-exposed name on this operator then
shares one slug prefix.
validate_btcpay_creds — Credential validator that checks BTCPay
credentials at receive time, not at first use. Invalid credentials are
rejected immediately during the Secure Courier exchange.
CredentialTemplate — Declares the operator's required secrets
(BTCPay host, API key, store ID) so the Secure Courier flow can prompt
for the right fields and validate them on delivery.
The npub parameter
Every paid tool must accept an npub keyword argument. It tells the runtime
which patron to bill; the connection proves the caller holds it. Use the SDK's
PatronNpub type so every operator describes it the same way:
A paid tool called with an empty or invalid npub is refused (npub is required)
before your function runs.
What the runtime handles under the hood
Constraint Engine
Constraints are dynamic pricing steps that live in the operator's pricing model:
each tool's chain in the model lists the steps the ConstraintGate walks on every
call, and coupons bound to the tool are added after them. Author them in
Pricing Studio or with
weather_set_pricing_model; nothing is switched on by environment variable.
Common constraint types (the SDK registry holds more — weather_list_constraint_types
enumerates the full set live):
Use weather_check_price to preview constraint effects without spending credits —
it walks exactly the chain the debit will.
Becoming an Operator
New to Tollbooth? See GETTING-STARTED.md for a step-by-step guide covering Nostr keypair setup, Authority enrollment, BTCPay configuration, and deploying your first monetized MCP service.
Quick Start
Local development
This serves over STDIO. There is no development bypass: paid tools are gated exactly as in production, and the patron's npub is proven by the HTTP connection (a NIP-98 signed request or an OAuth holder bearer), so over STDIO a paid tool is refused. Exercise paid tools against a deployed instance.
Deploy on Prefect Horizon
The hosting platform is Prefect Horizon (FastMCP is the runtime/framework the server is built on).
- Push to GitHub
- Connect the repo on Prefect Horizon
- Set environment variables:
TOLLBOOTH_NOSTR_OPERATOR_NSEC— Nostr key for identity bootstrap (the only env var the operator needs; the Neon database URL arrives from your Authority over Nostr, the relay set comes from the shared dpyc-community registry, and all other secrets are delivered via Secure Courier credential templates)
Horizon reads the entrypoint and dependencies from fastmcp.json.
Heads-up for operators with long-running tools. By default, claim-check / async jobs run in-memory (
async_jobs.backend: "memory (default)"), which means they do not survive a Horizon recycle (durable_across_recycles: false). That's fine for this reference sample, which has no long-runners — but if you add a tool that defers work to a background job, pin the tollbooth-dpyc[modal]extra, spreadLONGRUNNER_CREDENTIAL_FIELDSinto your operator credential template, and deliver the durable-executor secrets (modal_token_id/modal_token_secret/modal_app_name) via Secure Courier so jobs settle across redeploys. Check your live state anytime withservice_status.async_jobs.
Run tests
Tool Reference
The three weather tools are this operator's own; the rest come from
register_standard_tools() and include identity (weather_request_npub_proof,
weather_receive_npub_proof), Secure Courier, pricing, coupons, and notarization
tools. weather_get_operator_onboarding_status reports what is still missing.
DPYC Ecosystem
Core
- tollbooth-dpyc — Python SDK (vault, auth, pricing, Lightning, Nostr identity)
- dpyc-community — Governance registry: membership, advisories, threat model
- dpyc-oracle — Community concierge (free onboarding + member lookup)
- tollbooth-authority — Certification backbone (Schnorr-signed certificates)
- tollbooth-sample — Sample Operator (this canonical template)
- tollbooth-pricing-studio — iOS pricing-model editor / operator console
Operators
- cypher-mcp — Monetized graph answers: named Cypher templates over Neo4j/AuraDB
- schwab-mcp — Charles Schwab brokerage data
- thebrain-mcp — TheBrain personal knowledge graph
- excalibur-mcp — X/Twitter posting
- taxsort-mcp — Tax classification + Cloudflare Pages UI
- optionality-mcp — Options analytics (brokerage-data operator)
- goodearth-mcp — Climate analytics for small specialty-crop farms
- beesknees-mcp — The Bee's Knees, a monetized multiplayer race game
- roastify-mcp — Roastify coffee catalog and packaging artwork
- ChartRemotely-mcp — Puts a security on a desktop chart, by voice or tool call
Advocates & utilities
- tollbooth-oauth2-collector — OAuth2 callback handler (advocate service)
- tollbooth-shortlinks — URL shortener utility
- tollbooth-web — Shared browser SDK for operator front ends
License
Apache-2.0
来源:README.md,提交 8656a22
工具
0版本历史
2- v0.5.0最新Oct 21, 2026
- v0.4.9Sep 16, 2026
评分
已满足适用检查项的 85%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通必需25 分
- 已声明认证方式必需10 分
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分