feat(x402): optional x402 payment middleware for HTTP/SSE transports#2
Merged
feat(x402): optional x402 payment middleware for HTTP/SSE transports#2
Conversation
…ransports Problem\n- No way to call pay-protected MCP tools; HTTP/SSE requests need payment headers.\n\nSolution\n- Add optional x402 middleware that, when enabled per-server, injects payment headers into outgoing HTTP/SSE requests using a lazy-loaded x402 fetch wrapper.\n\nKey changes\n- src/types.ts: Extend McpServerConfig with `x402Middleware` (boolean | object) including wallet config and maxValueMicroUSDC.\n- src/transport-factory.ts: Wrap HTTP/SSE transports with x402 fetch when enabled; propagate headers/apiKey; add typed stdio options.\n- src/aggregator-server.ts & src/server-manager.ts: Log x402 enablement/limits per server.\n- src/x402.ts: Introduce helper to create x402-aware fetch and feature flags.\n- package.json: Add x402 and x402-fetch deps; add x402 test scripts.\n- examples/: Add example configs incl. Context7 x402 production, x402 example; update mixed-transports.\n- tests/: Add unit and e2e tests and configs for x402; add shell test harness.\n- tsconfig.json: Switch to NodeNext module/moduleResolution for ESM compatibility.\n- env.example: Document expected wallet env vars.\n\nNotes\n- Backward compatible: x402 is off by default unless `x402Middleware` is set/enabled.\n- README changes intentionally not included in this commit.\n- bun.lock is excluded from staging.\n\nFollow-ups\n- Document x402 configuration in README; add CI coverage for x402 tests.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Solution
x402Middleware(boolean | object). When enabled, HTTP/SSE transports use a lazy-created x402-awarefetchto inject payment headers.Key changes
src/types.ts: Addx402MiddlewaretoMcpServerConfigwith wallet config andmaxValueMicroUSDC.src/transport-factory.ts: Wrap HTTP/SSE transports with x402 fetch when enabled; propagateheaders/apiKey; strong typed stdio options.src/aggregator-server.ts&src/server-manager.ts: Log x402 enablement and per-server limits.src/x402.ts: Add helper to create x402 fetch and feature flag checks.package.json: Addx402/x402-fetchdeps; x402 test scripts.examples/: Add Context7 x402 production, x402 example; update mixed-transports.tests/: Add unit and e2e tests/configs; shell harness.tsconfig.json: Switch to NodeNext for ESM compatibility.env.example: Document wallet env var names.Notes
x402Middlewareis set/enabled.README.mdchanges deferred;bun.lockexcluded.Testing
npm run test:x402andnpm run test:x402:unitcover core flows; integration configs undertests/configs/*.Follow-ups
README.mdand add CI job for x402 tests.