Skip to content

Commit 2c863da

Browse files
authored
Merge pull request #13 from mark3labs/007-mcp-integration
MCP Integration (mcp-go)
2 parents 38fdeee + 5fdeb85 commit 2c863da

File tree

26 files changed

+3671
-8
lines changed

26 files changed

+3671
-8
lines changed

.beads/issues.jsonl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
{"id":"x402-go-1","title":"Remove DEBUG log statements from production code","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-10-29T17:25:43.770299599+03:00","updated_at":"2025-10-29T20:14:38.315218628+03:00","closed_at":"2025-10-29T20:14:38.315218628+03:00"}
2-
{"id":"x402-go-10","title":"Add godoc package documentation for all public packages","description":"Add godoc package documentation for all public packages. CDP signer (signers/coinbase) already has comprehensive GoDoc comments. Still needed for: http/, evm/, svm/, and root package.","status":"open","priority":3,"issue_type":"task","created_at":"2025-10-29T17:26:00.049130692+03:00","updated_at":"2025-10-30T15:06:57.195088706+03:00"}
2+
{"id":"x402-go-10","title":"Add godoc package documentation for all public packages","description":"","status":"open","priority":3,"issue_type":"task","created_at":"2025-10-29T17:26:00.049130692+03:00","updated_at":"2025-10-29T17:26:00.049130692+03:00"}
33
{"id":"x402-go-11","title":"types.go AmountToBigInt silently discards accuracy information","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-10-29T17:26:00.871179508+03:00","updated_at":"2025-10-29T20:14:36.210574163+03:00","closed_at":"2025-10-29T20:14:36.210574163+03:00"}
44
{"id":"x402-go-12","title":"http/client.go GetSettlement silently returns nil on parse errors","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-10-29T17:26:01.295078602+03:00","updated_at":"2025-10-29T20:14:35.399267019+03:00","closed_at":"2025-10-29T20:14:35.399267019+03:00"}
55
{"id":"x402-go-13","title":"http/facilitator.go should have configurable retry logic for facilitator failures","description":"","status":"closed","priority":2,"issue_type":"feature","created_at":"2025-10-29T17:26:01.361852264+03:00","updated_at":"2025-10-29T20:14:34.460462839+03:00","closed_at":"2025-10-29T20:14:34.460462839+03:00"}
6-
{"id":"x402-go-14","title":"Create issue to refactor local signers (evm/, svm/) to signers/evm and signers/svm in future PR","description":"","status":"closed","priority":3,"issue_type":"task","created_at":"2025-10-30T13:22:34.496743751+03:00","updated_at":"2025-10-30T17:28:30.095967169+03:00","closed_at":"2025-10-30T17:28:30.095967169+03:00"}
7-
{"id":"x402-go-15","title":"Create issue to refactor local signers (evm/, svm/) to signers/evm and signers/svm in future PR","description":"","status":"closed","priority":3,"issue_type":"task","created_at":"2025-10-30T13:22:37.735819263+03:00","updated_at":"2025-10-30T15:06:55.216825329+03:00","closed_at":"2025-10-30T15:06:55.216825329+03:00"}
8-
{"id":"x402-go-16","title":"Phase 7: Implement User Story 4 - Error Handling and Retry Logic for CDP signer","description":"","status":"closed","priority":1,"issue_type":"task","created_at":"2025-10-30T14:53:56.962210163+03:00","updated_at":"2025-10-30T14:58:09.892386737+03:00","closed_at":"2025-10-30T14:58:09.892386737+03:00"}
9-
{"id":"x402-go-17","title":"Phase 8: Implement User Story 6 - Multi-Chain Support testing for CDP signer","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-10-30T14:53:57.90470763+03:00","updated_at":"2025-10-30T15:02:30.219577791+03:00","closed_at":"2025-10-30T15:02:30.219577791+03:00"}
10-
{"id":"x402-go-18","title":"Phase 9: Polish and documentation for CDP signer","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-10-30T14:53:58.7000909+03:00","updated_at":"2025-10-30T15:03:12.358091619+03:00","closed_at":"2025-10-30T15:03:12.358091619+03:00"}
11-
{"id":"x402-go-19","title":"CDP Signer Implementation Complete - PR #10","description":"CDP signer implementation complete and merged in PR #10.\n\n**Implementation:**\n- 11 new files in signers/coinbase/ (6 source, 5 test)\n- 5,746 total lines of code\n- 84 passing tests with 69.8% coverage\n- Zero breaking changes\n\n**Features:**\n- CDP authentication with JWT signing\n- HTTP client with retry logic and error handling\n- Support for EVM (Base, Ethereum, Polygon) and SVM (Solana) networks\n- EIP-3009 and SPL Token TransferChecked signing\n- Automatic account creation and management\n- Multi-chain stateless design\n\n**Status:**\n✅ Phase 1-6: Core implementation complete\n✅ Phase 7: Error handling \u0026 retry logic\n✅ Phase 8: Multi-chain support validation\n✅ Phase 9: Polish and quality assurance\n✅ Committed and pushed to branch 006-cdp-signer\n✅ PR #10 created: https://github.com/mark3labs/x402-go/pull/10\n\n**Next Steps:**\n- Await PR review\n- Address any feedback\n- Merge to main","status":"closed","priority":1,"issue_type":"feature","created_at":"2025-10-30T15:07:03.4494984+03:00","updated_at":"2025-10-30T15:07:14.321726793+03:00","closed_at":"2025-10-30T15:07:14.321726793+03:00","dependencies":[{"issue_id":"x402-go-19","depends_on_id":"x402-go-16","type":"discovered-from","created_at":"2025-10-30T15:07:03.459568291+03:00","created_by":"daemon"},{"issue_id":"x402-go-19","depends_on_id":"x402-go-17","type":"discovered-from","created_at":"2025-10-30T15:07:03.462047835+03:00","created_by":"daemon"},{"issue_id":"x402-go-19","depends_on_id":"x402-go-18","type":"discovered-from","created_at":"2025-10-30T15:07:03.464070914+03:00","created_by":"daemon"}]}
126
{"id":"x402-go-2","title":"Error handling bug in handler.go sendPaymentRequiredWithRequirements","description":"","status":"closed","priority":1,"issue_type":"bug","created_at":"2025-10-29T17:25:44.911411053+03:00","updated_at":"2025-10-29T17:30:51.891979853+03:00","closed_at":"2025-10-29T17:30:51.891979853+03:00"}
13-
{"id":"x402-go-20","title":"Add token address format validation for network type (EVM vs Solana)","description":"Add validation to ensure token addresses match the network type:\n- EVM networks (base, base-sepolia, polygon, etc.) should validate 0x-prefixed hex addresses (42 chars)\n- Solana networks (solana, solana-devnet) should validate base58 addresses (32-44 chars)\n\nThis prevents runtime errors like 'invalid base58 digit' when using EVM addresses on Solana networks.\n\nAffected components:\n- signers/coinbase/signer.go: WithToken() and WithTokenPriority() options\n- svm/signer.go: WithToken() and WithTokenPriority() options \n- evm/signer.go: WithToken() and WithTokenPriority() options\n\nImplementation:\n- Add helper function ValidateTokenAddress(network, address string) error\n- Call in signer option functions before appending to tokens list\n- Return descriptive error (e.g., 'token address 0x123... is invalid for Solana network, expected base58 format')\n\nDiscovered during CDP signer testing when EVM USDC address was used for solana-devnet.","status":"open","priority":2,"issue_type":"task","created_at":"2025-10-30T16:53:00.227839944+03:00","updated_at":"2025-10-30T16:53:20.1556879+03:00"}
147
{"id":"x402-go-3","title":"Potential case-sensitivity issue in token address matching","description":"","status":"closed","priority":2,"issue_type":"bug","created_at":"2025-10-29T17:25:45.967861712+03:00","updated_at":"2025-10-29T20:14:39.09993865+03:00","closed_at":"2025-10-29T20:14:39.09993865+03:00"}
158
{"id":"x402-go-4","title":"DEBUG log statements should be removed or guarded by log level","description":"","status":"closed","priority":2,"issue_type":"task","created_at":"2025-10-29T17:25:52.122397206+03:00","updated_at":"2025-10-29T20:14:37.954623981+03:00","closed_at":"2025-10-29T20:14:37.954623981+03:00"}
169
{"id":"x402-go-5","title":"http/handler.go sendPaymentRequired has error handling bug after headers sent","description":"","status":"closed","priority":1,"issue_type":"bug","created_at":"2025-10-29T17:25:53.303006718+03:00","updated_at":"2025-10-29T17:30:51.694604235+03:00","closed_at":"2025-10-29T17:30:51.694604235+03:00"}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ bin/
5353
examples/x402demo/x402demo
5454
examples/gin/gin
5555
examples/gin/gin-example
56+
examples/mcp/mcp

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ For more details, see README.md and QUICKSTART.md.
133133
- Go 1.25.1 + PocketBase framework (github.com/pocketbase/pocketbase/core), existing x402-go core package (005-pocketbase-middleware)
134134
- N/A (stateless middleware, payment tracking delegated to facilitator) (005-pocketbase-middleware)
135135
- N/A (stateless signer, CDP manages wallet state) (006-cdp-signer)
136+
- Go 1.25.1 + github.com/mark3labs/mcp-go (latest stable release - MCP protocol), existing x402-go components (007-mcp-integration)
137+
- N/A (stateless middleware and transport) (007-mcp-integration)
136138

