BR

Braintree Payment Gateway MCP Server for AI Agents

Process payments, manage customers, and secure transactions with the Braintree payment gateway MCP server for AI agents.

Quick Install
npx -y @QuentinCody/braintree-mcp-server

Overview

This MCP (Model Context Protocol) server integrates the Braintree payment gateway with AI agents. It exposes a set of payment-related “tools” that an AI agent can call to perform common merchant tasks: tokenize payment methods, create customers, process transactions, handle refunds, and generate client tokens for client-side SDKs. The project repository is available at https://github.com/QuentinCody/braintree-mcp-server.

By wrapping Braintree operations as MCP-compatible tools, the server makes it easier to incorporate payments into an automated conversational workflow or an agent-driven application. Instead of wiring Braintree SDKs into each agent implementation, you can run this server as a secure, centralized payment service that enforces configuration, logging, and access control while presenting a small set of high-level operations to the agent.

Features

  • MCP-compatible tool endpoints for AI agents
  • Create and manage Braintree customers and payment methods
  • Create transactions (sale), issue refunds and voids
  • Generate client tokens for client-side Braintree SDK usage
  • Sandbox-ready configuration for development and testing
  • Simple HTTP API and example start scripts for local or containerized deployment

Installation / Configuration

Clone the repository, install dependencies, and configure environment variables required to connect to Braintree.

  1. Clone and install
git clone https://github.com/QuentinCody/braintree-mcp-server.git
cd braintree-mcp-server
npm install
  1. Environment variables

Create a .env file or export variables in your runtime environment. Typical variables:

PORT=3000
BRAINTREE_MERCHANT_ID=your_merchant_id
BRAINTREE_PUBLIC_KEY=your_public_key
BRAINTREE_PRIVATE_KEY=your_private_key
BRAINTREE_ENVIRONMENT=sandbox   # or production
MCP_AUTH_TOKEN=replace-with-a-secret-token
  1. Start locally
npm start
# or, if using nodemon for development
npm run dev
  1. Docker (optional)

Build and run with Docker. Example Dockerfile flow:

docker build -t braintree-mcp .
docker run -e BRAINTREE_MERCHANT_ID=... \
           -e BRAINTREE_PUBLIC_KEY=... \
           -e BRAINTREE_PRIVATE_KEY=... \
           -e BRAINTREE_ENVIRONMENT=sandbox \
           -e MCP_AUTH_TOKEN=secret \
           -p 3000:3000 \
           braintree-mcp

Available Resources

The server exposes a small set of MCP tools (HTTP endpoints) wrapping Braintree SDK operations. Available tools typically include:

  • generateClientToken — create a Braintree client token for client-side tokenization
  • createCustomer — create or update a customer record
  • tokenizePaymentMethod — store a payment method or accept a payment nonce
  • createTransaction — execute a sale (one-time charge)
  • refundTransaction — issue a refund for a transaction
  • voidTransaction — void an authorized transaction (before settlement)
  • findCustomer — retrieve customer details

Endpoints and exact tool names may vary; consult the repository code for precise route patterns and payload shapes. Tools expect JSON payloads and typically return JSON results with Braintree responses or normalized error objects.

Example request (generate client token):

curl -X POST http://localhost:3000/tools/generateClientToken \
  -H "Authorization: Bearer <MCP_AUTH_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{}'

Example request (create transaction):

curl -X POST http://localhost:3000/tools/createTransaction \
  -H "Authorization: Bearer <MCP_AUTH_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": "19.99",
    "payment_method_nonce": "fake-valid-nonce",
    "customer": {
      "firstName": "Jane",
      "lastName": "Doe",
      "email": "[email protected]"
    }
  }'

Use Cases

  • Checkout workflows: An AI shopping assistant collects order details and payment information, then calls createTransaction to complete the purchase. The assistant can present transaction confirmation and store a customer record for future orders.
  • Subscriptions and billing: Use tokenizePaymentMethod and createCustomer to store payment methods, then schedule recurring charges by invoking createTransaction on billing dates (or implement subscription flows via Braintree subscriptions).
  • Customer support refunds: A support-oriented agent can locate a transaction with a reference ID and call refundTransaction to process a refund, returning a structured confirmation back to the user.
  • Client-side SDK integration: A web or mobile client requests a client token (generateClientToken) from the server, uses Braintree’s Drop-in or Hosted Fields to capture secure payment data, then passes a payment nonce back to the agent-backed server for transaction processing.
  • Fraud mitigation and logging: Centralized handling lets you add logging, rate limiting, and additional fraud checks before forwarding operations to Braintree.

Security and Best Practices

  • Never embed Braintree private keys in client-side code. Keep the server-side secrets in environment variables or a secrets manager.
  • Use HTTPS in production and restrict access to the MCP endpoints using tokens or other auth mechanisms (e.g., MCP_AUTH_TOKEN).
  • Use Braintree sandbox credentials for development and thoroughly test payment flows before switching to production keys.
  • Review and handle Braintree error responses and transaction states (authorized, submitted_for_settlement, settled) according to your business logic.

For implementation details, source code, and updates, see the repository: https://github.com/QuentinCody/braintree-mcp-server.

Tags:finance