gatepay-local-mcp 1.0.1 → 1.0.3

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 (98) hide show
  1. package/Readme.md +143 -44
  2. package/dist/src/index.js +635 -106
  3. package/dist/src/index.js.map +1 -1
  4. package/dist/src/modes/build-pay-fetch.d.ts +7 -0
  5. package/dist/src/modes/build-pay-fetch.d.ts.map +1 -0
  6. package/dist/src/modes/build-pay-fetch.js +22 -0
  7. package/dist/src/modes/build-pay-fetch.js.map +1 -0
  8. package/dist/src/modes/input-normalizer.d.ts +17 -0
  9. package/dist/src/modes/input-normalizer.d.ts.map +1 -0
  10. package/dist/src/modes/input-normalizer.js +22 -0
  11. package/dist/src/modes/input-normalizer.js.map +1 -0
  12. package/dist/src/modes/local-private-key.d.ts +9 -0
  13. package/dist/src/modes/local-private-key.d.ts.map +1 -0
  14. package/dist/src/modes/local-private-key.js +35 -0
  15. package/dist/src/modes/local-private-key.js.map +1 -0
  16. package/dist/src/modes/plugin-wallet.d.ts +19 -0
  17. package/dist/src/modes/plugin-wallet.d.ts.map +1 -0
  18. package/dist/src/modes/plugin-wallet.js +171 -0
  19. package/dist/src/modes/plugin-wallet.js.map +1 -0
  20. package/dist/src/modes/quick-wallet.d.ts +19 -0
  21. package/dist/src/modes/quick-wallet.d.ts.map +1 -0
  22. package/dist/src/modes/quick-wallet.js +105 -0
  23. package/dist/src/modes/quick-wallet.js.map +1 -0
  24. package/dist/src/modes/registry.d.ts +26 -0
  25. package/dist/src/modes/registry.d.ts.map +1 -0
  26. package/dist/src/modes/registry.js +127 -0
  27. package/dist/src/modes/registry.js.map +1 -0
  28. package/dist/src/modes/signers.d.ts +40 -0
  29. package/dist/src/modes/signers.d.ts.map +1 -0
  30. package/dist/src/modes/signers.js +293 -0
  31. package/dist/src/modes/signers.js.map +1 -0
  32. package/dist/src/modes/types.d.ts +38 -0
  33. package/dist/src/modes/types.d.ts.map +1 -0
  34. package/dist/src/modes/types.js +2 -0
  35. package/dist/src/modes/types.js.map +1 -0
  36. package/dist/src/wallets/auth-token-store.d.ts +17 -0
  37. package/dist/src/wallets/auth-token-store.d.ts.map +1 -0
  38. package/dist/src/wallets/auth-token-store.js +43 -0
  39. package/dist/src/wallets/auth-token-store.js.map +1 -0
  40. package/dist/src/wallets/device-flow-login.d.ts +27 -0
  41. package/dist/src/wallets/device-flow-login.d.ts.map +1 -0
  42. package/dist/src/wallets/device-flow-login.js +235 -0
  43. package/dist/src/wallets/device-flow-login.js.map +1 -0
  44. package/dist/src/wallets/plugin-wallet-client.d.ts +17 -0
  45. package/dist/src/wallets/plugin-wallet-client.d.ts.map +1 -0
  46. package/dist/src/wallets/plugin-wallet-client.js +95 -0
  47. package/dist/src/wallets/plugin-wallet-client.js.map +1 -0
  48. package/dist/src/wallets/wallet-mcp-clients.d.ts +2121 -0
  49. package/dist/src/wallets/wallet-mcp-clients.d.ts.map +1 -0
  50. package/dist/src/wallets/wallet-mcp-clients.js +264 -0
  51. package/dist/src/wallets/wallet-mcp-clients.js.map +1 -0
  52. package/dist/src/x402/client.d.ts.map +1 -0
  53. package/dist/src/x402/client.js.map +1 -0
  54. package/dist/src/x402/exactEvmScheme.d.ts.map +1 -0
  55. package/dist/src/x402/exactEvmScheme.js.map +1 -0
  56. package/dist/src/x402/fetch.d.ts.map +1 -0
  57. package/dist/src/x402/fetch.js.map +1 -0
  58. package/dist/src/x402/gatelayer.d.ts.map +1 -0
  59. package/dist/src/x402/gatelayer.js.map +1 -0
  60. package/dist/src/x402/http.d.ts.map +1 -0
  61. package/dist/src/x402/http.js.map +1 -0
  62. package/dist/src/x402/types.d.ts.map +1 -0
  63. package/dist/src/x402/types.js.map +1 -0
  64. package/dist/src/{x402-standalone → x402}/utils.d.ts +15 -0
  65. package/dist/src/x402/utils.d.ts.map +1 -0
  66. package/dist/src/{x402-standalone → x402}/utils.js +8 -1
  67. package/dist/src/x402/utils.js.map +1 -0
  68. package/package.json +11 -5
  69. package/dist/src/x402-standalone/client.d.ts.map +0 -1
  70. package/dist/src/x402-standalone/client.js.map +0 -1
  71. package/dist/src/x402-standalone/exactEvmScheme.d.ts.map +0 -1
  72. package/dist/src/x402-standalone/exactEvmScheme.js.map +0 -1
  73. package/dist/src/x402-standalone/fetch.d.ts.map +0 -1
  74. package/dist/src/x402-standalone/fetch.js.map +0 -1
  75. package/dist/src/x402-standalone/gatelayer.d.ts.map +0 -1
  76. package/dist/src/x402-standalone/gatelayer.js.map +0 -1
  77. package/dist/src/x402-standalone/http.d.ts.map +0 -1
  78. package/dist/src/x402-standalone/http.js.map +0 -1
  79. package/dist/src/x402-standalone/signer.d.ts +0 -4
  80. package/dist/src/x402-standalone/signer.d.ts.map +0 -1
  81. package/dist/src/x402-standalone/signer.js +0 -38
  82. package/dist/src/x402-standalone/signer.js.map +0 -1
  83. package/dist/src/x402-standalone/types.d.ts.map +0 -1
  84. package/dist/src/x402-standalone/types.js.map +0 -1
  85. package/dist/src/x402-standalone/utils.d.ts.map +0 -1
  86. package/dist/src/x402-standalone/utils.js.map +0 -1
  87. /package/dist/src/{x402-standalone → x402}/client.d.ts +0 -0
  88. /package/dist/src/{x402-standalone → x402}/client.js +0 -0
  89. /package/dist/src/{x402-standalone → x402}/exactEvmScheme.d.ts +0 -0
  90. /package/dist/src/{x402-standalone → x402}/exactEvmScheme.js +0 -0
  91. /package/dist/src/{x402-standalone → x402}/fetch.d.ts +0 -0
  92. /package/dist/src/{x402-standalone → x402}/fetch.js +0 -0
  93. /package/dist/src/{x402-standalone → x402}/gatelayer.d.ts +0 -0
  94. /package/dist/src/{x402-standalone → x402}/gatelayer.js +0 -0
  95. /package/dist/src/{x402-standalone → x402}/http.d.ts +0 -0
  96. /package/dist/src/{x402-standalone → x402}/http.js +0 -0
  97. /package/dist/src/{x402-standalone → x402}/types.d.ts +0 -0
  98. /package/dist/src/{x402-standalone → x402}/types.js +0 -0
