> ## 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.

# MCP Server

> Enable AI assistants to interact with the Dodo Payments API through Code Mode—a high-performance architecture for seamless payment operations and subscription management.

## 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.

<Tip>
  Using Code Mode, agents can chain multiple API calls, handle conditional logic, and perform calculations without requiring multiple round-trips to the LLM.
</Tip>

### Quick Setup

Connect to the Dodo Payments MCP Server in your AI client:

<Tabs>
  <Tab title="Agent Plugin (recommended)">
    The [Dodo Agent Plugin](/developer-resources/build-with-ai-coding-agents) installs both MCP servers and all eight skills in one step for Claude Code, Codex CLI, Cursor, and OpenCode. See the [AI Coding Agents guide](/developer-resources/build-with-ai-coding-agents) for per-agent install commands.

    If your agent isn't in that list, use the tabs below to configure the MCP server directly.
  </Tab>

  <Tab title="Cursor">
    Add to `~/.cursor/mcp.json`:

    ```json theme={null}
    {
      "mcpServers": {
        "dodopayments": {
          "command": "npx",
          "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
        }
      }
    }
    ```
  </Tab>

  <Tab title="Claude Desktop">
    Add to your Claude Desktop configuration:

    ```json theme={null}
    {
      "mcpServers": {
        "dodopayments": {
          "command": "npx",
          "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
        }
      }
    }
    ```

    Configuration file locations:

    * **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
    * **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
    * **Linux**: `~/.config/Claude/claude_desktop_config.json`
  </Tab>

  <Tab title="Windsurf">
    Add to `~/.codeium/windsurf/mcp_config.json`:

    ```json theme={null}
    {
      "mcpServers": {
        "dodopayments": {
          "command": "npx",
          "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
        }
      }
    }
    ```
  </Tab>

  <Tab title="Claude Code">
    Run in your terminal:

    ```bash theme={null}
    claude mcp add dodopayments -- npx -y mcp-remote@latest https://mcp.dodopayments.com/sse
    ```
  </Tab>
</Tabs>

<Note>
  Requires Node.js 18 or higher. The remote server uses OAuth for authentication — you will be prompted to enter your API key and select your environment on first connection.
</Note>

## Dodo Knowledge MCP

In addition to the Dodo Payments MCP Server (for executing API operations), we provide **Dodo Knowledge MCP**—a semantic search server that gives AI assistants instant access to Dodo Payments documentation and knowledge base.

