gatepay-local-mcp 1.0.0 → 1.0.2
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 +122 -44
- package/dist/src/index.js +161 -86
- 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 +153 -0
- package/dist/src/modes/plugin-wallet.js.map +1 -0
- package/dist/src/modes/quick-wallet.d.ts +15 -0
- package/dist/src/modes/quick-wallet.d.ts.map +1 -0
- package/dist/src/modes/quick-wallet.js +94 -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 +126 -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 +259 -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 +15 -0
- package/dist/src/wallets/plugin-wallet-client.d.ts.map +1 -0
- package/dist/src/wallets/plugin-wallet-client.js +83 -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-standalone → x402}/client.js +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 +17 -0
- package/dist/src/x402/utils.d.ts.map +1 -0
- package/dist/src/{x402-standalone → x402}/utils.js +14 -1
- package/dist/src/x402/utils.js.map +1 -0
- package/package.json +14 -3
- 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/index.d.ts +0 -9
- package/dist/src/x402-standalone/index.d.ts.map +0 -1
- package/dist/src/x402-standalone/index.js +0 -8
- package/dist/src/x402-standalone/index.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/test/fetch.d.ts +0 -2
- package/dist/test/fetch.d.ts.map +0 -1
- package/dist/test/fetch.js +0 -54
- package/dist/test/fetch.js.map +0 -1
- /package/dist/src/{x402-standalone → x402}/client.d.ts +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` | Placeholder | Reserved for future extension, not implemented yet |
|
|
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,11 @@ 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
|
|
32
48
|
|
|
33
|
-
|
|
49
|
+
If you prefer remote wallet signing, you can omit `EVM_PRIVATE_KEY` and let the tool use `quick_wallet`:
|
|
34
50
|
|
|
35
51
|
```json
|
|
36
52
|
{
|
|
@@ -39,67 +55,129 @@ Put this in your MCP config (e.g. `~/.cursor/mcp.json`), then restart Cursor or
|
|
|
39
55
|
"command": "npx",
|
|
40
56
|
"args": ["-y", "gatepay-local-mcp"],
|
|
41
57
|
"env": {
|
|
42
|
-
"
|
|
58
|
+
"MCP_WALLET_API_KEY": "your-api-key",
|
|
59
|
+
"MCP_WALLET_URL": "https://api.gatemcp.ai/mcp/dex"
|
|
43
60
|
}
|
|
44
61
|
}
|
|
45
62
|
}
|
|
46
63
|
}
|
|
47
64
|
```
|
|
48
65
|
|
|
49
|
-
|
|
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`.
|
|
50
67
|
|
|
51
68
|
## Environment Variables
|
|
52
69
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
70
|
+
The server loads `.env` from the repository or package root at startup.
|
|
71
|
+
|
|
72
|
+
### Runtime variables
|
|
73
|
+
|
|
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` |
|
|
79
|
+
|
|
80
|
+
### Test and script variables
|
|
81
|
+
|
|
82
|
+
| Variable | Used By | Default | Description |
|
|
83
|
+
| ----------------------------- | ------------------------------- | ----------------------- | ----------------------------------------------- |
|
|
84
|
+
| `RESOURCE_SERVER_URL` | `test/privateKey.ts` | `http://localhost:8080` | Base URL for the local private-key flow test |
|
|
85
|
+
| `ENDPOINT_PATH` | `test/privateKey.ts` | `/flight/order` | Endpoint path appended to `RESOURCE_SERVER_URL` |
|
|
86
|
+
| `GATEPAY_MCP_TEST_TIMEOUT_MS` | `test/mcp-x402-request-tool.ts` | `180000` | Timeout for the MCP tool integration test |
|
|
57
87
|
|
|
58
|
-
## Available
|
|
88
|
+
## Available Tool
|
|
59
89
|
|
|
60
|
-
### x402_request
|
|
90
|
+
### `x402_request`
|
|
61
91
|
|
|
62
|
-
|
|
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:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"url": "https://api.example.com/resource"
|
|
111
|
+
}
|
|
112
|
+
```
|
|
63
113
|
|
|
64
|
-
|
|
114
|
+
POST request with explicit local signing:
|
|
65
115
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"url": "https://api.example.com/order",
|
|
119
|
+
"method": "POST",
|
|
120
|
+
"body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}",
|
|
121
|
+
"sign_mode": "local_private_key"
|
|
122
|
+
}
|
|
123
|
+
```
|
|
71
124
|
|
|
72
|
-
|
|
125
|
+
POST request with quick wallet login through Gate:
|
|
73
126
|
|
|
74
|
-
|
|
75
|
-
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
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"
|
|
134
|
+
}
|
|
135
|
+
```
|
|
76
136
|
|
|
77
137
|
## Development
|
|
78
138
|
|
|
79
139
|
```bash
|
|
80
|
-
#
|
|
81
|
-
|
|
140
|
+
# install dependencies
|
|
141
|
+
npm install
|
|
82
142
|
|
|
83
|
-
#
|
|
84
|
-
|
|
143
|
+
# build TypeScript output into dist/
|
|
144
|
+
npm run build
|
|
85
145
|
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
# or without build step
|
|
89
|
-
pnpm run dev
|
|
146
|
+
# start the MCP server from source
|
|
147
|
+
npm run dev
|
|
90
148
|
|
|
91
|
-
#
|
|
92
|
-
|
|
149
|
+
# run the built entrypoint through the package start script
|
|
150
|
+
npm start
|
|
151
|
+
|
|
152
|
+
# run unit tests
|
|
153
|
+
npm run test:unit
|
|
154
|
+
|
|
155
|
+
# run the local private key flow test
|
|
156
|
+
npm run test:privateKey
|
|
157
|
+
|
|
158
|
+
# run the MCP tool integration test
|
|
159
|
+
npm run test:mcp-tool
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Integration test notes
|
|
163
|
+
|
|
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:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npm run build
|
|
168
|
+
MCP_WALLET_API_KEY=your-key npm run test:mcp-tool
|
|
93
169
|
```
|
|
94
170
|
|
|
95
|
-
|
|
171
|
+
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
172
|
|
|
97
|
-
## How
|
|
173
|
+
## How It Works
|
|
98
174
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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.
|
|
103
181
|
|
|
104
182
|
## License
|
|
105
183
|
|
package/dist/src/index.js
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* x402 stdio bridge
|
|
4
|
-
*
|
|
5
|
-
* All x402 logic is inlined under x402-standalone/ so this package
|
|
6
|
-
* can be published and run via `npx -y gatepay-local-mcp` without
|
|
7
|
-
* depending on unpublished @x402/core, @x402/evm, @x402/fetch.
|
|
8
|
-
*
|
|
9
|
-
* One MCP tool: x402_request
|
|
10
|
-
* - url: full URL (required)
|
|
11
|
-
* - method: GET | POST | PUT | PATCH (default POST)
|
|
12
|
-
* - body: JSON string for request body (POST/PUT/PATCH); omit for GET
|
|
13
|
-
*
|
|
14
|
-
* Env:
|
|
15
|
-
* EVM_PRIVATE_KEY (required; when run via npx, pass via MCP "env" config)
|
|
16
|
-
* X402_DEBUG_LOG (optional) path to file — when set, append debug logs here (tail -f to debug)
|
|
3
|
+
* x402 stdio bridge with pluggable sign_mode support.
|
|
17
4
|
*/
|
|
18
5
|
import { config } from "dotenv";
|
|
19
|
-
import {
|
|
20
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
21
7
|
import { dirname, join } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
22
9
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
23
10
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
11
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
12
|
+
import { normalizeX402RequestInput } from "./modes/input-normalizer.js";
|
|
13
|
+
import { LocalPrivateKeyMode } from "./modes/local-private-key.js";
|
|
14
|
+
import { PluginWalletMode } from "./modes/plugin-wallet.js";
|
|
15
|
+
import { createSignModeRegistry, formatSignModeSelectionError, } from "./modes/registry.js";
|
|
16
|
+
import { QuickWalletMode } from "./modes/quick-wallet.js";
|
|
17
|
+
import { getMcpClientSync } from "./wallets/wallet-mcp-clients.js";
|
|
26
18
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
27
19
|
function findPackageRoot(startDir) {
|
|
28
20
|
let dir = startDir;
|
|
@@ -37,25 +29,8 @@ function findPackageRoot(startDir) {
|
|
|
37
29
|
}
|
|
38
30
|
const packageRoot = findPackageRoot(__dirname);
|
|
39
31
|
config({ path: join(packageRoot, ".env") });
|
|
40
|
-
const LOG_PATH = process.env.X402_DEBUG_LOG ?? process.env.MCP_X402_DEBUG_LOG;
|
|
41
|
-
const logStream = LOG_PATH
|
|
42
|
-
? (() => {
|
|
43
|
-
try {
|
|
44
|
-
return createWriteStream(LOG_PATH, { flags: "a" });
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
console.error("X402 debug log open failed:", e);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
})()
|
|
51
|
-
: null;
|
|
52
|
-
function debugLog(msg, obj) {
|
|
53
|
-
if (!logStream)
|
|
54
|
-
return;
|
|
55
|
-
const line = `${new Date().toISOString()} ${msg}${obj != null ? " " + JSON.stringify(obj) : ""}\n`;
|
|
56
|
-
logStream.write(line);
|
|
57
|
-
}
|
|
58
32
|
const TOOL_NAME = "x402_request";
|
|
33
|
+
const INSUFFICIENT_BALANCE_CODE = "800001001";
|
|
59
34
|
const INPUT_SCHEMA = {
|
|
60
35
|
type: "object",
|
|
61
36
|
properties: {
|
|
@@ -69,27 +44,101 @@ const INPUT_SCHEMA = {
|
|
|
69
44
|
},
|
|
70
45
|
body: {
|
|
71
46
|
type: "string",
|
|
72
|
-
description:
|
|
47
|
+
description: "JSON string request body for POST/PUT/PATCH. Omit for GET.",
|
|
48
|
+
},
|
|
49
|
+
sign_mode: {
|
|
50
|
+
type: "string",
|
|
51
|
+
description: "Optional preferred signing mode. Omit to auto-select the highest-priority ready mode.",
|
|
52
|
+
enum: ["local_private_key", "quick_wallet", "plugin_wallet"],
|
|
53
|
+
},
|
|
54
|
+
wallet_login_provider: {
|
|
55
|
+
type: "string",
|
|
56
|
+
description: "When quick_wallet needs login: OAuth provider. google = Google account, gate = Gate account. Defaults to gate.",
|
|
57
|
+
enum: ["google", "gate"],
|
|
73
58
|
},
|
|
74
59
|
},
|
|
75
60
|
required: ["url"],
|
|
76
61
|
};
|
|
77
62
|
const TOOL_DESCRIPTION = "Execute a single HTTP request with automatic x402 payment on 402. Use ONLY for endpoints that require payment (402). " +
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
63
|
+
"Set sign_mode to choose a signing mode, or omit it to auto-select the highest-priority ready mode.";
|
|
64
|
+
function parsePossiblyNestedJson(text) {
|
|
65
|
+
try {
|
|
66
|
+
const parsed = JSON.parse(text);
|
|
67
|
+
if (typeof parsed === "string") {
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(parsed);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return parsed;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return parsed;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function containsInsufficientBalanceSignal(message) {
|
|
82
|
+
return message.toLowerCase().includes("insufficient balance");
|
|
83
|
+
}
|
|
84
|
+
async function buildInsufficientBalanceReply(baseMessage) {
|
|
85
|
+
const mcp = getMcpClientSync();
|
|
86
|
+
if (!mcp || !mcp.isAuthenticated()) {
|
|
87
|
+
return [
|
|
88
|
+
"支付失败:检测到余额不足。",
|
|
89
|
+
`原始信息: ${baseMessage}`,
|
|
90
|
+
"当前无法获取钱包余额(未检测到已登录的托管钱包会话)。",
|
|
91
|
+
].join("\n");
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const tokenListResult = await mcp.walletGetTokenList();
|
|
95
|
+
const content = tokenListResult.content;
|
|
96
|
+
const first = Array.isArray(content)
|
|
97
|
+
? content[0]
|
|
98
|
+
: undefined;
|
|
99
|
+
const balances = first?.type === "text" && typeof first.text === "string"
|
|
100
|
+
? parsePossiblyNestedJson(first.text) ?? first.text
|
|
101
|
+
: tokenListResult;
|
|
102
|
+
return JSON.stringify({
|
|
103
|
+
code: Number(INSUFFICIENT_BALANCE_CODE),
|
|
104
|
+
message: "余额不足,已返回当前钱包余额信息",
|
|
105
|
+
originalMessage: baseMessage,
|
|
106
|
+
walletBalances: balances,
|
|
107
|
+
}, null, 2);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return [
|
|
111
|
+
"支付失败:检测到余额不足。",
|
|
112
|
+
`原始信息: ${baseMessage}`,
|
|
113
|
+
`查询钱包余额失败: ${error instanceof Error ? error.message : String(error)}`,
|
|
114
|
+
].join("\n");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function buildRequestInit(method, body) {
|
|
118
|
+
if (method === "GET") {
|
|
119
|
+
return { method: "GET" };
|
|
85
120
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
121
|
+
if (method === "POST" || method === "PUT" || method === "PATCH") {
|
|
122
|
+
if (body && body.trim()) {
|
|
123
|
+
JSON.parse(body);
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
method,
|
|
127
|
+
headers: { "Content-Type": "application/json" },
|
|
128
|
+
body: body && body.trim() ? body : undefined,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`不支持的 method: ${method}`);
|
|
132
|
+
}
|
|
133
|
+
async function main() {
|
|
134
|
+
const quickWalletMcpUrl = process.env.MCP_WALLET_URL ?? "https://api.gatemcp.ai/mcp/dex";
|
|
135
|
+
const quickWalletApiKey = process.env.MCP_WALLET_API_KEY;
|
|
136
|
+
const pluginWalletServerUrl = process.env.PLUGIN_WALLET_SERVER_URL ?? "https://walletmcp-test.gateweb3.cc/mcp";
|
|
137
|
+
const signModeRegistry = createSignModeRegistry([
|
|
138
|
+
new LocalPrivateKeyMode(),
|
|
139
|
+
new QuickWalletMode({ mcpWalletUrl: quickWalletMcpUrl, mcpApiKey: quickWalletApiKey }),
|
|
140
|
+
new PluginWalletMode({ serverUrl: pluginWalletServerUrl }),
|
|
141
|
+
]);
|
|
93
142
|
const server = new Server({
|
|
94
143
|
name: "x402 Paid Request Bridge (standalone)",
|
|
95
144
|
version: "1.0.0",
|
|
@@ -106,77 +155,104 @@ async function main() {
|
|
|
106
155
|
}));
|
|
107
156
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
108
157
|
const { name, arguments: args } = request.params;
|
|
109
|
-
debugLog("tool call", { name, args });
|
|
110
158
|
if (name !== TOOL_NAME) {
|
|
111
159
|
return {
|
|
112
160
|
content: [{ type: "text", text: `未知工具: ${name}. 仅支持 ${TOOL_NAME}。` }],
|
|
113
161
|
isError: true,
|
|
114
162
|
};
|
|
115
163
|
}
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
if (!url || !url.startsWith("http")) {
|
|
164
|
+
const normalized = normalizeX402RequestInput((args ?? {}));
|
|
165
|
+
if (!normalized.url || !normalized.url.startsWith("http")) {
|
|
119
166
|
return {
|
|
120
167
|
content: [{ type: "text", text: "缺少或无效参数 url(需完整 http/https URL)。" }],
|
|
121
168
|
isError: true,
|
|
122
169
|
};
|
|
123
170
|
}
|
|
124
|
-
|
|
125
|
-
|
|
171
|
+
let payFetch;
|
|
172
|
+
try {
|
|
173
|
+
const selectedMode = await signModeRegistry.selectMode(normalized.signMode);
|
|
174
|
+
payFetch = await signModeRegistry.getOrCreatePayFetch(selectedMode.mode, {
|
|
175
|
+
walletLoginProvider: normalized.walletLoginProvider,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
return {
|
|
180
|
+
content: [{ type: "text", text: formatSignModeSelectionError(error) }],
|
|
181
|
+
isError: true,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
126
184
|
try {
|
|
127
185
|
let init;
|
|
128
|
-
|
|
129
|
-
init =
|
|
130
|
-
}
|
|
131
|
-
else if (method === "POST" || method === "PUT" || method === "PATCH") {
|
|
132
|
-
if (bodyStr && bodyStr.trim()) {
|
|
133
|
-
try {
|
|
134
|
-
JSON.parse(bodyStr);
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
return {
|
|
138
|
-
content: [{ type: "text", text: "body 必须是合法 JSON 字符串。" }],
|
|
139
|
-
isError: true,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
init = {
|
|
144
|
-
method,
|
|
145
|
-
headers: { "Content-Type": "application/json" },
|
|
146
|
-
body: bodyStr && bodyStr.trim() ? bodyStr : undefined,
|
|
147
|
-
};
|
|
186
|
+
try {
|
|
187
|
+
init = buildRequestInit(normalized.method, normalized.body);
|
|
148
188
|
}
|
|
149
|
-
|
|
189
|
+
catch (error) {
|
|
150
190
|
return {
|
|
151
|
-
content: [{ type: "text", text:
|
|
191
|
+
content: [{ type: "text", text: error instanceof Error ? error.message : String(error) }],
|
|
152
192
|
isError: true,
|
|
153
193
|
};
|
|
154
194
|
}
|
|
155
|
-
|
|
156
|
-
const response = await fetchWithPayment(url, init);
|
|
195
|
+
const response = await payFetch(normalized.url, init);
|
|
157
196
|
const responseText = await response.text();
|
|
158
|
-
debugLog("fetch done", { url, status: response.status, textLen: responseText.length });
|
|
159
197
|
let text;
|
|
160
198
|
try {
|
|
161
199
|
const json = JSON.parse(responseText);
|
|
162
|
-
text =
|
|
200
|
+
text =
|
|
201
|
+
json.data != null
|
|
202
|
+
? JSON.stringify(json.data, null, 2)
|
|
203
|
+
: JSON.stringify(json, null, 2);
|
|
163
204
|
}
|
|
164
205
|
catch {
|
|
165
206
|
text = responseText;
|
|
166
207
|
}
|
|
208
|
+
const insufficientBalance = containsInsufficientBalanceSignal(responseText) ||
|
|
209
|
+
containsInsufficientBalanceSignal(text);
|
|
167
210
|
if (!response.ok && response.status !== 402) {
|
|
211
|
+
if (insufficientBalance) {
|
|
212
|
+
return {
|
|
213
|
+
content: [
|
|
214
|
+
{
|
|
215
|
+
type: "text",
|
|
216
|
+
text: await buildInsufficientBalanceReply(text),
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
isError: true,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
168
222
|
return {
|
|
169
223
|
content: [{ type: "text", text: `HTTP ${response.status}: ${text}` }],
|
|
170
224
|
isError: true,
|
|
171
225
|
};
|
|
172
226
|
}
|
|
227
|
+
// 上游常以 HTTP 200 + 业务 JSON(message 含 insufficient balance)表示余额不足,需同样拉取钱包余额
|
|
228
|
+
if (insufficientBalance) {
|
|
229
|
+
return {
|
|
230
|
+
content: [
|
|
231
|
+
{
|
|
232
|
+
type: "text",
|
|
233
|
+
text: await buildInsufficientBalanceReply(text),
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
isError: true,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
173
239
|
return { content: [{ type: "text", text }], isError: false };
|
|
174
240
|
}
|
|
175
241
|
catch (err) {
|
|
176
242
|
const message = err instanceof Error ? err.message : String(err);
|
|
177
|
-
|
|
243
|
+
if (containsInsufficientBalanceSignal(message)) {
|
|
244
|
+
return {
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
type: "text",
|
|
248
|
+
text: await buildInsufficientBalanceReply(message),
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
isError: true,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
178
254
|
const hint = message.toLowerCase().includes("fetch") || message.toLowerCase().includes("econnrefused")
|
|
179
|
-
? " 请确认 url 可访问;402
|
|
255
|
+
? " 请确认 url 可访问;402 支付需托管钱包已登录且有足够余额。"
|
|
180
256
|
: "";
|
|
181
257
|
return {
|
|
182
258
|
content: [{ type: "text", text: `请求失败: ${message}.${hint}` }],
|
|
@@ -188,7 +264,6 @@ async function main() {
|
|
|
188
264
|
await server.connect(stdio);
|
|
189
265
|
}
|
|
190
266
|
main().catch((err) => {
|
|
191
|
-
debugLog("fatal", { error: String(err), stack: err instanceof Error ? err.stack : undefined });
|
|
192
267
|
console.error("Fatal error:", err);
|
|
193
268
|
process.exit(1);
|
|
194
269
|
});
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM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AC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC;gBACrF,CAAC,CAAC,oCAAoC;gBACtC,CAAC,CAAC,EAAE,CAAC;YACb,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,SAAS,OAAO,IAAI,IAAI,EAAE,EAAE,CAAC;gBACtE,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,IAAI,oBAAoB,EAAE,CAAC;IACzC,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PayFetchFactory } from "./types.js";
|
|
2
|
+
export declare class DefaultPayFetchFactory implements PayFetchFactory {
|
|
3
|
+
build({ signer }: {
|
|
4
|
+
signer: import("../x402/types.js").ClientEvmSigner;
|
|
5
|
+
}): typeof fetch;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=build-pay-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-pay-fetch.d.ts","sourceRoot":"","sources":["../../../src/modes/build-pay-fetch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAYlD,qBAAa,sBAAuB,YAAW,eAAe;IAC5D,KAAK,CAAC,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,OAAO,kBAAkB,EAAE,eAAe,CAAA;KAAE,GAAG,OAAO,KAAK;CAOxF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { X402ClientStandalone } from "../x402/client.js";
|
|
2
|
+
import { ExactEvmScheme } from "../x402/exactEvmScheme.js";
|
|
3
|
+
import { wrapFetchWithPayment } from "../x402/fetch.js";
|
|
4
|
+
const SUPPORTED_NETWORKS = [
|
|
5
|
+
"gatelayer_testnet",
|
|
6
|
+
"eth",
|
|
7
|
+
"base",
|
|
8
|
+
"Polygon",
|
|
9
|
+
"gatelayer",
|
|
10
|
+
"gatechain",
|
|
11
|
+
"Arbitrum One",
|
|
12
|
+
];
|
|
13
|
+
export class DefaultPayFetchFactory {
|
|
14
|
+
build({ signer }) {
|
|
15
|
+
const client = new X402ClientStandalone();
|
|
16
|
+
for (const network of SUPPORTED_NETWORKS) {
|
|
17
|
+
client.register(network, new ExactEvmScheme(signer));
|
|
18
|
+
}
|
|
19
|
+
return wrapFetchWithPayment(fetch, client);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=build-pay-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-pay-fetch.js","sourceRoot":"","sources":["../../../src/modes/build-pay-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,kBAAkB,GAAG;IACzB,mBAAmB;IACnB,KAAK;IACL,MAAM;IACN,SAAS;IACT,WAAW;IACX,WAAW;IACX,cAAc;CACN,CAAC;AAEX,MAAM,OAAO,sBAAsB;IACjC,KAAK,CAAC,EAAE,MAAM,EAA0D;QACtE,MAAM,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC1C,KAAK,MAAM,OAAO,IAAI,kBAAkB,EAAE,CAAC;YACzC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;CACF"}
|