anthropics / anthropics/claude-cookbooks
Sharing: 4 production MCP servers with separated 'Agent Pricing' tier — reproducible pattern
- 主要语言
- Jupyter Notebook
- 星标
- 52.7k
- 派生
- 6.3k
- 平均合并
- 25 分钟
- 30 天内合并 PR
- 6
描述
Hi cookbook team — sharing a pattern that might be worth a recipe entry.
## The pattern
When wrapping a production SaaS as an MCP server, the obvious approach (reuse the same API key + same monthly plan) breaks badly because agent traffic patterns are very different from human traffic.
I shipped **separate "Agent Pricing" Stripe products** for 4 of my production SaaS, so AI agent calls are metered independently of the human Web subscription. The pattern is reproducible in any SaaS that already uses Stripe + a relational DB.
## Repos (all MIT)
- [airlogicpro-mcp](https://github.com/Shown06/airlogicpro-mcp) — App Store opportunity scoring
- [aimieru-mcp](https://github.com/Shown06/aimieru-mcp) — Japanese AIO citation diagnosis
- [paperbotai-mcp](https://github.com/Shown06/paperbotai-mcp) — Multi-channel manual RAG
- [tamawaru-mcp](https://github.com/Shown06/tamawaru-mcp) — Japanese subsidy search
## Key implementation details
### Bearer auth + SHA-256 hash storage
\`sk_live_\` + 24 byte base64url + SHA-256 hash, prefix-display only on dashboard. Standard pattern but worth showing in cookbook form.
### Atomic counter via PostgreSQL SECURITY DEFINER function
The naive approach (SELECT + UPDATE) has a stale-read bug under concurrent agent calls. The fix:
\`\`\`sql
CREATE OR REPLACE FUNCTION increment_agent_calls(key_id uuid)
RETURNS integer LANGUAGE plpgsql SECURITY DEFINER AS \$\$
DECLARE current_count integer;
BEGIN
UPDATE api_keys
SET agent_monthly_calls = agent_monthly_calls + 1,
updated_at = now()
WHERE id = key_id
RETURNING agent_monthly_calls INTO current_count;
RETURN current_count;
END;
\$\$;
\`\`\`
### Stripe webhook \`metadata.kind = "agent_subscription"\` branch
Separates Agent Pricing from Web Pricing so each can be upgraded/downgraded independently.
### llms.txt + /agents page
Helps AI crawlers (Perplexity, ChatGPT search) discover the MCP entry point deterministically.
## Could become
- \`tool_use/mcp_with_agent_pricing/\` recipe in this cookbook
- An \`examples/\` reference in [modelcontextprotocol/servers](https://github.com/modelcontextprotocol/servers)
Happy to extract a self-contained reference implementation as a PR if there's interest.
— [Shown](https://github.com/Shown06) / ReFlow Inc., Tokyo / [@asab0077](https://x.com/asab0077)
贡献指南
评估
这个 Issue 还没有评估数据。