bug-ops/tap-mcp-bridge
GitHub: bug-ops/tap-mcp-bridge
一个用 Rust 编写的 MCP 服务器和库,将 Visa TAP 协议与 Anthropic MCP 桥接,使 AI 代理能安全认证并执行支付交易。
Stars: 3 | Forks: 0
# TAP-MCP Bridge
[](https://crates.io/crates/tap-mcp-bridge)
[](https://docs.rs/tap-mcp-bridge)
[](https://github.com/bug-ops/tap-mcp-bridge/actions)
[](https://codecov.io/gh/bug-ops/tap-mcp-bridge)
[](LICENSE)
Rust 库和 MCP 服务器,用于 Visa 的 Trusted Agent Protocol (TAP),使 AI 代理能够与商户进行安全认证并执行支付交易。
## 工作区结构
| Crate | 类型 | 描述 |
|-------|------|-------------|
| [`tap-mcp-bridge`](tap-mcp-bridge/) | 库 | RFC 9421 签名,JWE 加密,TAP 协议 |
| [`tap-mcp-server`](tap-mcp-server/) | 二进制 | 为 Claude 和其他 AI 代理暴露 TAP 工具的 MCP 服务器 |
## 安装
### 作为库使用
```
[dependencies]
tap-mcp-bridge = "0.3"
```
### 作为 MCP 服务器
```
cargo install --path tap-mcp-server
```
配置你的 MCP 客户端(Claude Desktop 等):
```
{
"mcpServers": {
"tap": {
"command": "tap-mcp-server",
"env": {
"TAP_AGENT_ID": "your-agent-id",
"TAP_AGENT_DIRECTORY": "https://your-agent-directory.com",
"TAP_SIGNING_KEY": "64-hex-characters-ed25519-key"
}
}
}
}
```
## 快速示例
```
use ed25519_dalek::SigningKey;
use tap_mcp_bridge::tap::{InteractionType, TapSigner};
let signing_key = SigningKey::from_bytes(&[0u8; 32]);
let signer = TapSigner::new(signing_key, "agent-123", "https://agent.example.com");
let signature = signer.sign_request(
"POST",
"merchant.example.com",
"/checkout",
b"request body",
InteractionType::Checkout,
)?;
println!("Signature: {}", signature.signature);
println!("Signature-Input: {}", signature.signature_input);
```
## MCP 工具
服务器为 AI 代理提供以下工具:
| 工具 | 描述 |
|------|-------------|
| `checkout_with_tap` | 使用 TAP 认证执行支付 |
| `browse_merchant` | 使用已验证身份浏览商户目录 |
| `verify_agent_identity` | 健康检查和代理验证 |
| `get_products` | 带过滤器浏览产品目录 |
| `get_product` | 获取单个产品详情 |
| `add_to_cart` | 将商品加入购物车 |
| `get_cart` | 获取当前购物车状态 |
| `update_cart_item` | 更新商品数量 |
| `remove_from_cart` | 从购物车中移除商品 |
| `create_order` | 从购物车创建订单 |
| `get_order` | 获取订单状态 |
| `process_payment` | 使用 APC 加密完成支付 |
## 功能特性
### TAP 协议
- **RFC 9421** HTTP 消息签名(使用 Ed25519)
- **RFC 7516** 用于支付数据的 JWE 加密(A256GCM + RSA-OAEP-256)
- **RFC 7638** 用于密钥识别的 JWK Thumbprints
- **ID Tokens** (JWT) 用于消费者认证
- **ACRO** — Agentic Consumer Recognition Object
- **APC** — 使用 JWE 加密的 Agentic Payment Container
### 商户抽象
基于 trait 的抽象实现灵活的商户 API 集成:
```
use tap_mcp_bridge::{DefaultMerchant, MerchantApi};
// Standard TAP merchant
let merchant = DefaultMerchant::new();
// Custom merchant from TOML configuration
let merchant = DefaultMerchant::from_toml(r#"
name = "ACME Store"
base_url = "https://api.acme.com"
api_prefix = "/api/v2"
[endpoints]
products = "/catalog/items"
cart = "/basket"
[field_mappings.request]
consumer_id = "customerId"
product_id = "sku"
"#)?;
```
### 传输抽象
支持多种协议的可插拔传输层:
```
use tap_mcp_bridge::transport::{HttpTransport, HttpConfig, HttpVersion};
// Default HTTP transport with connection pooling
let transport = HttpTransport::new();
// HTTP/2 with custom configuration
let config = HttpConfig {
http_version: HttpVersion::Http2,
timeout_secs: 60,
pool_max_idle_per_host: 50,
..Default::default()
};
let transport = HttpTransport::with_config(&config)?;
```
**支持的协议:**
- HTTP/1.1(默认)
- 带多路复用的 HTTP/2
- HTTP/3 (QUIC) — 计划中
- gRPC — 计划中
- JSON-RPC — 计划中
### 生产环境特性
- **带退避的重试** — 针对瞬时故障的带抖动指数退避
- **熔断器** — 防止级联故障
- **速率限制** — 基于令牌桶算法的请求节流
- **审计日志** — 带敏感数据脱敏的结构化安全事件
- **Prometheus 指标** — 请求计数器,错误率,延迟跟踪
- **重放保护** — 使用 UUID v4 nonce 及 LRU 缓存验证
### 安全性
- HTTPS 强制执行(拒绝 HTTP URL)
- Localhost/回环地址阻断
- 路径遍历预防
- CRLF 头注入预防
- 字段映射注入保护
- 超时边界验证
## 示例
```
# 基本结账流程
cargo run --example basic_checkout
# 完整电子商务流程 (products → cart → order → payment)
cargo run --example full_checkout_flow
# 浏览商户目录
cargo run --example browse_catalog
# Error handling 模式
cargo run --example error_handling
# TAP signature 生成
cargo run --example signature_generation
# 用于 agent 目录的 JWKS
cargo run --example jwks_generation
# ID Token (JWT) 生成
cargo run --example id_token_generation
# ACRO 生成
cargo run --example acro_generation
# APC encryption/decryption
cargo run --example apc_generation
```
## 配置
### 商户配置 (TOML)
```
name = "My Merchant"
base_url = "https://api.merchant.com"
api_prefix = "/api/v1"
[endpoints]
products = "/products"
cart = "/cart"
checkout = "/checkout"
[field_mappings.request]
consumer_id = "customer_id"
product_id = "item_id"
[field_mappings.response]
customer_id = "consumer_id"
[auth]
type = "api_key"
header = "X-API-Key"
env_var = "MERCHANT_API_KEY"
pagination = "page_based" # or "offset_based", "cursor_based"
```
### 传输配置 (TOML)
```
[transport]
protocol = "http2"
[transport.http]
timeout_secs = 30
connect_timeout_secs = 10
pool_max_idle_per_host = 100
http_version = "http2" # or "http1", "auto"
```
## 文档
| 资源 | 描述 |
|----------|-------------|
| [API 参考](https://docs.rs/tap-mcp-bridge) | 完整的 API 文档 |
| [示例](tap-mcp-bridge/examples/) | 可运行的代码示例 |
| [商户配置](tap-mcp-bridge/examples/merchants/) | TOML 配置示例 |
## 开发
```
# 安装工具
cargo install cargo-nextest cargo-make cargo-deny
# 快速验证
cargo make pre-commit
# 完整测试套件 (490+ 项测试)
cargo nextest run --all-features
# Security audit
cargo deny check
# 文档
cargo doc --no-deps --open
```
## 许可证
根据 MIT 或 Apache-2.0 任一许可证授权。
## 资源
- [TAP 协议](https://developer.visa.com/capabilities/trusted-agent-protocol/) — Visa 官方文档
- [MCP 协议](https://modelcontextprotocol.io/) — Anthropic 的 Model Context Protocol
- [RFC 9421](https://www.rfc-editor.org/rfc/rfc9421.html) — HTTP 消息签名
- [RFC 7516](https://www.rfc-editor.org/rfc/rfc7516.html) — JSON Web Encryption (JWE)
标签:Anthropic MCP, Claude Desktop, Ed25519, HTTP 签名, JWE 加密, MCP Server, Python安全, RFC 9421, Rust, TAP协议, Visa TAP, 公钥密码学, 区块链与金融科技, 可视化界面, 安全支付, 密码学, 手动系统调用, 模型上下文协议, 生产就绪, 电子商务, 网络流量审计, 自定义请求头, 通知系统