feat: Anthropic SDK Integration + Complete x402 Payment Support#5
Merged
feat: Anthropic SDK Integration + Complete x402 Payment Support#5
Conversation
|
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 (beta)
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. Comment |
fbc53ea to
919dd18
Compare
fee5924 to
5c3b6b3
Compare
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
This PR adds complete x402 payment support with Anthropic SDK integration for AI agents. Agents can now autonomously pay for gateway tools using blockchain payments.
✅ What Was Achieved
1. Anthropic SDK Integration
any/unknownwhere avoidable)2. x402 Payment Protocol - FULLY WORKING 🚀
useFacilitator,exact.evm.decodePayment)3. Payment Architecture
Key Innovation: Two-layer architecture separates HTTP payment handling from MCP protocol, allowing proper 402 status codes while maintaining MCP compatibility.
4. New Files
src/transports/http-wrapper.ts- HTTP/SSE server with x402 (345 lines)src/transports/sse-server.ts- SSE transport implementation (316 lines)example-agents/ai16z-price-agent.ts- Anthropic SDK example (stdio)example-agents/ai16z-price-agent-sse.ts- Anthropic SDK + x402 (SSE)example-agents/run-gateway-sse.sh- Helper script to start HTTP wrapperexamples/coingecko-*-config.yaml- Various test configurations5. Enhanced Files
src/core/payment-middleware.ts- Proper x402 SDK usage withuseFacilitator()example-agents/package.json- Added @anthropic-ai/sdk, x402-fetch📊 Testing Results
✅ All Tests Passing
stdio agent (free config):
$ bun run ai16z-price-agent.ts [Agent] Connected to MCP Gateway [Agent] Result: The current price of the AI16Z token is $0.097646 USD.SSE agent (x402 payments):
Payment Verification Logs
📦 Dependencies Added
@anthropic-ai/sdk: ^0.65.0x402-fetch: ^0.6.6x402: ^0.6.6 (gateway)🔧 How to Use
Start HTTP Wrapper with x402 Support
cd example-agents ./run-gateway-sse.shRun Anthropic SDK Agent with Payments
cd example-agents ANTHROPIC_API_KEY=your_key WALLET_PRIVATE_KEY=your_wallet bun run ai16z-price-agent-sse.tsRun Free Version (stdio)
cd example-agents ANTHROPIC_API_KEY=your_key bun run ai16z-price-agent.ts🌟 Key Features
📚 References
🎯 Impact
This implementation enables:
Tested on Base Sepolia with real payments and tool calls. Ready for production use.