gatepay-local-mcp 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/Readme.md +271 -69
  2. package/dist/src/index.js +573 -104
  3. package/dist/src/index.js.map +1 -1
  4. package/dist/src/modes/build-pay-fetch.d.ts +3 -2
  5. package/dist/src/modes/build-pay-fetch.d.ts.map +1 -1
  6. package/dist/src/modes/build-pay-fetch.js +20 -4
  7. package/dist/src/modes/build-pay-fetch.js.map +1 -1
  8. package/dist/src/modes/local-private-key.d.ts.map +1 -1
  9. package/dist/src/modes/local-private-key.js +31 -10
  10. package/dist/src/modes/local-private-key.js.map +1 -1
  11. package/dist/src/modes/plugin-wallet.d.ts +12 -0
  12. package/dist/src/modes/plugin-wallet.d.ts.map +1 -1
  13. package/dist/src/modes/plugin-wallet.js +229 -9
  14. package/dist/src/modes/plugin-wallet.js.map +1 -1
  15. package/dist/src/modes/quick-wallet.d.ts +4 -0
  16. package/dist/src/modes/quick-wallet.d.ts.map +1 -1
  17. package/dist/src/modes/quick-wallet.js +46 -21
  18. package/dist/src/modes/quick-wallet.js.map +1 -1
  19. package/dist/src/modes/registry.d.ts.map +1 -1
  20. package/dist/src/modes/registry.js +10 -6
  21. package/dist/src/modes/registry.js.map +1 -1
  22. package/dist/src/modes/signers.d.ts +38 -1
  23. package/dist/src/modes/signers.d.ts.map +1 -1
  24. package/dist/src/modes/signers.js +447 -5
  25. package/dist/src/modes/signers.js.map +1 -1
  26. package/dist/src/modes/types.d.ts +16 -1
  27. package/dist/src/modes/types.d.ts.map +1 -1
  28. package/dist/src/wallets/plugin-wallet-client.d.ts +10 -0
  29. package/dist/src/wallets/plugin-wallet-client.d.ts.map +1 -1
  30. package/dist/src/wallets/plugin-wallet-client.js +32 -3
  31. package/dist/src/wallets/plugin-wallet-client.js.map +1 -1
  32. package/dist/src/wallets/wallet-mcp-clients.d.ts.map +1 -1
  33. package/dist/src/wallets/wallet-mcp-clients.js +2 -2
  34. package/dist/src/wallets/wallet-mcp-clients.js.map +1 -1
  35. package/dist/src/x402/exactSvmScheme.d.ts +20 -0
  36. package/dist/src/x402/exactSvmScheme.d.ts.map +1 -0
  37. package/dist/src/x402/exactSvmScheme.js +38 -0
  38. package/dist/src/x402/exactSvmScheme.js.map +1 -0
  39. package/dist/src/x402/fetch.d.ts.map +1 -1
  40. package/dist/src/x402/fetch.js +2 -0
  41. package/dist/src/x402/fetch.js.map +1 -1
  42. package/dist/src/x402/types.d.ts +5 -0
  43. package/dist/src/x402/types.d.ts.map +1 -1
  44. package/dist/src/x402/types.js +0 -3
  45. package/dist/src/x402/types.js.map +1 -1
  46. package/package.json +22 -7
package/Readme.md CHANGED
@@ -1,32 +1,217 @@
1
1
  # gatepay-local-mcp
2
2
 
3
- `gatepay-local-mcp` is a local `stdio` MCP server for calling **x402 payment-protected** HTTP endpoints. It exposes a single MCP tool, `x402_request`. When the upstream service returns `402 Payment Required`, the server parses the payment requirements, prepares the payment payload, signs it with the selected signer, and retries the request automatically.
3
+ `gatepay-local-mcp` is a local `stdio` MCP server for calling **X402 payment-protected** HTTP endpoints. It provides a suite of MCP tools to handle the complete X402 payment workflow, from placing orders to signing payments and submitting them to merchants.
4
4
 
5
5
  ## Features
6
6
 
