feat: add additional MCP server support with x402 batch payment example#434
feat: add additional MCP server support with x402 batch payment example#434plagtech wants to merge 5 commits into
Conversation
|
|
|
Reviewed the multi-MCP routing path from an agent-payment safety angle. The extension point is useful, but I would add a collision guard before this is exposed as a payment-tool pattern. Right now additional MCP servers are merged into if (this.additionalClient && this.additionalClient.hasTool(name)) {
return this.additionalClient.callTool(name, args);
}
return this.mcpClient.callTool(name, args, options);If an additional server exposes a tool with the same name as a Stripe core tool, it can shadow the Stripe tool at execution time. Depending on framework behavior, duplicate function/tool names may also produce invalid or ambiguous tool schemas for the model. For a payment toolkit, that is a risky default because an untrusted or misconfigured external MCP server could receive calls the developer expected to go to Stripe. Suggested fix before merge:
This is docs/code review only; I did not call external MCP servers or payment endpoints. |
|
Good catch — you're right that additional tools shouldn't be able to shadow core Stripe operations. Pushed a fix: Collision guard: MultiMcpClient.setReservedNames() receives all Stripe tool names before connecting additional servers. Any tool that shares a name with a Stripe tool is silently skipped with a console warning. |
|
Thanks for patching the collision case. I checked the new head and the guard looks directionally right: core Stripe names are reserved before additional MCP servers connect, and colliding external tools are skipped before routing can reach them. The current blocker appears to be CI/lint rather than the collision design itself. The failing TypeScript job is
I did not call any external MCP servers or payment endpoints. This is based on the GitHub Actions log for the failing TypeScript job on |
|
Thanks for the detailed breakdown — really appreciate you pulling the CI log. Pushing fixes now:
Will update shortly. |
feat: Add support for additional MCP servers with x402 batch payment example
Problem
The Stripe Agent Toolkit currently connects exclusively to
mcp.stripe.comfor its tools. While the core Stripe tools handle individual operations well (create_payment_link, create_invoice, etc.), agents frequently need to perform batch operations — paying multiple contractors, splitting revenue across recipients, or processing bulk refunds.Today, an agent handling "pay these 5 contractors" must loop through individual
create_transfercalls. There's no batch primitive, and no way to extend the toolkit with additional payment capabilities from external providers.Solution
This PR adds support for additional MCP servers whose tools are merged with the core Stripe tools. This enables:
How it works
When the agent calls a tool:
mcp.stripe.comas beforeWhy x402
Stripe already supports the x402 payment protocol on Base. This PR extends that support into the agent toolkit by enabling x402-based batch payments — settling multiple transfers in a single on-chain transaction via USDC.
Changes
Core changes (backward compatible)
configuration.ts: AddedAdditionalMcpServertype andadditionalMcpServersconfig optionmulti-mcp-client.ts: New client that manages connections to additional MCP servers with tool routingtoolkit-core.ts: Extendedinitialize()to connect additional servers; addedrouteToolCall()for transparent routingFramework updates
openai/toolkit.ts: UpdatedhandleToolCall()to userouteToolCall()for correct routinglangchain/toolkit.ts: UpdatedStripeToolto route throughToolkitCoreinstead of directmcpClientaccessai-sdk/toolkit.ts: Updatedexecutecallbacks to userouteToolCall()Example & tests
examples/batch-payments/: Complete example showing x402 batch payments with Spraay Protocoltest/shared/multi-mcp-client.test.ts: Unit tests for the multi-MCP clientBackward compatibility
additionalMcpServersconfig is optional and defaults toundefinedTesting