Our MCP Server Just Got a Major Upgrade: Code Mode Is Here
Build with us
We're building the payments and billing platform for SaaS, AI, and digital products. Come help us ship.
View Open PositionsThe way AI agents interact with APIs is changing fast. For months, the standard MCP (Model Context Protocol) approach has been to expose every API endpoint as its own tool - give the agent a massive catalog and let it pick the right one. It works, but it’s expensive, slow, and brittle at scale.
Today, we’re rolling out a fundamentally different architecture for the Dodo Payments MCP Server: Code Mode. Instead of hundreds of individual tools, your AI agent now gets just two - and it’s better at everything.
What Changed
The previous version of our MCP server followed the conventional pattern. Every API operation - creating a payment, managing subscriptions, issuing refunds, checking license keys - was its own discrete tool. That meant the agent’s context window was loaded with dozens of tool definitions before it even started working.
The new architecture strips all of that away. Your agent now interacts with two tools:
- Docs Search - a semantic search tool that lets the agent query Dodo Payments API and SDK documentation to understand what’s available and how to use it.
- Code Execution - a sandboxed TypeScript runtime where the agent writes and executes code directly against our SDK. That’s it. Two tools. Full access to the entire Dodo Payments API surface.
The Architecture at a Glance
Here’s how the two approaches compare:
Before: One Tool Per Endpoint
┌─────────────────────────────────────────────────────┐
│ AI Agent Context │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ create_ │ │ get_ │ │ list_ │ │
│ │ payment │ │ payment │ │ payments │ │
│ │ (850 tokens) │ │ (620 tokens) │ │ (780 tkns) │ │
│ └──────────────┘ └──────────────┘ └────────────┘ │
│ ┌──────────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ create_ │ │ cancel_ │ │ update_ │ │
│ │ subscription │ │ subscription │ │subscription│ │
│ │ (920 tokens) │ │ (540 tokens) │ │ (870 tkns) │ │
│ └──────────────┘ └──────────────┘ └────────────┘ │
│ ┌──────────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ create_ │ │ get_ │ │ activate_ │ │
│ │ refund │ │ customer │ │ license │ │
│ │ (680 tokens) │ │ (590 tokens) │ │ (720 tkns) │ │
│ └──────────────┘ └──────────────┘ └────────────┘ │
│ │
│ ... + 40 more tools = ~55,000 tokens total │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Remaining context for actual reasoning: │ │
│ │ ████░░░░░░░░░░░░░░░░ ~20% │ │
│ └──────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘
After: Code Mode (Two Tools)
┌─────────────────────────────────────────────────────┐
│ AI Agent Context │
│ │
│ ┌──────────────────┐ ┌───────────────────────┐ │
│ │ docs_search │ │ execute_code │ │
│ │ (480 tokens) │ │ (520 tokens) │ │
│ └──────────────────┘ └───────────────────────┘ │
│ │
│ Total: ~1,000 tokens │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Remaining context for actual reasoning: │ │
│ │ ████████████████████████████████████ ~95% │ │
│ └──────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘
Why This Matters
The shift to Code Mode isn’t a cosmetic change. It addresses the three biggest pain points developers have been hitting with MCP-based agent workflows.
Context Window Efficiency
Traditional MCP tool definitions are verbose. For a mid-size API, you’re looking at 55K to 100K+ tokens just to describe the available tools before any actual work happens. For larger APIs, this becomes absurd - Cloudflare’s 2,500-endpoint API would require roughly 1.17 million tokens worth of tool definitions.
Code Mode collapses all of that into approximately 1,000 tokens. That’s a 95%+ reduction in context overhead for Dodo Payments, and it means your agent has dramatically more room to actually reason about the task at hand.
Token Usage Comparison
──────────────────────────────────────────────
Traditional (tool-per-endpoint):
Tool definitions: ████████████████████████████████████ 55,000 tokens
Agent reasoning: ████████ ~20% of context
Code Mode:
Tool definitions: █ 1,000 tokens
Agent reasoning: ████████████████████████████████████ ~95% of context
Reduction: 95%+
Accuracy and Fewer Round-Trips
When an agent has to pick from a long list of tools, call one, interpret the result, pick another, and repeat - errors compound. Each round-trip is an opportunity for the model to misinterpret a parameter or choose the wrong endpoint.
With Code Mode, the agent writes a single TypeScript script that can chain multiple API calls, handle conditional logic, and perform calculations - all in one execution. Research from Anthropic’s engineering team and benchmarks by Stainless have shown this approach delivers a 37% reduction in tokens used and meaningfully improved accuracy. In Stainless’s evaluations, Code Mode achieved near-perfect completeness, scoring 1.0 on 30 of 31 test cases.
Here’s what that difference looks like for a real task - “create a subscription for a customer with usage-based billing and send them a license key”:
Before: Traditional MCP (5 tool calls, 5 round-trips)
Agent -> get_customer(email: "acme@example.com") # Round trip 1
create_product(name: "Pro Plan", ...) # Round trip 2
create_subscription( # Round trip 3
customer_id: "cust_abc123",
product_id: "prod_xyz789",
billing_type: "usage_based"
)
create_license_key( # Round trip 4
subscription_id: "sub_def456",
activations_limit: 5
)
get_subscription(subscription_id: "sub_def456") # Round trip 5
│ API │
│ │ ⚠ Key visible in │ │
│ │ context window │ │
│ │ ⚠ Key in tool call logs │ │
└──────────┘ └──────────┘
Code Mode:
┌──────────┐ Code only (no keys) ┌──────────────┐ API Key injected ┌──────────┐
│ Agent │ ──────────────────────> │ Sandbox │ ─────────────────────> │ API │
│ │ │ (isolated) │ │ │
│ │ ✓ No key in context │ No web │ ✓ Key server-side │ │
│ │ ✓ No key in logs │ No filesystem│ ✓ Never exposed │ │
└──────────┘ └──────────────┘ └──────────┘
In the traditional model, API keys often had to be passed as tool parameters, creating surface area for leaks. With Code Mode, your credentials are injected server-side into the sandbox. They never appear in tool parameters, never flow through the model’s context, and never show up in logs. The sandbox itself runs without web or filesystem access, so even if something goes wrong, the blast radius is contained.
The Agent Workflow: How It Actually Works
Here’s the step-by-step flow when an agent uses our Code Mode MCP server:
User: "Set up usage-based billing for Acme Corp's Pro plan"
│
▼
┌─────────────────────┐
│ 1. Agent searches │
│ documentation │
│ │
│ Tool: docs_search │
│ Query: "usage │
│ based billing │
│ subscription" │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ 2. Agent receives │
│ SDK examples, │
│ type signatures,│
│ and guides │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ 3. Agent writes │
│ TypeScript code │
│ using the SDK │
│ │
│ Tool: execute_code │
│ - Chains API calls │
│ - Handles errors │
│ - Returns results │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ 4. Code executes │
│ in sandbox │
│ │
│ - No web access │
│ - No filesystem │
│ - Keys injected │
│ server-side │
└──────────┬──────────┘
│
▼
┌─────────────────────┐
│ 5. Agent returns │
│ structured │
│ result to user │
└─────────────────────┘
Two tool calls total. The first fetches context, the second executes the entire workflow.
Real-World Example: Handling a Refund with Usage Adjustment
To show how Code Mode handles more complex logic, here’s an example where an agent needs to process a partial refund and adjust the customer’s usage meter - something that would require careful orchestration with the traditional approach:
// The agent writes this as a single code execution:
// Step 1: Look up the payment and associated subscription
const payment = await client.payments.get("pay_abc123");
const subscription = await client.subscriptions.get(
payment.subscription_id
);
// Step 2: Calculate prorated refund amount
const daysUsed = 12;
const totalDays = 30;
const fullAmount = payment.total_amount;
const refundAmount = Math.round(fullAmount * ((totalDays - daysUsed) / totalDays));
// Step 3: Issue the partial refund
const refund = await client.refunds.create({
payment_id: payment.payment_id,
amount: refundAmount,
reason: "Prorated refund - plan downgrade"
});
// Step 4: Update the subscription to the lower tier
const updated = await client.subscriptions.update(
subscription.subscription_id,
{ product_id: "prod_basic_plan" }
);
console.log({
refund_id: refund.refund_id,
refund_amount: refundAmount,
new_plan: "Basic",
subscription_status: updated.status
});
With the traditional approach, this would be four separate tool calls with the agent doing arithmetic in its reasoning steps (error-prone). With Code Mode, the math happens in TypeScript - deterministic and correct every time.
The Industry Is Moving This Way
We’re not alone in making this shift. The Code Mode architecture has been gaining momentum across the ecosystem.
Company What They Did Result
─────────────────────────────────────────────────────────────────────────
Cloudflare 2,500 endpoints -> 2 Code Mode tools 99.9% token reduction
Anthropic Published code-execution-with-MCP research 98.7% context savings
Stainless Made Code Mode the default for all MCP servers 95% efficiency in benchmarks
Dodo Payments Migrated to Code Mode via Stainless 95%+ token reduction
Cloudflare published a detailed write-up on how they collapsed over 2,500 API endpoints into two Code Mode tools. Anthropic’s engineering team published research showing that code execution within MCP reduces context overhead by 98.7% in their benchmarks and enables agents to process large datasets without flowing raw data through the model. Stainless, whose infrastructure powers our MCP server generation, has moved to Code Mode as their default and only architecture for MCP servers - a strong signal that this is where the industry is headed.
Built with Stainless
We want to give proper credit here: our MCP server is generated and maintained using Stainless. Their tooling handles the heavy lifting of turning our OpenAPI specification into a production-ready MCP server with Code Mode baked in.
┌────────────────┐ ┌──────────────┐ ┌──────────────────┐
│ Dodo Payments │ │ │ │ Production MCP │
│ OpenAPI Spec │ ──────>│ Stainless │ ──────> │ Server with │
│ │ │ │ │ Code Mode │
└────────────────┘ └──────────────┘ └──────────────────┘
│
▼
┌──────────────┐
│ TypeScript │
│ SDK │
│ (idiomatic, │
│ typed) │
└──────────────┘
Stainless has been at the forefront of this architectural shift. Their research demonstrated that SDK-based code execution achieves state-of-the-art accuracy for agents operating APIs via MCP. When agents generate code using idiomatic SDKs, consult both API reference and narrative documentation, and receive structured error messages, they produce correct results with significantly fewer turns and less token overhead. In their benchmarks, the Stainless Code Mode architecture averaged 95% efficiency - solving problems in fewer turns than any alternative approach they tested.
By building on Stainless, we get these improvements automatically as they continue to refine their MCP infrastructure. When Stainless ships an optimization, our server benefits. That’s the kind of leverage that lets a team like ours stay at the cutting edge without maintaining the underlying MCP plumbing ourselves.
What This Looks Like in Practice
Getting started is straightforward. You can connect to our hosted MCP server without any local installation:
https://mcp.dodopayments.com/sse
Or run it locally via npx:
export DODO_PAYMENTS_API_KEY="your-api-key"
export DODO_PAYMENTS_ENVIRONMENT="live_mode"
npx -y dodopayments-mcp@latest
We support one-click setup for Cursor, Claude Desktop, VS Code, Windsurf, Claude Code, Cline, and Zed. Configuration details are in our updated documentation.
The Bigger Picture: Two Servers, Complete Coverage
We run a dual-server architecture that gives agents full understanding and full control:
┌──────────────────────────────────────────────────────────────┐
│ AI Agent │
└──────────────┬───────────────────────────────┬───────────────┘
│ │
▼ ▼
┌──────────────────────────┐ ┌──────────────────────────────┐
│ Dodo Knowledge MCP │ │ Dodo Payments MCP │
│ │ │ (Code Mode) │
│ - Semantic doc search │ │ │
│ - Vector embeddings │ │ - docs_search tool │
│ - No API key needed │ │ - execute_code tool │
│ - No local setup │ │ - Sandboxed TypeScript │
│ │ │ - Full API access │
│ Powered by ContextMCP │ │ Powered by Stainless │
└──────────────────────────┘ └──────────────────────────────┘
│ │
│ "How does usage-based │ "Create a subscription
│ billing work?" │ with usage metering
│ │ for Acme Corp"
▼ ▼
Understanding Action
Together, these two servers give AI agents everything they need to understand and operate the Dodo Payments platform without human intervention on routine payment operations.
What’s Next
Code Mode is live today. If you’re already using the Dodo Payments MCP server, the upgrade is seamless - just update to the latest version and your agent will automatically use the new two-tool architecture.
If you’re new to building with AI agents and payment infrastructure, there’s never been a better time to start. The combination of Code Mode’s efficiency and our SDK’s coverage means your agent can handle complex, multi-step payment workflows that would have been impractical with the old tool-per-endpoint approach.
Check out the full documentation, and if you have questions, reach out to us. We’d love to hear what you build.
Build with us
We're building the payments and billing platform for SaaS, AI, and digital products. Come help us ship.
View Open Positions