7
- - One MCP tool: `x402_request`
8
- - Built-in x402 payment flow under `src/x402-standalone/`
9
- - Multiple signing modes via `sign_mode`
7
+ - **5 MCP Tools** for flexible X402 payment workflows
8
+ - Built-in X402 payment flow under `src/x402/`
9
+ - **Multiple signing modes**: `local_private_key`, `quick_wallet`, `plugin_wallet`
10
+ - **Multi-chain support**: EVM (Ethereum, Base, Polygon, etc.) and Solana
10
11
  - Works with Cursor, Claude Desktop, and other MCP clients
11
- - Supports auto-selecting the first ready signing mode
12
+ - Auto-selects the first ready signing mode if not specified
13
+
14
+ ## Available Tools
15
+
16
+ ### 1. `x402_place_order`
17
+
18
+ Send an HTTP request and return complete response information including headers, body, and the original request details.
19
+
20
+ **Use case**: Initial request to a payment-protected endpoint that returns `402 Payment Required`.
21
+
22
+ **Parameters**:
23
+ ```typescript
24
+ {
25
+ url: string; // Target URL (required)
26
+ method?: string; // HTTP method: GET, POST, PUT, PATCH (default: POST)
27
+ body?: string; // JSON string request body (optional)
28
+ sign_mode?: string; // Signing mode: local_private_key, quick_wallet, plugin_wallet (auto-select if omitted)
29
+ wallet_login_provider?: string; // OAuth provider: google, gate (default: gate)
30
+ }
31
+ ```
32
+
33
+ **Returns**: Complete response with status code, headers (including `PAYMENT-REQUIRED`), body, and original request details.
34
+
35
+ ---
36
+
37
+ ### 2. `x402_sign_payment`
38
+
39
+ Parse X402 payment requirements, create a signed payment authorization, and submit the payment to complete a 402-protected request (all-in-one workflow).
40
+
41
+ **Use case**: Single-step payment flow - parse, sign, and submit in one call.
42
+
43
+ **Parameters**:
44
+ ```typescript
45
+ {
46
+ url: string; // Target URL (required)
47
+ method?: string; // HTTP method (default: POST)
48
+ body?: string; // JSON request body (optional)
49
+ payment_required_header?: string; // Base64-encoded PAYMENT-REQUIRED header
50
+ response_body?: string; // Response body from 402 response (alternative to header)
51
+ sign_mode?: string; // Signing mode (auto-select if omitted)
52
+ wallet_login_provider?: string; // OAuth provider (default: gate)
53
+ }
54
+ ```
55
+
56
+ **Returns**: Final response from the merchant after successful payment.
57
+
58
+ ---
59
+
60
+ ### 3. `x402_create_signature`
61
+
62
+ Parse X402 payment requirements and create a signed payment authorization.
63
+
64
+ **Use case**: Two-step workflow - create signature first, then submit separately.
65
+
66
+ **Parameters**:
67
+ ```typescript
68
+ {
69
+ payment_required_header?: string; // Base64-encoded PAYMENT-REQUIRED header
70
+ response_body?: string; // Response body from 402 response (alternative to header)
71
+ sign_mode?: string; // Signing mode (auto-select if omitted)
72
+ wallet_login_provider?: string; // OAuth provider (default: gate)
73
+ }
74
+ ```
75
+
76
+ **Returns**: Payment payload and base64-encoded `PAYMENT-SIGNATURE` header value.
77
+
78
+ ---
79
+
80
+ ### 4. `x402_submit_payment`
81
+
82
+ Submit a signed payment to complete a 402-protected request.
83
+
84
+ **Use case**: Second step of two-step workflow - submit the signature created by `x402_create_signature`.
85
+
86
+ **Parameters**:
87
+ ```typescript
88
+ {
89
+ url: string; // Target URL (required)
90
+ method?: string; // HTTP method (default: POST)
91
+ body?: string; // JSON request body (optional)
92
+ payment_signature: string; // Base64-encoded PAYMENT-SIGNATURE from x402_create_signature (required)
93
+ }
94
+ ```
95
+
96
+ **Returns**: Final response from the merchant.
97
+
98
+ ---
99
+
100
+ ### 5. `x402_quick_wallet_auth`
101
+
102
+ Pre-authorize with Quick Wallet using device-flow OAuth (Google or Gate account).
103
+
104
+ **Use case**: When using `sign_mode: quick_wallet`, run this first to complete the device-flow login before making payment requests.
105
+
106
+ **Parameters**:
107
+ ```typescript
108
+ {
109
+ wallet_login_provider?: string; // OAuth provider: google, gate (default: gate)
110
+ }
111
+ ```
112
+
113
+ **Returns**: Authorization status and wallet addresses (EVM and Solana).
114
+
115
+ ---
116
+
117
+ ## Workflow Examples
118
+
119
+ ### Single-Step Workflow (Recommended)
120
+
121
+ ```
122
+ 1. x402_place_order → Get payment requirements
123
+ 2. x402_sign_payment → Sign and submit payment (all-in-one)
124
+ ```
125
+
126
+ ### Two-Step Workflow (Advanced)
127
+
128
+ ```
129
+ 1. x402_place_order → Get payment requirements
130
+ 2. x402_create_signature → Create signed payment
131
+ 3. x402_submit_payment → Submit signed payment
132
+ ```
133
+
134
+ ### Quick Wallet Pre-Auth
135
+
136
+ ```
137
+ 1. x402_quick_wallet_auth → Authorize with Google/Gate
138
+ 2. x402_place_order → Get payment requirements
139
+ 3. x402_sign_payment → Sign and submit (using quick_wallet)
140
+ ```
12
141
 
