关于 Robokassa Mcp
Robokassa Mcp 是面向支付集成的 Python 客户端和 MCP 服务,可连接 Robokassa 支付网关。它涵盖结账、支付状态、退款、预授权、周期扣款、财政收据及相关接口。
主要功能
- 01生成签名结账链接
- 02查询支付状态
- 03创建并查询退款
- 04管理银行卡预授权
- 05处理周期扣款
- 06支持财政收据和拆分支付
适用场景
- 01生成 Robokassa 结账链接
- 02确认支付是否完成
- 03发起或查询退款
- 04设置订阅扣款
MCP 相关
向 MCP 客户端提供 18 个 Robokassa 工具,涵盖结账、支付状态、退款、周期扣款、财政收据和 Webhook 签名校验。支持 stdio 和基于 HTTP 的传输方式。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
uvx robokassa-mcpROBOKASSA_LOGINMerchant login identifier for the Robokassa shop.ROBOKASSA_PASSWORD1密钥Shop's Password #1 — used for checkout URL signing, SuccessURL signature verification, CalcOutSumm, fiscal receipts, and SMS.ROBOKASSA_PASSWORD2密钥Shop's Password #2 — used for OpStateExt payment status checks and ResultURL signature verification.ROBOKASSA_PASSWORD3密钥Shop's Password #3 — used for Refund API (JWT HS256). Refund API access must be enabled in the cabinet.本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。
工具
18收录的工具列表 · 更新于 2 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| inv_id | integer | 是 | |
| algorithm | enum | 否 | md5 | sha256 | sha384 | sha512 |
| password2 | any | 否 | |
| merchant_login | any | 否 |
详细介绍
robokassa-mcp
📚 文档 · PyPI · Docker · MCP 注册表
面向 Robokassa(俄罗斯支付网关)的完整 Python 客户端和 Model Context Protocol 服务。
覆盖完整 API:结账、XML 状态接口、退款、预授权、定期订阅、54-ФЗ 财务收据、Partner API 和辅助端点。
安装(发布后)
# As an MCP server for Claude Desktop / Claude Code / Cursor / Windsurf
uvx robokassa-mcp
# As a Python library
pip install robokassa-mcp
作为 Python 库使用
import asyncio
from decimal import Decimal
from robokassa import create_invoice, RobokassaClient
# Build a signed checkout URL (no HTTP — just URL construction).
invoice = create_invoice(
merchant_login="my-shop",
out_sum=Decimal("599.00"),
inv_id=12345,
password1="...",
description="Premium subscription",
email="[email protected]",
)
print(invoice.url) # https://auth.robokassa.ru/Merchant/Index.aspx?...
# Check the state of a payment (hits the OpStateExt XML endpoint).
async def check() -> None:
async with RobokassaClient("my-shop", password2="...") as client:
state = await client.check_payment(inv_id=12345)
print(state.is_paid, state.info.op_key)
asyncio.run(check())
完整退款流程
from robokassa import RobokassaClient
async def refund_flow(inv_id: int) -> None:
async with RobokassaClient("my-shop", password2="p2", password3="p3") as client:
# 1. Fetch the payment state to get its OpKey.
state = await client.check_payment(inv_id)
assert state.info.op_key, "payment not complete yet"
# 2. Initiate a refund.
created = await client.refund_create(state.info.op_key)
print("refund requestId:", created.request_id)
# 3. Poll status until finished / canceled.
while True:
status = await client.refund_status(created.request_id)
if status.is_terminal:
print("final:", status.state)
break
Webhook 签名验证(FastAPI 示例)
from fastapi import FastAPI, Request, HTTPException, PlainTextResponse
from robokassa import verify_result_signature, build_ok_response
app = FastAPI()
@app.post("/robokassa/result")
async def result_url(req: Request) -> PlainTextResponse:
form = dict(await req.form())
if not verify_result_signature(form, password2="..."):
raise HTTPException(status_code=403, detail="Bad signature")
# ... persist the notification, mark invoice paid ...
return PlainTextResponse(build_ok_response(form["InvId"]))
作为 MCP 服务使用
Claude Desktop
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json(macOS)或 %APPDATA%\Claude\claude_desktop_config.json(Windows):
{
"mcpServers": {
"robokassa": {
"command": "uvx",
"args": ["robokassa-mcp"],
"env": {
"ROBOKASSA_LOGIN": "your-shop-login",
"ROBOKASSA_PASSWORD1": "password1",
"ROBOKASSA_PASSWORD2": "password2",
"ROBOKASSA_PASSWORD3": "password3"
}
}
}
}
Claude Code
claude mcp add robokassa \
-e ROBOKASSA_LOGIN=my-shop \
-e ROBOKASSA_PASSWORD1=... \
-e ROBOKASSA_PASSWORD2=... \
-e ROBOKASSA_PASSWORD3=... \
-- uvx robokassa-mcp
Cursor
编辑 ~/.cursor/mcp.json:
{
"mcpServers": {
"robokassa": {
"command": "uvx",
"args": ["robokassa-mcp"],
"env": {
"ROBOKASSA_LOGIN": "your-shop-login",
"ROBOKASSA_PASSWORD1": "password1",
"ROBOKASSA_PASSWORD2": "password2",
"ROBOKASSA_PASSWORD3": "password3"
}
}
}
}
VS Code(GitHub Copilot)
在用户或工作区的 settings.json 中:
{
"github.copilot.chat.mcp.servers": {
"robokassa": {
"command": "uvx",
"args": ["robokassa-mcp"],
"env": {
"ROBOKASSA_LOGIN": "your-shop-login",
"ROBOKASSA_PASSWORD1": "password1",
"ROBOKASSA_PASSWORD2": "password2",
"ROBOKASSA_PASSWORD3": "password3"
}
}
}
}
Windsurf
编辑 ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"robokassa": {
"command": "uvx",
"args": ["robokassa-mcp"],
"env": {
"ROBOKASSA_LOGIN": "your-shop-login",
"ROBOKASSA_PASSWORD1": "password1",
"ROBOKASSA_PASSWORD2": "password2",
"ROBOKASSA_PASSWORD3": "password3"
}
}
}
}
HTTP 传输(MCP Inspector、远程客户端)
uvx robokassa-mcp --transport http --port 8000
标志:--transport {stdio,http,streamable-http,sse}、--host、--port。
向 Agent 暴露的 MCP 工具
全部 18 个工具都封装为 @mcp.tool(),可供任何支持 MCP 的 Agent 使用(Claude Desktop、Claude Code、Cursor、Windsurf 等)。
| 工具 | 用途 | 身份验证 |
|---|---|---|
create_invoice | 构建经过签名的结账 URL(可选 54-ФЗ 收据)。 | Password#1 |
check_payment | 根据 InvId 获取付款当前状态(通过 OpStateExt)。 | Password#2 |
list_currencies | 列出商店可用的付款方式。 | — |
calc_out_sum | 计算指定付款中记入商店的金额。 | Password#1 |
refund_create | 发起退款(需要 Refund API 访问权限)。 | Password#3 JWT |
refund_status | 根据 requestId 查询退款进度。 | — |
verify_result_signature | 验证 ResultURL webhook。 | Password#2 |
verify_success_signature | 验证 SuccessURL 重定向。 | Password#1 |
hold_init / hold_confirm / hold_cancel | 两步式银行卡预授权。 | Password#1 |
init_recurring_parent / recurring_charge | 订阅自动扣款。 | Password#1 |
build_split_invoice | 面向多个收款方的电商平台结账。 | — |
send_sms | 付费短信服务。 | Password#1 |
second_receipt_create / second_receipt_status | 预付款后的 54-ФЗ 最终收据。 | Password#1 |
partner_refund | 面向合作伙伴集成商的备用退款路径。 | Partner JWT |
低级签名辅助函数仅可通过 Python 使用:compute_signature、op_state_signature、build_checkout_signature、build_refund_jwt、build_sms_signature、compute_result_signature、compute_success_signature、encode_fiscal_body。
API 覆盖范围
根据 Robokassa 的 8 个公开 API 组进行映射:
| 组 | 覆盖范围 | 模块 |
|---|---|---|
| 商户结账 | ✅ create_invoice(+ 54-ФЗ) | robokassa.checkout |
| XML 接口 | ✅ check_payment、list_currencies、calc_out_sum | robokassa.xml_interface |
| Refund API | ✅ refund_create、refund_status | robokassa.refund |
| 资金冻结 / 预授权 | ✅ 初始化 / 确认 / 取消 | robokassa.holding |
| 定期扣款 | ✅ 父项 + 子项 | robokassa.recurring |
| 财政 54-ФЗ | ✅ 创建 / 查询第二张收据 | robokassa.fiscal |
| 合作伙伴 API | 🟡 仅 partner_refund — 查看覆盖范围说明 | robokassa.partner |
| 辅助功能 | ✅ send_sms、webhook 签名、拆分付款 | robokassa.sms、robokassa.webhooks、robokassa.split |
环境变量
大多数高级入口点在未显式传入凭据时,会回退使用以下环境变量:
| 变量 | 用途 |
|---|---|
ROBOKASSA_LOGIN | 所有操作 |
ROBOKASSA_PASSWORD1 | 结账、webhook SuccessURL 验证、CalcOutSumm、财政功能、短信 |
ROBOKASSA_PASSWORD2 | check_payment(OpStateExt)、webhook ResultURL 验证 |
ROBOKASSA_PASSWORD3 | refund_create |
签名算法
所有生成签名的辅助函数都接受 algorithm=,可使用 "md5" / "sha256" / "sha384" / "sha512"——请与 Robokassa 控制面板中配置的算法保持一致。
开发
git clone https://github.com/artgas1/robokassa-mcp.git
cd robokassa-mcp
uv sync --all-extras --dev
uv run pytest # 107+ unit tests
uv run ruff check .
uv run pyright
许可证
MIT — 请参阅 LICENSE。维护方式为随用随弃;欢迎提交 PR,但不保证会及时审核。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。