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.
- package/Readme.md +143 -44
- package/dist/src/index.js +635 -106
- package/dist/src/index.js.map +1 -1
- package/dist/src/modes/build-pay-fetch.d.ts +7 -0
- package/dist/src/modes/build-pay-fetch.d.ts.map +1 -0
- package/dist/src/modes/build-pay-fetch.js +22 -0
- package/dist/src/modes/build-pay-fetch.js.map +1 -0
- package/dist/src/modes/input-normalizer.d.ts +17 -0
- package/dist/src/modes/input-normalizer.d.ts.map +1 -0
- package/dist/src/modes/input-normalizer.js +22 -0
- package/dist/src/modes/input-normalizer.js.map +1 -0
- package/dist/src/modes/local-private-key.d.ts +9 -0
- package/dist/src/modes/local-private-key.d.ts.map +1 -0
- package/dist/src/modes/local-private-key.js +35 -0
- package/dist/src/modes/local-private-key.js.map +1 -0
- package/dist/src/modes/plugin-wallet.d.ts +19 -0
- package/dist/src/modes/plugin-wallet.d.ts.map +1 -0
- package/dist/src/modes/plugin-wallet.js +171 -0
- package/dist/src/modes/plugin-wallet.js.map +1 -0
- package/dist/src/modes/quick-wallet.d.ts +19 -0
- package/dist/src/modes/quick-wallet.d.ts.map +1 -0
- package/dist/src/modes/quick-wallet.js +105 -0
- package/dist/src/modes/quick-wallet.js.map +1 -0
- package/dist/src/modes/registry.d.ts +26 -0
- package/dist/src/modes/registry.d.ts.map +1 -0
- package/dist/src/modes/registry.js +127 -0
- package/dist/src/modes/registry.js.map +1 -0
- package/dist/src/modes/signers.d.ts +40 -0
- package/dist/src/modes/signers.d.ts.map +1 -0
- package/dist/src/modes/signers.js +293 -0
- package/dist/src/modes/signers.js.map +1 -0
- package/dist/src/modes/types.d.ts +38 -0
- package/dist/src/modes/types.d.ts.map +1 -0
- package/dist/src/modes/types.js +2 -0
- package/dist/src/modes/types.js.map +1 -0
- package/dist/src/wallets/auth-token-store.d.ts +17 -0
- package/dist/src/wallets/auth-token-store.d.ts.map +1 -0
- package/dist/src/wallets/auth-token-store.js +43 -0
- package/dist/src/wallets/auth-token-store.js.map +1 -0
- package/dist/src/wallets/device-flow-login.d.ts +27 -0
- package/dist/src/wallets/device-flow-login.d.ts.map +1 -0
- package/dist/src/wallets/device-flow-login.js +235 -0
- package/dist/src/wallets/device-flow-login.js.map +1 -0
- package/dist/src/wallets/plugin-wallet-client.d.ts +17 -0
- package/dist/src/wallets/plugin-wallet-client.d.ts.map +1 -0
- package/dist/src/wallets/plugin-wallet-client.js +95 -0
- package/dist/src/wallets/plugin-wallet-client.js.map +1 -0
- package/dist/src/wallets/wallet-mcp-clients.d.ts +2121 -0
- package/dist/src/wallets/wallet-mcp-clients.d.ts.map +1 -0
- package/dist/src/wallets/wallet-mcp-clients.js +264 -0
- package/dist/src/wallets/wallet-mcp-clients.js.map +1 -0
- package/dist/src/x402/client.d.ts.map +1 -0
- package/dist/src/x402/client.js.map +1 -0
- package/dist/src/x402/exactEvmScheme.d.ts.map +1 -0
- package/dist/src/x402/exactEvmScheme.js.map +1 -0
- package/dist/src/x402/fetch.d.ts.map +1 -0
- package/dist/src/x402/fetch.js.map +1 -0
- package/dist/src/x402/gatelayer.d.ts.map +1 -0
- package/dist/src/x402/gatelayer.js.map +1 -0
- package/dist/src/x402/http.d.ts.map +1 -0
- package/dist/src/x402/http.js.map +1 -0
- package/dist/src/x402/types.d.ts.map +1 -0
- package/dist/src/x402/types.js.map +1 -0
- package/dist/src/{x402-standalone → x402}/utils.d.ts +15 -0
- package/dist/src/x402/utils.d.ts.map +1 -0
- package/dist/src/{x402-standalone → x402}/utils.js +8 -1
- package/dist/src/x402/utils.js.map +1 -0
- package/package.json +11 -5
- package/dist/src/x402-standalone/client.d.ts.map +0 -1
- package/dist/src/x402-standalone/client.js.map +0 -1
- package/dist/src/x402-standalone/exactEvmScheme.d.ts.map +0 -1
- package/dist/src/x402-standalone/exactEvmScheme.js.map +0 -1
- package/dist/src/x402-standalone/fetch.d.ts.map +0 -1
- package/dist/src/x402-standalone/fetch.js.map +0 -1
- package/dist/src/x402-standalone/gatelayer.d.ts.map +0 -1
- package/dist/src/x402-standalone/gatelayer.js.map +0 -1
- package/dist/src/x402-standalone/http.d.ts.map +0 -1
- package/dist/src/x402-standalone/http.js.map +0 -1
- package/dist/src/x402-standalone/signer.d.ts +0 -4
- package/dist/src/x402-standalone/signer.d.ts.map +0 -1
- package/dist/src/x402-standalone/signer.js +0 -38
- package/dist/src/x402-standalone/signer.js.map +0 -1
- package/dist/src/x402-standalone/types.d.ts.map +0 -1
- package/dist/src/x402-standalone/types.js.map +0 -1
- package/dist/src/x402-standalone/utils.d.ts.map +0 -1
- package/dist/src/x402-standalone/utils.js.map +0 -1
- /package/dist/src/{x402-standalone → x402}/client.d.ts +0 -0
- /package/dist/src/{x402-standalone → x402}/client.js +0 -0
- /package/dist/src/{x402-standalone → x402}/exactEvmScheme.d.ts +0 -0
- /package/dist/src/{x402-standalone → x402}/exactEvmScheme.js +0 -0
- /package/dist/src/{x402-standalone → x402}/fetch.d.ts +0 -0
- /package/dist/src/{x402-standalone → x402}/fetch.js +0 -0
- /package/dist/src/{x402-standalone → x402}/gatelayer.d.ts +0 -0
- /package/dist/src/{x402-standalone → x402}/gatelayer.js +0 -0
- /package/dist/src/{x402-standalone → x402}/http.d.ts +0 -0
- /package/dist/src/{x402-standalone → x402}/http.js +0 -0
- /package/dist/src/{x402-standalone → x402}/types.d.ts +0 -0
- /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
|
-
|
|
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
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
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
|
-
##
|
|
13
|
+
## Signing Modes
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
The server currently registers these signing modes:
|
|
14
16
|
|
|
15
|
-
`
|
|
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
|
|
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
|
-
|
|
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
|
-
"
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
93
|
+
### Runtime variables
|
|
59
94
|
|
|
60
|
-
|
|
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
|
-
|
|
101
|
+
### Test and script variables
|
|
63
102
|
|
|
64
|
-
|
|
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
|
-
|
|
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
|
-
|
|
111
|
+
### `x402_request`
|
|
73
112
|
|
|
74
|
-
-
|
|
75
|
-
|
|
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
|
-
#
|
|
81
|
-
|
|
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
|
-
#
|
|
84
|
-
|
|
173
|
+
# run unit tests
|
|
174
|
+
npm run test:unit
|
|
85
175
|
|
|
86
|
-
#
|
|
87
|
-
|
|
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
|
-
#
|
|
92
|
-
|
|
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
|
-
|
|
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
|
|
194
|
+
## How It Works
|
|
98
195
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
|