Conversation
Adds mcpc x402 subcommands: init, import, list, remove, sign. Wallets stored in ~/.mcpc/wallets.json. Signing parses PAYMENT-REQUIRED headers and produces PAYMENT-SIGNATURE for x402 payment protocol.
Implement automatic x402 payment signing when calling paid MCP tools. The --x402 global flag enables auto-payment using the default wallet. Architecture: - Shared signer module (src/lib/x402/signer.ts) for EIP-3009 typed data signing - Fetch middleware (src/lib/x402/fetch-middleware.ts) wraps SDK's fetch with: - Proactive signing: reads _meta.x402 from cached tools list, signs before request - 402 fallback: if server returns HTTP 402, parses PAYMENT-REQUIRED header, signs, retries once - Bridge receives wallet credentials via IPC (set-x402-wallet message type) - Bridge maintains its own tools cache for proactive signing (populated on connect, updated via listChanged notifications) - Direct connections (withMcpClient) only support 402 fallback (no persistent tools cache) - customFetch option threaded through transports.ts -> factory.ts -> SDK transport Known issues and TODOs: - --x402 is currently a boolean flag (always uses 'default' wallet). Supporting --x402 [wallet-name] with optional value is blocked by Commander.js not being able to disambiguate optional option values from subcommands. Options considered: (a) pre-process args to convert '--x402 name' to '--x402=name' before Commander, (b) use separate --x402-wallet <name> option, (c) strip --x402 from Commander args and re-inject via closure. All approaches were prototyped but add significant complexity. For now --x402 uses the default wallet; named wallets can wait. - No unit tests yet for signer.ts and fetch-middleware.ts - No E2E test with the demo x402 server - Interactive shell does not support --x402 (only direct commands and sessions) - Direct connections don't have proactive signing (no tools cache), only 402 fallback - Pre-existing flaky test: sessions/bridge-resilience occasionally fails (unrelated)
Drop multi-wallet support (named wallets, --name options, defaultWallet)
in favor of a single wallet stored in ~/.mcpc/wallets.json with a
versioned format { version: 1, wallet?: WalletData }.
- Remove wallet names from WalletData, X402WalletCredentials, SessionData
- Replace SessionData.walletName with x402 boolean flag
- Simplify wallets.ts CRUD to operate on single wallet
- Rename 'list' command to 'info', remove --name from all x402 commands
- Update bridge IPC: --wallet <name> arg becomes --x402 boolean flag
- Update all callsites (bridge-manager, sessions, helpers, parser, CLI)
This avoids Commander.js optional-arg parsing complexity for --x402
[wallet-name] and matches the actual use case (one wallet per user).
Multi-wallet can be added later with --x402-wallet <name> if needed.
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.
Summary
Add x402 payment protocol support — automatic USDC payments for paid MCP tools on Base/Base Sepolia.
mcpc x402 init|import|info|remove|signfor wallet management--x402flag enables auto-payment on both direct and session connections_meta.x402from tools list) and 402 fallback (retry on HTTP 402)~/.mcpc/wallets.json(versioned format,0600perms)viemfor EIP-3009 signing, customfetchwrapper via SDK transportTested e2e against local x402 demo server (direct + bridge, paid + free tools). All existing tests pass except pre-existing flaky
bridge-resilience(parallel test pollution causes INVARIANT VIOLATION — unrelated to x402).