TAP-MCP电桥
    
用于Visa可信代理协议(TAP)的Rust库和MCP服务器,使AI代理能够安全地与商家进行身份验证并执行支付交易。
工作区结构
| 板条箱 | 类型 | 描述 |
|---|---|---|
tap-mcp-bridge | 库 | RFC 9421签名、JWE加密、TAP协议 |
tap-mcp-server | Binary | MCP服务器为Claude和其他AI代理提供TAP工具 |
安装
作为图书馆
[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"
}
}
}
}\[!重要\] 需要Rust 1.94+(2024版,解析器v3)。
快速示例
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 使用Ed25519的HTTP消息签名
- RFC 7516 支付数据的JWE加密(A256GCM+RSA-OAEP-256)
- RFC 7638 JWK指纹用于钥匙识别
- ID令牌 (JWT)用于消费者身份验证
- 肢端 --代理消费者识别对象
- 自动程序控制 --JWE加密的代理支付容器
商户抽象
灵活的商户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"
"#)?;\[!提示\] 看 examples/merchants/ 对于TOML配置示例。运输抽象
支持多种协议的可插拔传输层:
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——计划中
生产特点
- 使用回退重试 --瞬态故障时具有抖动的指数回退
- 断路器 --防止级联故障
- 速率限制 --用于请求限制的令牌桶算法
- 审核日志记录 --带有敏感数据编辑的结构化安全事件
- 普罗米修斯指标 --请求计数器、错误率、延迟跟踪
- 重放保护 --带有LRU缓存验证的UUID v4随机数
安全
- HTTPS强制(HTTP URL被拒绝)
- 本地主机/环回阻止
- 路径遍历预防
- CRLF头注入防止
- 现场测绘注入保护
- 超时界限验证
示例
# Basic checkout flow
cargo run --example basic_checkout
# Full e-commerce flow (products → cart → order → payment)
cargo run --example full_checkout_flow
# Browse merchant catalog
cargo run --example browse_catalog
# Error handling patterns
cargo run --example error_handling
# TAP signature generation
cargo run --example signature_generation
# JWKS for agent directory
cargo run --example jwks_generation
# ID Token (JWT) generation
cargo run --example id_token_generation
# ACRO generation
cargo run --example acro_generation
# APC encryption/decryption
cargo run --example apc_generation\[!提示\] 集AGENT_SIGNING_KEY运行示例前的环境变量: ``bash export AGENT_SIGNING_KEY=$(openssl rand -hex 32)``
配置
商户配置(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"文档
发展
# Install tools
cargo install cargo-nextest cargo-make cargo-deny
# Quick verification
cargo make pre-commit
# Full test suite (490+ tests)
cargo nextest run --all-features
# Security audit
cargo deny check
# Documentation
cargo doc --no-deps --open许可证
根据您的选择,在MIT或Apache-2.0下获得许可。