13
142
  ## Signing Modes
14
143
 
15
- The server currently registers these signing modes:
144
+ The server supports three signing modes with automatic selection:
145
+
146
+ | `sign_mode` | Status | Networks | Description |
147
+ | ------------------- | --------------------------------------------- | ----------- | ------------------------------------------------------------------------ |
148
+ | `local_private_key` | Ready when `EVM_PRIVATE_KEY` / `SVM_PRIVATE_KEY` set | EVM, Solana | Signs locally with your private keys (no external dependencies) |
149
+ | `quick_wallet` | Ready after OAuth login | EVM, Solana | Custodial MCP wallet with device-flow login (Google/Gate account) |
150
+ | `plugin_wallet` | Ready when `PLUGIN_WALLET_TOKEN` set | EVM, Solana | Browser extension wallet (e.g., Gate Wallet) via MCP bridge |
151
+
152
+ **Priority Order** (when `sign_mode` is omitted):
153
+ 1. `plugin_wallet` (priority: 30) - if token configured
154
+ 2. `quick_wallet` (priority: 20) - if MCP endpoint configured
155
+ 3. `local_private_key` (priority: 10) - if private keys configured
156
+
157
+ The server automatically selects the highest-priority ready mode.
16
158
 
17
- | `sign_mode` | Status | Description |
18
- | ------------------- | ----------------------------------- | ------------------------------------------------------------------------ |
19
- | `local_private_key` | Ready when `EVM_PRIVATE_KEY` is set | Signs locally with your EVM private key |
20
- | `quick_wallet` | Ready after login | Uses the remote MCP wallet and can trigger device-flow login when needed |
21
- | `plugin_wallet` | Placeholder | Reserved for future extension, not implemented yet |
159
+ ### Network Support
22
160
 
23
- If `sign_mode` is omitted, the server auto-selects the highest-priority ready mode.
161
+ - **EVM Networks**: Ethereum, Base, Polygon, Arbitrum One, GateChain, GateLayer
162
+ - **Solana Networks**: Solana Mainnet, Solana Devnet
24
163
 
25
164
  ## Quick Start
26
165
 
