跳转到主要内容

Documentation Index

Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The Model Context Protocol (MCP) is an open standard that enables AI applications to securely connect to external data sources and APIs. The Dodo Payments MCP Server provides AI assistants like Claude, Cursor, and other MCP-compatible clients with structured access to your payment infrastructure. The Dodo Payments MCP Server uses the Code Mode architecture. Instead of exposing hundreds of individual tools for every API endpoint, Code Mode enables AI agents to write and execute TypeScript code against the Dodo Payments SDK in an isolated sandbox environment.

Key capabilities

  • Payment Operations: Create, retrieve, and manage payments and refunds
  • Subscription Management: Handle recurring billing, upgrades, and cancellations
  • Customer Administration: Manage customer data and portal access
  • Product Catalog: Create and update products, pricing, and discounts
  • License Management: Activate, validate, and manage software licenses
  • Usage-Based Billing: Track and bill for metered usage

How Code Mode Works

The Dodo Payments MCP Server provides your AI agent with exactly two tools:
  1. Docs Search Tool: Queries documentation about the Dodo Payments API and SDK to understand available operations and parameters.
  2. Code Execution Tool: Writes TypeScript code against the SDK that executes in a secure sandbox environment.
This architecture allows agents to perform complex, multi-step operations in a single invocation. For example, an agent can list all active subscriptions, filter them based on specific criteria, and apply a discount to each—all within one script.
Using Code Mode, agents can chain multiple API calls, handle conditional logic, and perform calculations without requiring multiple round-trips to the LLM.

Quick Setup

Connect to the Dodo Payments MCP Server in your AI client:
需要 Node.js 18 或更高版本。远程服务器使用 OAuth 进行身份认证——首次连接时,您将被提示输入 API 密钥并选择环境。

Dodo 知识 MCP

除了 Dodo Payments MCP 服务器(用于执行 API 操作)外,我们还提供 Dodo Knowledge MCP——这是一个语义搜索服务器,让 AI 助手可以即时访问 Dodo Payments 文档和知识库。
构建于 ContextMCP.ai: Dodo Knowledge MCP 由 ContextMCP 支持,使用向量嵌入实现快速的文档语义搜索。

什么是 Dodo Knowledge MCP?

Dodo Knowledge MCP 是一个远程 MCP 服务器,提供:
  • 语义文档搜索:使用自然语言查询查找相关文档。
  • 上下文答案:AI 助手获得有关 Dodo Payments 的准确、最新信息。
  • 零设置:无需 API 密钥或本地安装——只需连接并开始查询。

快速设置

在您的 AI 客户端中连接到 Dodo Knowledge MCP:
添加到 ~/.cursor/mcp.json
{
  "mcpServers": {
    "dodo-knowledge": {
      "command": "npx",
      "args": ["-y", "mcp-remote@latest", "https://knowledge.dodopayments.com/mcp"]
    }
  }
}
需要 Node.js 18 或更高版本。mcp-remote 包处理与远程 MCP 服务器的连接。

同时使用两个 MCP 服务器

为了获得最佳的 AI 辅助开发体验,我们建议使用这两个 MCP 服务器:
服务器目的使用案例
Dodo Knowledge MCP文档搜索“如何处理 webhooks?”,“支持哪些付款方式?”
Dodo Payments MCPAPI 操作创建付款、管理订阅、处理退款
{
  "mcpServers": {
    "dodo-knowledge": {
      "command": "npx",
      "args": ["-y", "mcp-remote@latest", "https://knowledge.dodopayments.com/mcp"]
    },
    "dodopayments": {
      "command": "npx",
      "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
    }
  }
}
配置好两个服务器后,您的 AI 助手可以先搜索文档以了解如何实现功能,然后执行实际的 API 调用——全部在一次对话中完成。

排除知识 MCP 的故障

如果遇到连接问题:
  1. 清除 MCP 认证缓存: rm -rf ~/.mcp-auth
  2. 重启您的客户端应用
  3. 检查客户端日志以获取错误消息
  4. 验证 Node.js 版本: 需要 Node.js 18+

Knowledge MCP Server

访问 Dodo 知识 MCP 配置页面

安装

选择最适合您工作流程的安装方法。

远程 MCP 服务器(推荐)

无需本地设置或安装即可访问托管的 MCP 服务器。这是最快的入门方式。
1

Access the remote server

在浏览器中导航到 https://mcp.dodopayments.com
2

Configure your MCP client

复制为您特定客户端提供的 JSON 配置。对于 Cursor 或 Claude Desktop,请将此添加到您的 MCP 设置中:
{
  "mcpServers": {
    "dodopayments_api": {
      "command": "npx",
      "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
    }
  }
}
3

