Repository avatar
AI Tools
v0.2.0
active

llm-cost-router-mcp

io.github.talkingape/llm-cost-router-mcp

OpenRouter cost-optimal router, $0 free-tier scanner, and OpenAI gateway probe MCP server.

Documentation

LLM Cost-Router & AI Gateway Pulse MCP

Zero-dependency MCP Server (JSON-RPC 2.0 over stdio) + OpenRouter Cost-Optimal Router + OpenAI-Compatible Gateway Health Probe (sub2api / new-api / LiteLLM) with SQLite metering, HMAC-SHA256 / Payhip v2 licensing, and dual-chain x402 Native USDC support (X Layer eip155:196 + Base eip155:8453).

  • Companion Raycast Extension: AI Gateway Pulse (probes /v1/models latency, scans $0 high-context text models on OpenRouter, and copies MCP client config).
  • MCP Tools Exposed: list_free_high_context_models, recommend_cost_optimal_route, probe_openai_gateway, get_savings_and_entitlement.
  • Quickstart: python3 mcp_server.py --demo or python3 -m unittest discover -s . -p "test_*.py" -v.

Commercial Pro License ($29) & Starter Kit ($49)

  • Cost-Router MCP Pro ($29 lifetime · PayPal / Card instant license key): https://payhip.com/b/AgDFy
  • PayGate MCP Commercial Starter Kit ($49 · reusable Python MCP monetization boilerplate): https://payhip.com/b/TaM7u
  • Dual-Chain Native USDC x402 (0.01 USDC / 100 extra routes) payTo: 0x13523bEBaf8d054beB8470911F5A6d5275E7E60a
    • Primary: X Layer Mainnet (eip155:196, Circle Native USDC 0x74b7f16337b8972027f6196a17a631ac6de26d22)
    • Fallback: Base Mainnet (eip155:8453, Circle Native USDC 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913)
  • Activate Key: Pass your MCR1 or Payhip key via MCR_LICENSE_KEY environment variable or the tool argument license_key.

零第三方依赖的 MCP Server + 成本最优路由引擎 + OpenAI 兼容网关(sub2api / new-api / LiteLLM)健康探针 + Payhip(PayPal) / OKX Web3(x402) 商业化闸门。

文件结构

  • router_core.py:OpenRouter 实时定价加载与缓存、纯文本高上下文限免扫描、:free/:batch 价差分析、成本最优路由计算、OpenAI 兼容网关 /v1/models 只读探测、SQLite 配额计量 + MCR1 离线签名 Key(含可选过期校验)+ Payhip v2 在线校验与 SQLite 缓存 + HTTP 402 / x402 闸门。
  • generate_payhip_keys.py:Payhip 批量制卡 CLI,生成可直接粘贴/导入 Payhip「License Keys」的 txt(每行 1 个签名 Key)或审计 csv 文件,并与服务端校验完全兼容。
  • mcp_server.py:标准 MCP JSON-RPC 2.0 over stdio 服务端(暴露 list_free_high_context_models、recommend_cost_optimal_route、probe_openai_gateway、get_savings_and_entitlement 4 个工具),附带 --demo 一键实测模式。
  • test_mvp.py:自动化单测与集成测试套件(含本地网关探测、Payhip v2 在线校验与缓存、HTTP 402/x402 与钱包地址校验、批量制卡 CLI、子进程 MCP stdio 往返、OpenRouter 实时联网烟雾测试)。
  • pyproject.toml / glama.json / server.json:标准 MCP Registry、Glama 与 Python 包生态索引清单。

环境变量配置(运维说明)

变量名说明默认值 / 示例
MCR_LICENSE_SECRETMCR1 离线签名密钥(部署时务必通过环境变量注入强随机密钥)开发演示默认值
MCR_LICENSE_KEY客户持有的 MCR1... 或 Payhip License Key空
MCR_PAYHIP_CHECKOUT_URLPayhip Pro 结账链接(PayPal / Card 即时发卡)https://payhip.com/b/AgDFy
MCR_PAYHIP_PRODUCT_SECRETPayhip 商品高级设置中的 product-secret-key(开启在线校验与退款吊销)空
MCR_X402_RECIPIENTOKX Web3 自托管钱包 EVM 收款地址(支持 X Layer + Base 双链原生 USDC,可通过环境变量覆盖)0x13523bEBaf8d054beB8470911F5A6d5275E7E60a

x402 双链原生 USDC 支持

HTTP 402 回包同时输出 accepts 数组:

  1. 首选 X Layer Mainnet(network: "xlayer-mainnet", chainId: "eip155:196", Circle Native USDC 0x74b7f16337b8972027f6196a17a631ac6de26d22")
  2. 备选 Base Mainnet(network: "base-mainnet", chainId: "eip155:8453", Circle Native USDC 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913")

一键运行与测试

1. 运行自动化测试套件

PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s . -p "test_*.py" -v

2. 批量生成可导入 Payhip 的签名 License Key

MCR_LICENSE_SECRET="your-production-secret" \
python3 generate_payhip_keys.py \
  --count 100 --tier pro --prefix payhip --format txt --output payhip_keys.txt

如需生成 30 天订阅版或导出审计表,可加 --days 30 与 --format csv。

3. 运行实时联网端到端演示

PYTHONDONTWRITEBYTECODE=1 python3 mcp_server.py --demo

客户端挂载配置(Claude Code / Cursor / Raycast MCP)

{
  "mcpServers": {
    "llm-cost-router": {
      "command": "python3",
      "args": [
        "/path/to/llm-cost-router-mcp/mcp_server.py"
      ],
      "env": {
        "MCR_LICENSE_KEY": "",
        "MCR_PAYHIP_CHECKOUT_URL": "https://payhip.com/b/AgDFy",
        "MCR_X402_RECIPIENT": "0x13523bEBaf8d054beB8470911F5A6d5275E7E60a"
      }
    }
  }
}
MCPB
https://github.com/talkingape/llm-cost-router-mcp/releases/download/v0.2.0/llm-cost-router-mcp.mcpb
Install Command
# mcpb: https://github.com/talkingape/llm-cost-router-mcp/releases/download/v0.2.0/llm-cost-router-mcp.mcpb