27
- ### Cursor / Claude Desktop with local private key
166
+ ### 1. Local Private Key Mode (EVM + Solana)
167
+
168
+ This is the simplest setup for local signing with your own private keys:
169
+
170
+ ```json
171
+ {
172
+ "mcpServers": {
173
+ "gatepay-mcp": {
174
+ "command": "npx",
175
+ "args": ["-y", "gatepay-local-mcp"],
176
+ "env": {
177
+ "EVM_PRIVATE_KEY": "your-evm-private-key-hex-with-or-without-0x-prefix",
178
+ "SVM_PRIVATE_KEY": "your-solana-private-key-base58-optional"
179
+ }
180
+ }
181
+ }
182
+ }
183
+ ```
184
+
185
+ - Set `EVM_PRIVATE_KEY` for EVM network payments (Ethereum, Base, Polygon, etc.)
186
+ - Set `SVM_PRIVATE_KEY` for Solana network payments (optional)
187
+ - Put this into your MCP config such as `~/.cursor/mcp.json`, then restart or reload MCP
188
+
189
+ ### 2. Quick Wallet Mode (Custodial)
190
+
191
+ Remote wallet signing with device-flow OAuth (Google or Gate account):
192
+
193
+ ```json
194
+ {
195
+ "mcpServers": {
196
+ "gatepay-mcp": {
197
+ "command": "npx",
198
+ "args": ["-y", "gatepay-local-mcp"],
199
+ "env": {
200
+ "QUICK_WALLET_MCP_URL": "https://walletmcp.gate.com/mcp",
201
+ "QUICK_WALLET_API_KEY": "your-api-key-optional"
202
+ }
203
+ }
204
+ }
205
+ }
206
+ ```
207
+
208
+ - First payment will trigger device-flow login (opens browser)
209
+ - Token is persisted at `~/.gate-pay/auth.json`
210
+ - Use `x402_quick_wallet_auth` tool to pre-authorize
28
211
 
29
- This is the simplest setup if you want local signing:
212
+ ### 3. Plugin Wallet Mode (Browser Extension)
213
+
214
+ Sign with browser extension wallet (e.g., Gate Wallet):
30
215
 
31
216
  ```json
32
217
  {
@@ -35,18 +220,20 @@ This is the simplest setup if you want local signing:
35
220
  "command": "npx",
36
221
  "args": ["-y", "gatepay-local-mcp"],
37
222
  "env": {
38
- "EVM_PRIVATE_KEY": "your-evm-private-key-hex-with-or-without-0x-prefix"
223
+ "PLUGIN_WALLET_TOKEN": "your-plugin-wallet-mcp-token"
39
224
  }
40
225
  }
41
226
  }
42
227
  }
43
228
  ```
44
229
 
45
- Put this into your MCP config such as `~/.cursor/mcp.json`, then restart the client or reload MCP.
230
+ - Get the token from your browser extension wallet
231
+ - Requires the wallet extension to be installed and running
232
+ - User confirms transactions in the browser extension
46
233
 
47
- ### Cursor / Claude Desktop with quick wallet
234
+ ### Cursor / Claude Desktop with plugin wallet
48
235
 
49
- If you prefer remote wallet signing, you can omit `EVM_PRIVATE_KEY` and let the tool use `quick_wallet`:
236
+ If you want to use a browser extension wallet (like Gate Wallet) for signing, configure the plugin wallet mode:
50
237
 
51
238
  ```json
52
239
  {
@@ -55,29 +242,35 @@ If you prefer remote wallet signing, you can omit `EVM_PRIVATE_KEY` and let the
55
242
  "command": "npx",
56
243
  "args": ["-y", "gatepay-local-mcp"],
57
244
  "env": {
58
- "MCP_WALLET_API_KEY": "your-api-key",
59
- "MCP_WALLET_URL": "https://api.gatemcp.ai/mcp/dex"
245
+ "PLUGIN_WALLET_SERVER_URL": "https://your-plugin-wallet-server.com",
246
+ "PLUGIN_WALLET_TOKEN": "your-token-from-browser-wallet"
60
247
  }
61
248
  }
62
249
  }
63
250
  }
64
251
  ```
65
252
 