Authenticate and configure

OAuth 流程将提示您:
  • 输入您的 Dodo Payments API 密钥
  • 选择您的环境(测试或实时)
  • 选择您的 MCP 客户端类型
确保您的 API 密钥安全。 在开发期间使用测试模式密钥。
4

Complete setup

点击 登录并批准 以授权连接。
一旦连接,您的 AI 助手就可以代表您与 Dodo Payments API 进行交互。

NPM 包

使用 NPM 本地安装并运行 MCP 服务器。
# Set your environment variables
export DODO_PAYMENTS_API_KEY="dodo_test_..."
export DODO_PAYMENTS_WEBHOOK_KEY="your_webhook_key"
export DODO_PAYMENTS_ENVIRONMENT="live_mode"

# Run the latest version
npx -y dodopayments-mcp@latest
使用 @latest 始终拉取最新版本,或像 @1.0.0 一样钉选特定版本以确保稳定性。

Docker

在容器化环境中运行 MCP 服务器以实现一致性部署。
# Pull the latest image
docker pull ghcr.io/dodopayments/mcp:latest

# Run the container
docker run -e DODO_PAYMENTS_API_KEY="dodo_test_..." \
  -e DODO_PAYMENTS_WEBHOOK_KEY="your_webhook_key" \
  -e DODO_PAYMENTS_ENVIRONMENT="live_mode" \
  ghcr.io/dodopayments/mcp:latest
Docker 镜像可在 GitHub 容器注册表 中找到。

客户端配置