137139
## Recent Changes
138140
- 005-pocketbase-middleware: Added PocketBase middleware adapter for x402 payment gating

examples/mcp/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# MCP x402 Example
2+
3+
This example demonstrates both client and server implementations of MCP with x402 payment integration.
4+
5+
## Usage
6+
7+
### Server Mode
8+
9+
Start an MCP server with free and paid tools:
10+
11+
```bash
12+
go run . -mode server -pay-to 0xYOUR_WALLET_ADDRESS
13+
```
14+
15+
Options:
16+
- `-port` - Server port (default: 8080)
17+
- `-pay-to` - Payment recipient address (required for server mode)
18+
- `-facilitator` - Facilitator URL (default: https://facilitator.x402.rs)
19+
- `-verify-only` - Only verify payments, don't settle (useful for testing)
20+
- `-testnet` - Use Base Sepolia testnet
21+
- `-v` - Verbose logging
22+
23+
### Client Mode
24+
25+
Connect to an MCP server and call tools:
26+
27+
```bash
28+
go run . -mode client -key YOUR_PRIVATE_KEY -server http://localhost:8080
29+
```
30+
31+
Options:
32+
- `-server` - MCP server URL (default: http://localhost:8080)
33+
- `-key` - Private key for signing payments (required for client mode)
34+
- `-network` - Network to use (default: base)
35+
- `-testnet` - Use Base Sepolia testnet
36+
- `-v` - Verbose logging
37+
38+
## Example Session
39+
40+
Terminal 1 (Server):
41+
```bash
42+
# Start server with payment address
43+
go run . -mode server -pay-to 0x1234567890123456789012345678901234567890 -v
44+
```
45+
46+
Terminal 2 (Client):
47+
```bash
48+
# Run client with private key
49+
go run . -mode client -key 0xYOUR_PRIVATE_KEY -v
50+
```
51+
52+
The client will:
53+
1. Connect to the MCP server
54+
2. List available tools (echo - free, search - paid)
55+
3. Call the echo tool (no payment required)
56+
4. Call the search tool (automatically handles payment)
57+
58+
## Tools
59+
60+
### Free Tool: echo
61+
- Description: Echoes back the input message
62+
- Arguments: `message` (string, required)
63+
- Payment: None required
64+
65+
### Paid Tool: search
66+
- Description: Premium search service
67+
- Arguments: `query` (string, required), `max_results` (number, optional)
68+
- Payment: 0.01 USDC on Base (or Base Sepolia if using -testnet)

examples/mcp/go.mod

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module github.com/mark3labs/x402-go/examples/mcp
2+
3+
go 1.25.1
4+
5+
replace github.com/mark3labs/x402-go => ../..
6+
7+
require (
8+
github.com/mark3labs/mcp-go v0.42.0
9+
github.com/mark3labs/x402-go v0.0.0-00010101000000-000000000000
10+
)
11+
12+
require (
13+
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
14+
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
15+
github.com/bahlo/generic-list-go v0.2.0 // indirect
16+
github.com/bits-and-blooms/bitset v1.24.2 // indirect
17+
github.com/buger/jsonparser v1.1.1 // indirect
18+
github.com/consensys/gnark-crypto v0.19.2 // indirect
19+
github.com/crate-crypto/go-eth-kzg v1.4.0 // indirect
20+
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
21+
github.com/deckarep/golang-set/v2 v2.8.0 // indirect
22+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
23+
github.com/ethereum/c-kzg-4844/v2 v2.1.5 // indirect
24+
github.com/ethereum/go-ethereum v1.16.5 // indirect
25+
github.com/ethereum/go-verkle v0.2.2 // indirect
26+
github.com/fsnotify/fsnotify v1.9.0 // indirect
27+
github.com/google/uuid v1.6.0 // indirect
28+
github.com/holiman/uint256 v1.3.2 // indirect
29+
github.com/invopop/jsonschema v0.13.0 // indirect
30+
github.com/mailru/easyjson v0.7.7 // indirect
31+
github.com/spf13/cast v1.10.0 // indirect
32+
github.com/supranational/blst v0.3.16 // indirect
33+
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
34+
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
35+
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
36+
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
37+
golang.org/x/crypto v0.43.0 // indirect
38+
golang.org/x/sync v0.17.0 // indirect
39+
golang.org/x/sys v0.37.0 // indirect
40+
gopkg.in/yaml.v3 v3.0.1 // indirect
41+
)

0 commit comments

Comments
 (0)