<Info>
  **Built with [ContextMCP.ai](https://contextmcp.ai)**: Dodo Knowledge MCP is powered by ContextMCP, enabling fast semantic search across our documentation using vector embeddings.
</Info>

### What is Dodo Knowledge MCP?

Dodo Knowledge MCP is a remote MCP server that provides:

* **Semantic Documentation Search**: Find relevant documentation using natural language queries.
* **Contextual Answers**: AI assistants get accurate, up-to-date information about Dodo Payments.
* **Zero Setup**: No API keys or local installation required—just connect and start querying.

### Quick Setup

Connect to Dodo Knowledge MCP in your AI client:

<Tabs>
  <Tab title="Cursor">
    Add to `~/.cursor/mcp.json`:

    ```json theme={null}
    {
      "mcpServers": {
        "dodo-knowledge": {
          "command": "npx",
          "args": ["-y", "mcp-remote@latest", "https://knowledge.dodopayments.com/mcp"]
        }
      }
    }
    ```
  </Tab>

  <Tab title="Claude Desktop">
    Add to your Claude Desktop configuration:

    ```json theme={null}
    {
      "mcpServers": {
        "dodo-knowledge": {
          "command": "npx",
          "args": ["-y", "mcp-remote@latest", "https://knowledge.dodopayments.com/mcp"]
        }
      }
    }
    ```

    Configuration file locations:

    * **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
    * **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
    * **Linux**: `~/.config/Claude/claude_desktop_config.json`
  </Tab>

  <Tab title="Windsurf">
    Add to `~/.codeium/windsurf/mcp_config.json`:

    ```json theme={null}
    {
      "mcpServers": {
        "dodo-knowledge": {
          "command": "npx",
          "args": ["-y", "mcp-remote@latest", "https://knowledge.dodopayments.com/mcp"]
        }
      }
    }
    ```
  </Tab>

  <Tab title="Claude Code">
    Run in your terminal:

    ```bash theme={null}
    claude mcp add dodo-knowledge -- npx -y mcp-remote@latest https://knowledge.dodopayments.com/mcp
    ```
  </Tab>
</Tabs>

<Note>
  Requires Node.js 18 or higher. The `mcp-remote` package handles the connection to the remote MCP server.
</Note>

### Using Both MCP Servers Together

For the best AI-assisted development experience, we recommend using both MCP servers:

| Server                 | Purpose              | Use Case                                                           |
| ---------------------- | -------------------- | ------------------------------------------------------------------ |
| **Dodo Knowledge MCP** | Documentation search | "How do I handle webhooks?", "What payment methods are supported?" |
| **Dodo Payments MCP**  | API operations       | Create payments, manage subscriptions, handle refunds              |

```json theme={null}
{
  "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"]
    }
  }
}
```

<Tip>
  With both servers configured, your AI assistant can first search documentation to understand how to implement a feature, then execute the actual API calls—all in a single conversation.
</Tip>

### Troubleshooting Knowledge MCP

If you encounter connection issues:

1. **Clear MCP authentication cache**: `rm -rf ~/.mcp-auth`
2. **Restart your client application**
3. **Check client logs** for error messages
4. **Verify Node.js version**: Requires Node.js 18+

<Card title="Knowledge MCP Server" icon="book-open" href="https://knowledge.dodopayments.com">
  Access the Dodo Knowledge MCP configuration page
</Card>

## Installation

Choose the installation method that best fits your workflow.

### Remote MCP Server (Recommended)

Access the hosted MCP server without any local setup or installation. This is the fastest way to get started.

<Frame>
  <iframe className="w-full aspect-video rounded-md" src="https://www.youtube.com/embed/TxGgYxNmkT4" title="Using Dodo Payment's Remote MCP Server" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen />
</Frame>

<Steps>
  <Step title="Access the remote server">
    Navigate to [https://mcp.dodopayments.com](https://mcp.dodopayments.com) in your browser.
  </Step>

  <Step title="Configure your MCP client">
    Copy the provided JSON configuration for your specific client. For Cursor or Claude Desktop, add this to your MCP settings:

    ```json theme={null}
    {
      "mcpServers": {
        "dodopayments_api": {
          "command": "npx",
          "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
        }
      }
    }
    ```
  </Step>

  <Step title="Authenticate and configure">
    The OAuth flow will prompt you to:

    * Enter your Dodo Payments API key
    * Select your environment (test or live)
    * Choose your MCP client type

    <Warning>
      Keep your API key secure. Use test mode keys during development.
    </Warning>
  </Step>

  <Step title="Complete setup">
    Click **Login and Approve** to authorize the connection.

    <Check>
      Once connected, your AI assistant can interact with the Dodo Payments API on your behalf.
    </Check>
  </Step>
</Steps>

### NPM Package

Install and run the MCP server locally using NPM.

<Tabs>
  <Tab title="NPX (No Installation)">
    ```bash theme={null}
    # 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
    ```
  </Tab>

  <Tab title="MCP Client Configuration">
    ```json theme={null}
    {
      "mcpServers": {
        "dodopayments_api": {
          "command": "npx",
          "args": ["-y", "dodopayments-mcp@latest"],
          "env": {
            "DODO_PAYMENTS_API_KEY": "dodo_test_...",
            "DODO_PAYMENTS_WEBHOOK_KEY": "your_webhook_key",
            "DODO_PAYMENTS_ENVIRONMENT": "live_mode"
          }
        }
      }
    }
    ```
  </Tab>
</Tabs>

<Tip>
  Use `@latest` to always pull the most recent version, or pin to a specific version like `@1.0.0` for stability.
</Tip>

### Docker

Run the MCP server in a containerized environment for consistent deployment.

<CodeGroup>
  ```bash Docker theme={null}
  # 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
  ```

  ```yaml Docker Compose theme={null}
  services:
    dodopayments-mcp:
      image: ghcr.io/dodopayments/mcp:latest
      environment:
        - DODO_PAYMENTS_API_KEY=dodo_test_...
        - DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_key
        - DODO_PAYMENTS_ENVIRONMENT=live_mode
      restart: unless-stopped
  ```
</CodeGroup>

<Note>
  Docker images are available on [GitHub Container Registry](https://github.com/orgs/dodopayments/packages/container/package/mcp).
</Note>

## Client Configuration

Configure the Dodo Payments MCP server in your preferred AI client.

<Tabs>
  <Tab title="Cursor">
    Set up the Dodo Payments MCP server in Cursor to enable conversational access to your payments data.

    **One-Click Install**

    Use the button below to install the MCP server directly in Cursor:

    [![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=dodopayments-mcp\&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsImRvZG9wYXltZW50cy1tY3AiXSwiZW52Ijp7IkRPRE9fUEFZTUVOVFNfQVBJX0tFWSI6IlNldCB5b3VyIERPRE9fUEFZTUVOVFNfQVBJX0tFWSBoZXJlLiIsIkRPRE9fUEFZTUVOVFNfV0VCSE9PS19LRVkiOiJTZXQgeW91ciBET0RPX1BBWU1FTlRTX1dFQkhPT0tfS0VZIGhlcmUuIn19)

    After clicking, set your environment variables in Cursor's `mcp.json` via **Cursor Settings** > **Tools & MCP** > **New MCP Server**.

    **Manual Configuration**

    <Steps>
      <Step title="Open Cursor settings">
        Navigate to **Cursor Settings** > **Features** > **Model Context Protocol** or press `Cmd/Ctrl + Shift + P` and search for "MCP Settings".
      </Step>

      <Step title="Edit configuration">
        Click **Edit Config** to open the `mcp_config.json` file.
      </Step>

      <Step title="Add Dodo Payments configuration">
        Choose one of the following configurations:

        **Remote Server (Recommended)**

        ```json theme={null}
        {
          "mcpServers": {
            "dodopayments": {
              "command": "npx",
              "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
            }
          }
        }
        ```

        **Local NPX**

        ```json theme={null}
        {
          "mcpServers": {
            "dodopayments": {
              "command": "npx",
              "args": ["-y", "dodopayments-mcp@latest"],
              "env": {
                "DODO_PAYMENTS_API_KEY": "dodo_test_...",
                "DODO_PAYMENTS_WEBHOOK_KEY": "your_webhook_key"
              }
            }
          }
        }
        ```
      </Step>

      <Step title="Save and restart">
        Save the configuration file and restart Cursor.

        <Check>
          Verify the connection by asking the AI assistant about your Dodo Payments data.
        </Check>
      </Step>
    </Steps>
  </Tab>

  <Tab title="Claude Desktop">
    Set up the Dodo Payments MCP server in Claude Desktop to enable conversational access to your payments data.

    <Steps>
      <Step title="Locate configuration file">
        Find the Claude Desktop configuration file:

        * **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
        * **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
        * **Linux**: `~/.config/Claude/claude_desktop_config.json`
      </Step>

      <Step title="Edit configuration">
        Open the file in a text editor and add the Dodo Payments configuration:

        **Remote Server (Recommended)**

        ```json theme={null}
        {
          "mcpServers": {
            "dodopayments": {
              "command": "npx",
              "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
            }
          }
        }
        ```

        **Local NPX**

        ```json theme={null}
        {
          "mcpServers": {
            "dodopayments": {
              "command": "npx",
              "args": ["-y", "dodopayments-mcp@latest"],
              "env": {
                "DODO_PAYMENTS_API_KEY": "dodo_test_...",
                "DODO_PAYMENTS_WEBHOOK_KEY": "your_webhook_key"
              }
            }
          }
        }
        ```
      </Step>

      <Step title="Restart Claude Desktop">
        Close and reopen Claude Desktop for the changes to take effect.

        <Tip>
          Look for the 🔌 icon in Claude Desktop to confirm the MCP server is connected.
        </Tip>
      </Step>
    </Steps>
  </Tab>

  <Tab title="Claude Code">
    Set up the Dodo Payments MCP server in Claude Code CLI.

    Run the following command in your terminal:

    ```bash theme={null}
    claude mcp add --transport stdio dodopayments_api \
      --env DODO_PAYMENTS_API_KEY="dodo_test_..." \
      DODO_PAYMENTS_WEBHOOK_KEY="your_webhook_key" \
      -- npx -y dodopayments-mcp
    ```

    The configuration will be stored in your home directory's `.claude.json` file.

    <Tip>
      Claude Code automatically picks up environment variables from your shell, so you can also export them before running the command.
    </Tip>
  </Tab>

  <Tab title="VS Code">
    Set up the Dodo Payments MCP server in VS Code.

    **One-Click Install**

    [Open VS Code](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22dodopayments-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22dodopayments-mcp%22%5D%2C%22env%22%3A%7B%22DODO_PAYMENTS_API_KEY%22%3A%22Set%20your%20DODO_PAYMENTS_API_KEY%20here.%22%2C%22DODO_PAYMENTS_WEBHOOK_KEY%22%3A%22Set%20your%20DODO_PAYMENTS_WEBHOOK_KEY%20here.%22%7D%7D)

    After clicking, set your environment variables in VS Code's `mcp.json` via **Command Palette** > **MCP: Open User Configuration**.

    **Manual Configuration**

    <Steps>
      <Step title="Open MCP configuration">
        Open the Command Palette (`Cmd/Ctrl + Shift + P`) and search for "MCP: Open User Configuration".
      </Step>

      <Step title="Add server configuration">
        Add the Dodo Payments MCP server:

        ```json theme={null}
        {
          "mcpServers": {
            "dodopayments": {
              "command": "npx",
              "args": ["-y", "dodopayments-mcp@latest"],
              "env": {
                "DODO_PAYMENTS_API_KEY": "dodo_test_...",
                "DODO_PAYMENTS_WEBHOOK_KEY": "your_webhook_key"
              }
            }
          }
        }
        ```
      </Step>

      <Step title="Reload window">
        Reload VS Code (`Cmd/Ctrl + Shift + P` > "Reload Window") to activate the MCP server.
      </Step>
    </Steps>
  </Tab>

  <Tab title="Cline (VS Code)">
    Set up the Dodo Payments MCP server in Cline (VS Code) to enable conversational access to your payments data.

    <Steps>
      <Step title="Open Cline settings">
        Locate the Cline configuration file:

        * **macOS**: `~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`
        * **Windows**: `%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json`
        * **Linux**: `~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`
      </Step>

      <Step title="Configure MCP server">
        Add the Dodo Payments MCP server configuration:

        ```json theme={null}
        {
          "mcpServers": {
            "dodopayments": {
              "command": "npx",
              "args": ["-y", "dodopayments-mcp@latest"],
              "env": {
                "DODO_PAYMENTS_API_KEY": "dodo_test_...",
                "DODO_PAYMENTS_WEBHOOK_KEY": "your_webhook_key"
              }
            }
          }
        }
        ```
      </Step>

      <Step title="Reload VS Code">
        Reload the VS Code window (`Cmd/Ctrl + Shift + P` > "Reload Window") to activate the MCP server connection.
      </Step>
    </Steps>
  </Tab>

  <Tab title="Zed">
    Set up the Dodo Payments MCP server in Zed to enable conversational access to your payments data.

    <Steps>
      <Step title="Open Zed settings">
        Navigate to **Settings** > **Assistant** > **Model Context Protocol**.
      </Step>

      <Step title="Add server configuration">
        Add the following configuration:

        ```json theme={null}
        {
          "mcpServers": {
            "dodopayments": {
              "command": "npx",
              "args": ["-y", "dodopayments-mcp@latest"],
              "env": {
                "DODO_PAYMENTS_API_KEY": "dodo_test_...",
                "DODO_PAYMENTS_WEBHOOK_KEY": "your_webhook_key"
              }
            }
          }
        }
        ```
      </Step>

      <Step title="Save and verify">
        Save the configuration. The MCP server should now be available in Zed's AI assistant.
      </Step>
    </Steps>
  </Tab>

  <Tab title="Other Clients">
    Set up the Dodo Payments MCP server in other MCP-compatible clients.

    **Remote Server (Recommended)**

    ```json theme={null}
    {
      "mcpServers": {
        "dodopayments": {
          "command": "npx",
          "args": ["-y", "mcp-remote@latest", "https://mcp.dodopayments.com/sse"]
        }
      }
    }
    ```

    **Local NPX**

    ```json theme={null}
    {
      "mcpServers": {
        "dodopayments": {
          "command": "npx",
          "args": ["-y", "dodopayments-mcp@latest"],
          "env": {
            "DODO_PAYMENTS_API_KEY": "dodo_test_...",
            "DODO_PAYMENTS_WEBHOOK_KEY": "your_webhook_key"
          }
        }
      }
    }
    ```

    <Info>
      Visit [modelcontextprotocol.io/clients](https://modelcontextprotocol.io/clients) for a complete list of MCP-compatible clients and their configuration methods.
    </Info>
  </Tab>
</Tabs>

## Environment Variables

Configure the MCP server behavior using environment variables.

| Variable                    | Description                       | Required |
| --------------------------- | --------------------------------- | -------- |
| `DODO_PAYMENTS_API_KEY`     | Your Dodo Payments API key        | Yes      |
| `DODO_PAYMENTS_WEBHOOK_KEY` | Your webhook signing key          | No       |
| `DODO_PAYMENTS_ENVIRONMENT` | Set to `live_mode` for production | No       |

## Running Remotely

Deploy the MCP server as a remote HTTP server for web-based clients or agentic workflows.

```bash theme={null}
# Start as remote server
npx -y dodopayments-mcp --transport=http

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

### Remote Server Configuration

Once deployed, clients can connect using the server URL:

```json theme={null}
{
  "mcpServers": {
    "dodopayments_api": {
      "url": "http://localhost:3000",
      "headers": {
        "Authorization": "Bearer your_api_key"
      }
    }
  }
}
```

### Authorization Headers

The remote server accepts authentication via the following headers:

| Header                    | Description                 |
| ------------------------- | --------------------------- |
| `Authorization`           | Bearer token authentication |
| `x-dodo-payments-api-key` | Direct API key header       |

## Security Best Practices

Code Mode provides inherent security by executing code in a sandboxed environment and injecting API keys server-side. Follow these additional best practices to protect your credentials.

<AccordionGroup>
  <Accordion title="API Key Management">
    **Never commit credentials to version control**

    Store API keys in environment variables or secure secret management systems.

    ```bash theme={null}
    # 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
    ```

    **Rotate keys regularly**

    Generate new API keys periodically and revoke old ones through your Dodo Payments dashboard.

    **Use test keys for development**

    Always use test mode API keys during development to avoid affecting production data.
  </Accordion>

  <Accordion title="Access Control">
    **Implement authentication for remote servers**

    When deploying remotely, always require authentication via the `Authorization` header or `x-dodo-payments-api-key` header.

    **Monitor API usage**

    Track MCP server activity through your Dodo Payments dashboard and set up alerts for unusual patterns.
  </Accordion>

  <Accordion title="Network Security">
    **Use HTTPS for remote servers**

    Always deploy remote MCP servers behind HTTPS endpoints.

    **Implement rate limiting**

    Protect against abuse by implementing rate limits at both the MCP server and API levels.

    **Restrict network access**

    Configure firewall rules to limit which clients can connect to your MCP server.
  </Accordion>
</AccordionGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Connection issues">
    **Verify your API key**

    Ensure your API key is correctly set and has the necessary permissions.

    ```bash theme={null}
    # Test your API key
    curl -H "Authorization: Bearer dodo_test_..." \
      https://test.dodopayments.com/payments
    ```

    **Check your network connection**

    Verify you can reach the Dodo Payments API endpoints.

    **Review client logs**

    Enable verbose logging in your MCP client to diagnose connection problems.
  </Accordion>

  <Accordion title="Authentication errors">
    **Confirm API key environment**

    Ensure you're using test keys with test endpoints and live keys with production endpoints.

    **Check environment variable**

    Verify `DODO_PAYMENTS_ENVIRONMENT` is set correctly (`live_mode` for production).

    **Regenerate credentials**

    If issues persist, generate a new API key through your dashboard.
  </Accordion>

  <Accordion title="Tool execution failures">
    **Validate input parameters**

    Ensure the AI assistant is providing correctly formatted parameters for each tool.

    **Review error messages**

    Check the error response from the API for specific guidance on what went wrong.

    **Test with API directly**

    Verify the operation works when calling the Dodo Payments API directly via curl or Postman.
  </Accordion>
</AccordionGroup>

## Why Code Mode

Traditional MCP implementations often suffer from "tool proliferation," where every API endpoint is exposed as a separate tool. Code Mode is a superior approach for several reasons:

### LLMs are better at writing code than calling tools

LLMs have been trained on millions of lines of real-world code, making them naturally proficient at writing scripts. In contrast, tool-calling is often based on synthetic examples.

<Info>
  "Making an LLM perform tasks with tool calling is like putting Shakespeare through a month-long class in Mandarin and then asking him to write a play in it." — [Cloudflare](https://blog.cloudflare.com/code-mode/)
</Info>

### Eliminates context window bloat

In a traditional approach, every tool definition consumes tokens before the conversation even starts. Exposing 50+ tools can easily eat 55K–100K+ tokens. Anthropic found that tool definitions could consume up to 134K tokens before optimization.

With Code Mode, only 2 tool definitions are loaded (\~1K tokens). The agent searches for the documentation it needs on-demand. Anthropic's Tool Search Tool preserved 95% of the context window, reducing overhead from 77K to 8.7K tokens.

### Reduces latency via programmatic orchestration

Traditional tool-calling requires a full model inference round-trip for every single operation. If a task requires 20 API calls, that's 20 round-trips. In Code Mode, the agent writes one script that executes all calls and returns only the final result.

Anthropic observed a 37% reduction in tokens and improved accuracy (knowledge retrieval improved from 25.6% to 28.5%) using this programmatic approach.

### More secure by design

Code Mode provides inherent security benefits:

* **No API keys in parameters**: API keys are injected server-side and never exposed in the tool parameters sent to the LLM.
* **Isolated sandbox**: Code runs in a secure environment with no access to the network or the host filesystem.
* **Controlled SDK**: Only authorized SDK methods are available to the agent.

### Scales to any API size

As an API grows, traditional MCP performance degrades because more tools must be loaded into the context. Code Mode remains constant with 2 tools regardless of the API's surface area. Cloudflare successfully collapsed over 2,500 API endpoints into just 2 tools and approximately 1,000 tokens of context.

<Info>
  For more details on the benefits of this architecture, see the engineering blogs from [Anthropic](https://www.anthropic.com/engineering/advanced-tool-use) and [Cloudflare](https://blog.cloudflare.com/code-mode/), and the [Programmatic Tool Calling](https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling) documentation from Claude.
</Info>

## Resources

<CardGroup cols={2}>
  <Card title="API Reference" icon="book" href="/api-reference/introduction">
    Explore the complete Dodo Payments API documentation
  </Card>

  <Card title="MCP Protocol" icon="link" href="https://modelcontextprotocol.io">
    Learn more about the Model Context Protocol standard
  </Card>

  <Card title="GitHub Repository" icon="github" href="https://github.com/dodopayments/dodopayments-typescript/tree/main/packages/mcp-server">
    View the MCP server source code and contribute
  </Card>

  <Card title="NPM Package" icon="npm" href="https://www.npmjs.com/package/dodopayments-mcp">
    Install the MCP server from NPM
  </Card>
</CardGroup>