package/Readme.md CHANGED
@@ -1,18 +1,32 @@
1
- # gatepay-local-mcp
1
+ # gatepay-local-mcp
2
2
 
3
- A local (stdio) MCP server that sends HTTP requests to **x402 payment-protected** endpoints. On `402 Payment Required`, it creates the payment payload, signs with your EVM key, and retries the request with the payment header. Exposes a single tool: `x402_request`.
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.
4
4
 
5
5
  ## Features
6
6
 
7
- - **One tool** `x402_request`: request any URL with optional method and JSON body; 402 is handled automatically (parse → sign → retry).
8
- - **No @x402/* deps** x402 logic is implemented in-repo under `x402-standalone/` (EVM exact scheme; supports `eth`, `base`, etc.).
9
- - **Cursor / Claude Desktop** — add the server via `mcp.json` and set `EVM_PRIVATE_KEY` in `env`; no code changes needed.
7
+ - One MCP tool: `x402_request`
8
+ - Built-in x402 payment flow under `src/x402-standalone/`
9
+ - Multiple signing modes via `sign_mode`
10
+ - Works with Cursor, Claude Desktop, and other MCP clients
11
+ - Supports auto-selecting the first ready signing mode
10
12
 
11
- ## Quick Start (Cursor / Claude Desktop)
13
+ ## Signing Modes
12
14
 
13
- ### With authentication (required for x402 payment)
15
+ The server currently registers these signing modes:
14
16
 
15
- `EVM_PRIVATE_KEY` is required; the server will not start without it.
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` | Ready when `PLUGIN_WALLET_TOKEN` is set | Signs via browser extension wallet (e.g., Gate Wallet) |
22
+
23
+ If `sign_mode` is omitted, the server auto-selects the highest-priority ready mode.
24
+
25
+ ## Quick Start
26
+
27
+ ### Cursor / Claude Desktop with local private key
28
+
29
+ This is the simplest setup if you want local signing:
16
30
 
17
31
  ```json
18
32
  {
@@ -28,9 +42,28 @@ A local (stdio) MCP server that sends HTTP requests to **x402 payment-protected*
28
42
  }
29
43
  ```
30
44
 
31
- Put this in your MCP config (e.g. `~/.cursor/mcp.json`), then restart Cursor or reload MCP. The AI can then call `x402_request` for x402-protected URLs.
45
+ Put this into your MCP config such as `~/.cursor/mcp.json`, then restart the client or reload MCP.
46
+
47
+ ### Cursor / Claude Desktop with quick wallet
48
+
49
+ If you prefer remote wallet signing, you can omit `EVM_PRIVATE_KEY` and let the tool use `quick_wallet`. Note that you need to obtain API credentials from the wallet service provider.
50
+
51
+ ```json
52
+ {
53
+ "mcpServers": {
54
+ "gatepay-mcp": {
55
+ "command": "npx",
56
+ "args": ["-y", "gatepay-local-mcp"]
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ When `quick_wallet` has no saved token, the server can start a device-flow login and persist the token at `~/.gate-pay/auth.json`.
63
+
64
+ ### Cursor / Claude Desktop with plugin wallet
32
65
 
33
- ### Optional: debug logging
66
+ If you want to use a browser extension wallet (like Gate Wallet) for signing, configure the plugin wallet mode:
34
67
 
35
68
  ```json
36
69
  {
@@ -39,67 +72,133 @@ Put this in your MCP config (e.g. `~/.cursor/mcp.json`), then restart Cursor or
39
72
  "command": "npx",
40
73
  "args": ["-y", "gatepay-local-mcp"],
41
74
  "env": {
42
- "EVM_PRIVATE_KEY": "your-evm-private-key"
75
+ "PLUGIN_WALLET_SERVER_URL": "https://your-plugin-wallet-server.com",
76
+ "PLUGIN_WALLET_TOKEN": "your-token-from-browser-wallet"
43
77
  }
44
78
  }
45
79
  }
46
80
  }
47
81
  ```
48
82
 
49
- Use `tail -f /tmp/x402-debug.log` to watch requests and errors.
83
+ Before using plugin wallet mode:
84
+ 1. Install a compatible browser extension wallet (e.g., [Gate Wallet](https://www.gate.io/web3))
85
+ 2. Open the wallet extension in your browser and obtain the connection token
86
+ 3. Configure `PLUGIN_WALLET_SERVER_URL` and `PLUGIN_WALLET_TOKEN` in your MCP config
87
+ 4. The wallet extension must be active in your browser when making x402 requests
50
88
 
51
89
  ## Environment Variables
52
90
 
53
- | Variable | Required | Default | Description |
54
- | -------- | -------- | ------- | ----------- |
55
- | `EVM_PRIVATE_KEY` | **Yes** | — | EVM wallet private key (hex, with or without `0x`) for x402 payment signing |
56
- | `X402_DEBUG_LOG` or `MCP_X402_DEBUG_LOG` | No | — | File path for debug log (append-only; use `tail -f` to inspect) |
91
+ The server loads `.env` from the repository or package root at startup.
57
92
 
58
- ## Available Tools
93
+ ### Runtime variables
59
94
 
60
- ### x402_request
95
+ | Variable | Required | Default | Description |
96
+ | --------------------------- | -------- | ------- | --------------------------------------------------------------------------- |
97
+ | `EVM_PRIVATE_KEY` | No | — | Local EVM private key used by `local_private_key`; hex with or without `0x` |
98
+ | `PLUGIN_WALLET_SERVER_URL` | No | — | Base URL for the plugin wallet MCP server (required for `plugin_wallet`) |
99
+ | `PLUGIN_WALLET_TOKEN` | No | — | Authentication token for plugin wallet (required for `plugin_wallet`) |
61
100
 
62
- Execute one HTTP request to an x402-protected endpoint. If the server responds with `402 Payment Required`, the tool parses the payment requirements, builds and signs the payment payload, and retries the request with the `PAYMENT-SIGNATURE` header.
101
+ ### Test and script variables
63
102
 
64
- **Use only for endpoints that require payment (402).** Do not use for public or non-402 endpoints.
103
+ | Variable | Used By | Default | Description |
104
+ | ----------------------------- | ------------------------------- | ----------------------- | ----------------------------------------------- |
105
+ | `RESOURCE_SERVER_URL` | `test/privateKey.ts` | `http://localhost:8080` | Base URL for the local private-key flow test |
106
+ | `ENDPOINT_PATH` | `test/privateKey.ts` | `/flight/order` | Endpoint path appended to `RESOURCE_SERVER_URL` |
107
+ | `GATEPAY_MCP_TEST_TIMEOUT_MS` | `test/mcp-x402-request-tool.ts` | `180000` | Timeout for the MCP tool integration test |
65
108
 
66
- | Argument | Type | Required | Description |
67
- | -------- | ---- | -------- | ----------- |
68
- | `url` | string | **Yes** | Full URL of the endpoint (e.g. `http://localhost:8080/flight/order`) |
69
- | `method` | string | No | `GET`, `POST`, `PUT`, or `PATCH`. Default: `POST`. |
70
- | `body` | string | No | JSON string for request body (POST/PUT/PATCH). Omit for GET. |
109
+ ## Available Tool
71
110
 
72
- **Examples (as passed by the client):**
111
+ ### `x402_request`
73
112
 
74
- - GET: `{ "url": "https://api.example.com/resource" }`
75
- - POST: `{ "url": "https://api.example.com/order", "method": "POST", "body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}" }`
113
+ 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.
114
+
115
+ Use this tool only for endpoints that are expected to require x402 payment.
116
+
117
+ | Argument | Type | Required | Description |
118
+ | ----------------------- | ------ | -------- | ------------------------------------------------------------------------------- |
119
+ | `url` | string | Yes | Full `http` or `https` URL |
120
+ | `method` | string | No | `GET`, `POST`, `PUT`, or `PATCH`; default is `POST` |
121
+ | `body` | string | No | JSON string request body; omit for `GET` |
122
+ | `sign_mode` | string | No | Preferred signing mode: `local_private_key`, `quick_wallet`, or `plugin_wallet` |
123
+ | `wallet_login_provider` | string | No | Login provider for `quick_wallet`: `google` or `gate`; default is `gate` |
124
+
125
+ ### Tool examples
126
+
127
+ GET request with automatic mode selection:
128
+
129
+ ```json
130
+ {
131
+ "url": "https://api.example.com/resource"
132
+ }
133
+ ```
134
+
135
+ POST request with explicit local signing:
136
+
137
+ ```json
138
+ {
139
+ "url": "https://api.example.com/order",
140
+ "method": "POST",
141
+ "body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}",
142
+ "sign_mode": "local_private_key"
143
+ }
144
+ ```
145
+
146
+ POST request with quick wallet login through Gate:
147
+
148
+ ```json
149
+ {
150
+ "url": "https://api.example.com/order",
151
+ "method": "POST",
152
+ "body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}",
153
+ "sign_mode": "quick_wallet",
154
+ "wallet_login_provider": "gate"
155
+ }
156
+ ```
76
157
 
77
158
  ## Development
78
159
 
79
160
  ```bash
80
- # Install dependencies
81
- pnpm install
161
+ # install dependencies
162
+ npm install
163
+
164
+ # build TypeScript output into dist/
165
+ npm run build
166
+
167
+ # start the MCP server from source
168
+ npm run dev
169
+
170
+ # run the built entrypoint through the package start script
171
+ npm start
82
172
 
83
- # Build (output in dist/)
84
- pnpm run build
173
+ # run unit tests
174
+ npm run test:unit
85
175
 
86
- # Run MCP locally (loads .env from package/repo root for EVM_PRIVATE_KEY)
87
- pnpm start
88
- # or without build step
89
- pnpm run dev
176
+ # run the local private key flow test
177
+ npm run test:privateKey
90
178
 
91
- # Run the fetch demo (POST to a configurable x402 endpoint)
92
- pnpm run fetch
179
+ # run the MCP tool integration test
180
+ npm run test:mcp-tool
181
+ ```
182
+
183
+ ### Integration test notes
184
+
185
+ `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.
186
+
187
+ ```bash
188
+ npm run build
189
+ npm run test:mcp-tool
93
190
  ```
94
191
 
95
- The fetch demo uses `RESOURCE_SERVER_URL` (default `http://localhost:4021`) and `ENDPOINT_PATH` (default `/weather`); set them in `.env` or the shell. See `test/fetch.ts` to change URL, method, or body.
192
+ 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`.
96
193
 
97
- ## How it works
194
+ ## How It Works
98
195
 
99
- - On first request, the server may respond with `402` and `PAYMENT-REQUIRED` (or a JSON body with payment requirements).
100
- - The client parses requirements, selects a supported scheme/network (e.g. `exact` + `eth`/`base`), builds the EIP-3009–style payload, and signs with `EVM_PRIVATE_KEY`.
101
- - It retries the same request with `PAYMENT-SIGNATURE` (and `Access-Control-Expose-Headers` for `PAYMENT-RESPONSE`).
102
- - The final response (200 or error) and optional `PAYMENT-RESPONSE` header are returned to the caller.
196
+ 1. The MCP client calls `x402_request`.
197
+ 2. The server normalizes the input and selects a ready `sign_mode`.
198
+ 3. The first request is sent to the target URL.
199
+ 4. If the upstream returns `402 Payment Required`, the server parses the payment requirements.
200
+ 5. The selected signer signs the payment payload.
201
+ 6. The server retries the request with the payment header and returns the final response.
103
202
 
104
203
  ## License
105
204