在您首选的 AI 客户端中配置 Dodo Payments MCP 服务器。
在 Cursor 中设置 Dodo Payments MCP 服务器,以便通过对话访问您的付款数据。一键安装使用下面的按钮直接在 Cursor 中安装 MCP 服务器:[添加到 Cursor](https://cursor.com/en-US/install-mcp?name=dodopayments-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsImRvZG9wYXltZW50cy1tY3AiXSwiZW52Ijp7IkRPRE9fUEFZTUVOVFNfQVBJX0tFWSI6IlNldCB5b3VyIERPRE9fUEFZTUVOVFNfQVBJX0tFWSBoZXJlLiIsIkRPRE9fUEFZTUVOVFNfV0VCSE9PS19LRVkiOiJTZXQgeW91ciBET0RPX1BBWU1FTlRTX1dFQkhPT0tfS0VZIGhlcmUuIn19)点击后,通过 Cursor 设置 > 工具和 MCP > 新 MCP 服务器在 Cursor 的 mcp.json 中设置您的环境变量。手动配置
1

Open Cursor settings

导航到 Cursor 设置 > 功能 > 模型上下文协议 或按下 Cmd/Ctrl + Shift + P 并搜索“ MCP 设置”。
2

Edit configuration

点击 编辑配置 以打开 mcp_config.json 文件。
3

Add Dodo Payments configuration

选择以下配置之一:远程服务器(推荐)
{
  "mcpServers": {
    "dodopayments": {
      "command": "npx",
      "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
    }
  }
}
本地 NPX
{
  "mcpServers": {
    "dodopayments": {
      "command": "npx",
      "args": ["-y", "dodopayments-mcp@latest"],
      "env": {
        "DODO_PAYMENTS_API_KEY": "dodo_test_...",
        "DODO_PAYMENTS_WEBHOOK_KEY": "your_webhook_key"
      }
    }
  }
}
4

Save and restart

保存配置文件并重新启动 Cursor。
通过询问 AI 助手有关您 Dodo Payments 数据的信息来验证连接。

环境变量

使用环境变量配置 MCP 服务器行为。
变量描述必需
DODO_PAYMENTS_API_KEY您的 Dodo Payments API 密钥
DODO_PAYMENTS_WEBHOOK_KEY您的 webhook 签名密钥
DODO_PAYMENTS_ENVIRONMENT设置为 live_mode 用于生产环境

远程运行

将 MCP 服务器部署为远程 HTTP 服务器以进行基于 Web 的客户端或代理性工作流。
# Start as remote server
npx -y dodopayments-mcp --transport=http

# Specify a custom port
npx -y dodopayments-mcp --transport=http --port=3000

远程服务器配置

一旦部署,客户端可以使用服务器 URL 连接:
{
  "mcpServers": {
    "dodopayments_api": {
      "url": "http://localhost:3000",
      "headers": {
        "Authorization": "Bearer your_api_key"
      }
    }
  }
}

授权头

远程服务器通过以下头接受认证:
描述
Authorization令牌认证
x-dodo-payments-api-key直接 API 密钥头

安全最佳实践

代码模式通过在沙盒环境中执行代码和在服务器端注入 API 密钥提供固有的安全性。请遵循以下其他最佳做法以保护您的凭据。
切勿将凭据提交到版本控制中将 API 密钥存储在环境变量或安全的秘密管理系统中。
# Use environment variables
export DODO_PAYMENTS_API_KEY="dodo_test_..."

# Use a .env file (add to .gitignore)
echo "DODO_PAYMENTS_API_KEY=dodo_test_..." > .env
定期旋转密钥定期生成新的 API 密钥,并通过您的 Dodo Payments 仪表板撤销旧的。为开发使用测试密钥开发时始终使用测试模式 API 密钥,以免影响生产数据。
为远程服务器实施认证远程部署时,始终要求通过 Authorization 头或 x-dodo-payments-api-key 头进行认证。监控 API 使用情况通过您的 Dodo Payments 仪表板跟踪 MCP 服务器活动,并设置警报以检测异常模式。
为远程服务器使用 HTTPS始终在 HTTPS 端点后面部署远程 MCP 服务器。实施速率限制通过在 MCP 服务器和 API 级别实施速率限制以防止滥用。限制网络访问配置防火墙规则以限制可以连接到您的 MCP 服务器的客户端。

故障排除

验证您的 API 密钥确保设置正确的 API 密钥并具备必要的权限。
# Test your API key
curl -H "Authorization: Bearer dodo_test_..." \
  https://test.dodopayments.com/payments
检查您的网络连接验证您可以访问 Dodo Payments API 端点。查看客户端日志在您的 MCP 客户端中启用详细日志记录以诊断连接问题。
确认 API 密钥环境确保您在测试端点中使用测试密钥,在生产端点中使用实时密钥。检查环境变量验证 DODO_PAYMENTS_ENVIRONMENT 设置正确(生产环境为 live_mode)。重新生成凭据如果问题仍然存在,请通过您的仪表板生成新的 API 密钥。
验证输入参数确保 AI 助手为每个工具提供格式正确的参数。查看错误消息检查 API 的错误响应以获取有关问题原因的具体指南。直接用 API 测试通过 curl 或 Postman 直接调用 Dodo Payments API 验证操作是否有效。

为什么使用代码模式

传统的 MCP 实现通常存在“工具扩散”问题,每个 API 端点都被作为一个单独的工具暴露。代码模式由于以下几个原因是更优的:

LLM 更擅长编写代码而不是调用工具

LLM 已经在数百万行真实世界代码上进行过训练,使其在编写脚本方面天生擅长。相比之下,工具调用通常基于合成示例。
“让 LLM 使用工具调用来执行任务,就像是让莎士比亚参加一个月的普通话课,然后要求他用普通话写一部戏剧。” — Cloudflare

消除上下文窗口膨胀

在传统方法中,每个工具定义在对话开始前就消耗了 tokens。暴露 50 多个工具很容易耗费 55K-100K+ tokens。Anthropic 发现工具定义在优化前可以消耗多达 134K tokens。 使用代码模式,仅加载 2 个工具定义(约 1K tokens)。代理根据需要查找所需文档。Anthropic 的工具搜索工具保留了 95% 的上下文窗口,将开销从 77K 减少到 8.7K tokens。

通过编程组织降低延迟

传统工具调用每个操作都需要完整的模型推理往返。如果一个任务需要 20 次 API 调用,那就是 20 次往返。在代码模式中,代理编写一个脚本来执行所有调用,只返回最终结果。 Anthropic 观察到使用这种编程方法,tokens 减少了 37%,并且提高了准确性(知识检索从 25.6% 提高到 28.5%)。

天生更安全

代码模式提供固有的安全优势:
  • 在参数中没有 API 密钥:API 密钥在服务器端注入,永远不会暴露在发送给 LLM 的工具参数中。
  • 隔离的沙盒:代码在一个安全的环境中运行,无法访问网络或主机文件系统。
  • 受控 SDK:只有授权的 SDK 方法可供代理使用。

可扩展到任意 API 大小

随着 API 的增长,传统 MCP 性能下降,因为需要将更多工具加载到上下文中。代码模式无论 API 的表面积如何都保持恒定,始终只需 2 个工具。Cloudflare 成功将 2500 多个 API 端点缩减为仅 2 个工具和大约 1000 个上下文 tokens。
有关此架构优点的更多详细信息,请参阅来自 AnthropicCloudflare 的工程博客,以及 Claude 的 程序化工具调用 文档。

资源

API Reference

探索完整的 Dodo Payments API 文档

MCP Protocol

了解更多关于模型上下文协议标准的信息

GitHub Repository

查看 MCP 服务器源代码并贡献

NPM Package

从 NPM 安装 MCP 服务器
Last modified on May 4, 2026