Braintree支付处理服务器

一个非官方的Model Context Protocol (MCP)服务器,用于与PayPal Braintree支付处理服务交互,支持通过GraphQL API执行支付操作。

  • by QuentinCody
  • Python
  • 混合部署
  • 4 星标
  • 更新于
在 GitHub 查看 QuentinCody/braintree-mcp-server

使用说明

Braintree MCP服务器

用于与PayPal Braintree支付处理服务交互的非官方模型上下文协议(MCP)服务器。

许可证和引用

该项目在麻省理工学院许可证下提供,并附有学术引文要求。这意味着您可以自由使用、修改和分发代码,但使用此软件的任何学术或科学出版物都必须提供适当的归属。

学术/研究用途:

如果您在导致出版物、演示文稿或报告的研究项目中使用此软件,您 必须 根据中提供的格式引用此作品 引文.md.

商业/非学术用途:

商业和非学术用途遵循麻省理工学院的标准许可条款,无需引用。

使用本软件即表示您同意这些条款。看 许可证.md 获取完整的许可证文本。

服务器版本

Braintree MCP服务器有两个版本:

1.STDIO传输服务器(braintree_server.py)

  • 使用标准输入/输出(STDIO)进行通信
  • 专为与Claude Desktop和其他支持STDIO的MCP客户端集成而设计
  • 每个客户端会话都会生成一个新的服务器进程
  • 当客户端断开连接时,服务器终止

使用Claude Desktop:

  1. 配置 claude_desktop_config.json 指向此服务器
  2. 打开Claude Desktop并选择Braintree工具

2.SSE传输服务器(braintree_sse_server.py)

  • 使用服务器发送事件(SSE)进行通信
  • 设计为可处理多个客户端连接的独立web服务器
  • 服务器持续运行,直到手动停止
  • 绑定到 127.0.0.1:8001 默认情况下(可配置)

手动使用:

python braintree_sse_server.py

连接到SSE服务器: 使用支持SSE传输的MCP客户端并连接到 http://127.0.0.1:8001/sse

概述

该服务器实现模型上下文协议(MCP)规范,通过GraphQL API为人工智能辅助模型提供对Braintree支付处理能力的直接结构化访问。它使人工智能系统能够通过MCP工具执行支付操作,如提取交易、创建支付和管理客户数据。

安装

  1. 克隆此存储库
git clone https://github.com/yourusername/braintree-mcp-server.git
cd braintree-mcp-server
  1. 设置Python 3.13+环境
# If using pyenv
pyenv install 3.13.0
pyenv local 3.13.0

# Or using another method to ensure Python 3.13+
  1. 安装依赖项
pip install -e .

配置

创建一个 .env 使用Braintree凭据在项目根目录中创建文件:

BRAINTREE_MERCHANT_ID=your_merchant_id
BRAINTREE_PUBLIC_KEY=your_public_key
BRAINTREE_PRIVATE_KEY=your_private_key
BRAINTREE_ENVIRONMENT=sandbox  # or production

您可以从Braintree控制面板获取这些凭据。

用法

运行服务器

默认STDIO传输

python braintree_server.py

默认情况下,服务器使用stdio传输运行,这适用于与支持MCP的AI辅助系统集成。

服务器发送事件(SSE)传输

python braintree_sse_server.py

SSE服务器提供了一个基于web的传输层,允许多个持久客户端连接。这对于需要多个客户端访问Braintree功能的独立部署非常有用。

默认配置:

  • 主机:127.0.0.1(本地主机)
  • 端口:8001
  • 环境:在.env文件中定义

看 requirements.txt 对于所需的依赖关系。

可用的MCP工具

braintree_ping

简单的连接测试,检查您的Braintree凭据是否正常工作。

response = await braintree_ping()
# Returns "pong" if successful

braintreeexecutegraphql

针对Braintree API执行任意GraphQL查询。

query = """
query GetTransactionDetails($id: ID!) {
  node(id: $id) {
    ... on Transaction {
      id
      status
      amount {
        value
        currencyCode
      }
      createdAt
    }
  }
}
"""

variables = {"id": "transaction_id_here"}

response = await braintree_execute_graphql(query, variables)
# Returns JSON response from Braintree

常见GraphQL操作

获取客户

query GetCustomer($id: ID!) {
  node(id: $id) {
    ... on Customer {
      id
      firstName
      lastName
      email
      paymentMethods {
        edges {
          node {
            id
            details {
              ... on CreditCardDetails {
                last4
                expirationMonth
                expirationYear
                cardType
              }
            }
          }
        }
      }
    }
  }
}

创建交易

mutation CreateTransaction($input: ChargePaymentMethodInput!) {
  chargePaymentMethod(input: $input) {
    transaction {
      id
      status
      amount {
        value
        currencyCode
      }
    }
  }
}

变量:

{
  "input": {
    "paymentMethodId": "payment_method_id_here",
    "transaction": {
      "amount": "10.00",
      "orderId": "order123",
      "options": {
        "submitForSettlement": true
      }
    }
  }
}

故障排除

  • 确保您的Braintree凭据在 .env 文件
  • 验证您的网络连接是否可以到达Braintree的API端点
  • 检查您的Braintree帐户是否存在任何限速或权限问题