66
- When `quick_wallet` has no saved token, the server can start a device-flow login and persist the token at `~/.gate-pay/auth.json`.
253
+ Before using plugin wallet mode:
254
+ 1. Install a compatible browser extension wallet (e.g., [Gate Wallet](https://www.gate.io/web3))
255
+ 2. Open the wallet extension in your browser and obtain the connection token
256
+ 3. Configure `PLUGIN_WALLET_SERVER_URL` and `PLUGIN_WALLET_TOKEN` in your MCP config
257
+ 4. The wallet extension must be active in your browser when making x402 requests
67
258
 
68
259
  ## Environment Variables
69
260
 
70
261
  The server loads `.env` from the repository or package root at startup.
71
262
 
72
- ### Runtime variables
263
+ ### Signing Mode Configuration
73
264
 
74
- | Variable | Required | Default | Description |
75
- | -------------------- | -------- | -------------------------------- | --------------------------------------------------------------------------- |
76
- | `EVM_PRIVATE_KEY` | No | | Local EVM private key used by `local_private_key`; hex with or without `0x` |
77
- | `MCP_WALLET_API_KEY` | No | | API key used when connecting to the remote MCP wallet |
78
- | `MCP_WALLET_URL` | No | `https://api.gatemcp.ai/mcp/dex` | Remote MCP wallet server URL used by `quick_wallet` |
265
+ | Variable | Mode | Description |
266
+ | ------------------------- | ------------------- | --------------------------------------------------------------------------- |
267
+ | `EVM_PRIVATE_KEY` | `local_private_key` | Local EVM private key; hex with or without `0x` prefix |
268
+ | `SVM_PRIVATE_KEY` | `local_private_key` | Local Solana private key; base58 encoded (optional) |
269
+ | `QUICK_WALLET_MCP_URL` | `quick_wallet` | MCP wallet endpoint URL (default: `https://walletmcp.gate.com/mcp`) |
270
+ | `QUICK_WALLET_API_KEY` | `quick_wallet` | API key for MCP wallet service (optional) |
271
+ | `PLUGIN_WALLET_TOKEN` | `plugin_wallet` | MCP token from browser extension wallet |
79
272
 
80
- ### Test and script variables
273
+ ### Test and Script Variables
81
274
 
82
275
  | Variable | Used By | Default | Description |
83
276
  | ----------------------------- | ------------------------------- | ----------------------- | ----------------------------------------------- |
@@ -85,55 +278,73 @@ The server loads `.env` from the repository or package root at startup.
85
278
  | `ENDPOINT_PATH` | `test/privateKey.ts` | `/flight/order` | Endpoint path appended to `RESOURCE_SERVER_URL` |
86
279
  | `GATEPAY_MCP_TEST_TIMEOUT_MS` | `test/mcp-x402-request-tool.ts` | `180000` | Timeout for the MCP tool integration test |
87
280
 
88
- ## Available Tool
89
-
90
- ### `x402_request`
281
+ ## Usage Examples
91
282
 
92
- Executes a single HTTP request to an x402-protected endpoint. If the response is `402 Payment Required`, the server completes the payment flow and retries automatically.
93
-
94
- Use this tool only for endpoints that are expected to require x402 payment.
95
-
96
- | Argument | Type | Required | Description |
97
- | ----------------------- | ------ | -------- | ------------------------------------------------------------------------------- |
98
- | `url` | string | Yes | Full `http` or `https` URL |
99
- | `method` | string | No | `GET`, `POST`, `PUT`, or `PATCH`; default is `POST` |
100
- | `body` | string | No | JSON string request body; omit for `GET` |
101
- | `sign_mode` | string | No | Preferred signing mode: `local_private_key`, `quick_wallet`, or `plugin_wallet` |
102
- | `wallet_login_provider` | string | No | Login provider for `quick_wallet`: `google` or `gate`; default is `gate` |
103
-
104
- ### Tool examples
105
-
106
- GET request with automatic mode selection:
283
+ ### Example 1: Single-Step Payment (Recommended)
107
284
 
108
285
  ```json
286
+ // Step 1: Place order to get payment requirements
109
287
  {
110
- "url": "https://api.example.com/resource"
288
+ "tool": "x402_place_order",
289
+ "arguments": {
290
+ "url": "https://api.example.com/order",
291
+ "method": "POST",
292
+ "body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}"
293
+ }
294
+ }
295
+
296
+ // Step 2: If 402 response, sign and submit payment
297
+ {
298
+ "tool": "x402_sign_payment",
299
+ "arguments": {
300
+ "url": "https://api.example.com/order",
301
+ "method": "POST",
302
+ "body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}",
303
+ "payment_required_header": "<base64-from-place_order>",
304
+ "sign_mode": "quick_wallet"
305
+ }
111
306
  }
112
307
  ```
113
308
 
114
- POST request with explicit local signing:
309
+ ### Example 2: Two-Step Payment (Advanced)
115
310
 
116
311
  ```json
312
+ // Create signature first
117
313
  {
118
- "url": "https://api.example.com/order",
119
- "method": "POST",
120
- "body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}",
121
- "sign_mode": "local_private_key"
314
+ "tool": "x402_create_signature",
315
+ "arguments": {
316
+ "payment_required_header": "<base64>",
317
+ "sign_mode": "local_private_key"
318
+ }
319
+ }
320
+
321
+ // Then submit separately
322
+ {
323
+ "tool": "x402_submit_payment",
324
+ "arguments": {
325
+ "url": "https://api.example.com/order",
326
+ "payment_signature": "<base64-from-create_signature>"
327
+ }
122
328
  }
123
329
  ```
124
330
 
125
- POST request with quick wallet login through Gate:
331
+ ### Example 3: Quick Wallet with Pre-Auth
126
332
 
127
333
  ```json
334
+ // Pre-authorize (opens browser for OAuth)
128
335
  {
129
- "url": "https://api.example.com/order",
130
- "method": "POST",
131
- "body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}",
132
- "sign_mode": "quick_wallet",
133
- "wallet_login_provider": "gate"
336
+ "tool": "x402_quick_wallet_auth",
337
+ "arguments": {
338
+ "wallet_login_provider": "gate"
339
+ }
134
340
  }
135
341
  ```
136
342
 
343
+ ## Agent Skill
344
+
345
+
346
+ For AI agents that orchestrate x402 payments, wallet setup, and merchant discovery, this repository ships an **[Agent Skill](gatepay-local-mcp/skills/SKILL.md at master · gate/gatepay-local-mcp)** at [`skills/SKILL.md`]. Install it in your host’s skills directory or point auto-update at the raw file on your default branch. **Tool names and arguments always follow each tool’s MCP `inputSchema`** on the server you connected; the skill may describe flows that apply across builds, while this package’s exposed tools depend on the version you run (e.g. the minimal npm build exposes `x402_request` only—see the tool list in your client).
347
+
137
348
  ## Development
138
349
 
139
350
  ```bash
@@ -161,24 +372,15 @@ npm run test:mcp-tool
161
372
 
162
373
  ### Integration test notes
163
374
 
164
- `npm run test:mcp-tool` starts `dist/src/index.js` and calls `x402_request` against the configured remote wallet flow. In practice you usually want:
375
+ `npm run test:mcp-tool` starts `dist/src/index.js` and calls `x402_request` against the configured remote wallet flow. The test requires proper wallet credentials to be configured.
165
376
 
166
377
  ```bash
167
378
  npm run build
168
- MCP_WALLET_API_KEY=your-key npm run test:mcp-tool
379
+ npm run test:mcp-tool
169
380
  ```
170
381
 
171
382
  If you already logged in before, the saved token in `~/.gate-pay/auth.json` will be reused. Otherwise the quick wallet flow may require interactive device login. You can increase the timeout with `GATEPAY_MCP_TEST_TIMEOUT_MS`.
172
383
 
173
- ## How It Works
174
-
175
- 1. The MCP client calls `x402_request`.
176
- 2. The server normalizes the input and selects a ready `sign_mode`.
177
- 3. The first request is sent to the target URL.
178
- 4. If the upstream returns `402 Payment Required`, the server parses the payment requirements.
179
- 5. The selected signer signs the payment payload.
180
- 6. The server retries the request with the payment header and returns the final response.
181
-
182
384
  ## License
183
385
 
184
386
  MIT