gatepay-local-mcp 1.0.10 → 1.2.0
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 +198 -8
- package/dist/src/config/env-config.d.ts +38 -0
- package/dist/src/config/env-config.d.ts.map +1 -1
- package/dist/src/config/env-config.js +46 -0
- package/dist/src/config/env-config.js.map +1 -1
- package/dist/src/config/tool-display-names.d.ts +8 -0
- package/dist/src/config/tool-display-names.d.ts.map +1 -0
- package/dist/src/config/tool-display-names.js +15 -0
- package/dist/src/config/tool-display-names.js.map +1 -0
- package/dist/src/config/tool-display-names.json +15 -0
- package/dist/src/config/tracking-product-defaults.json +12 -0
- package/dist/src/gate-pay/pay-token-store.d.ts.map +1 -1
- package/dist/src/gate-pay/pay-token-store.js +8 -0
- package/dist/src/gate-pay/pay-token-store.js.map +1 -1
- package/dist/src/index.js +51 -30
- package/dist/src/index.js.map +1 -1
- package/dist/src/modes/build-pay-fetch.d.ts +2 -5
- package/dist/src/modes/build-pay-fetch.d.ts.map +1 -1
- package/dist/src/modes/build-pay-fetch.js +1 -1
- package/dist/src/modes/build-pay-fetch.js.map +1 -1
- package/dist/src/modes/quick-wallet.js +10 -8
- package/dist/src/modes/quick-wallet.js.map +1 -1
- package/dist/src/modes/registry.d.ts.map +1 -1
- package/dist/src/modes/registry.js +1 -0
- package/dist/src/modes/registry.js.map +1 -1
- package/dist/src/modes/signers/index.d.ts +2 -1
- package/dist/src/modes/signers/index.d.ts.map +1 -1
- package/dist/src/modes/signers/index.js +1 -1
- package/dist/src/modes/signers/index.js.map +1 -1
- package/dist/src/modes/signers/local-private-key.d.ts.map +1 -1
- package/dist/src/modes/signers/local-private-key.js +2 -0
- package/dist/src/modes/signers/local-private-key.js.map +1 -1
- package/dist/src/modes/signers/plugin-wallet.d.ts +5 -0
- package/dist/src/modes/signers/plugin-wallet.d.ts.map +1 -1
- package/dist/src/modes/signers/plugin-wallet.js +156 -1
- package/dist/src/modes/signers/plugin-wallet.js.map +1 -1
- package/dist/src/modes/signers/quick-wallet.d.ts +12 -4
- package/dist/src/modes/signers/quick-wallet.d.ts.map +1 -1
- package/dist/src/modes/signers/quick-wallet.js +48 -4
- package/dist/src/modes/signers/quick-wallet.js.map +1 -1
- package/dist/src/modes/signers/shared-utils.d.ts +4 -0
- package/dist/src/modes/signers/shared-utils.d.ts.map +1 -1
- package/dist/src/modes/signers/shared-utils.js +24 -0
- package/dist/src/modes/signers/shared-utils.js.map +1 -1
- package/dist/src/modes/types.d.ts +2 -0
- package/dist/src/modes/types.d.ts.map +1 -1
- package/dist/src/mpp-base/escrow.d.ts +54 -0
- package/dist/src/mpp-base/escrow.d.ts.map +1 -0
- package/dist/src/mpp-base/escrow.js +91 -0
- package/dist/src/mpp-base/escrow.js.map +1 -0
- package/dist/src/mpp-base/index.d.ts +160 -0
- package/dist/src/mpp-base/index.d.ts.map +1 -0
- package/dist/src/mpp-base/index.js +458 -0
- package/dist/src/mpp-base/index.js.map +1 -0
- package/dist/src/mpp-base/usdc.d.ts +680 -0
- package/dist/src/mpp-base/usdc.d.ts.map +1 -0
- package/dist/src/mpp-base/usdc.js +113 -0
- package/dist/src/mpp-base/usdc.js.map +1 -0
- package/dist/src/tools/centralized-payment.d.ts.map +1 -1
- package/dist/src/tools/centralized-payment.js +32 -12
- package/dist/src/tools/centralized-payment.js.map +1 -1
- package/dist/src/tools/create-signature.d.ts.map +1 -1
- package/dist/src/tools/create-signature.js +1 -0
- package/dist/src/tools/create-signature.js.map +1 -1
- package/dist/src/tools/gate-pay-auth.d.ts.map +1 -1
- package/dist/src/tools/gate-pay-auth.js +5 -1
- package/dist/src/tools/gate-pay-auth.js.map +1 -1
- package/dist/src/tools/index.d.ts +2 -1
- package/dist/src/tools/index.d.ts.map +1 -1
- package/dist/src/tools/index.js +2 -1
- package/dist/src/tools/index.js.map +1 -1
- package/dist/src/tools/mpp-session-store.d.ts +94 -0
- package/dist/src/tools/mpp-session-store.d.ts.map +1 -0
- package/dist/src/tools/mpp-session-store.js +77 -0
- package/dist/src/tools/mpp-session-store.js.map +1 -0
- package/dist/src/tools/mpp-session.d.ts +38 -0
- package/dist/src/tools/mpp-session.d.ts.map +1 -0
- package/dist/src/tools/mpp-session.js +506 -0
- package/dist/src/tools/mpp-session.js.map +1 -0
- package/dist/src/tools/place-order.d.ts.map +1 -1
- package/dist/src/tools/place-order.js +8 -0
- package/dist/src/tools/place-order.js.map +1 -1
- package/dist/src/tools/quick-wallet-auth.d.ts.map +1 -1
- package/dist/src/tools/quick-wallet-auth.js +2 -0
- package/dist/src/tools/quick-wallet-auth.js.map +1 -1
- package/dist/src/tools/schemas.d.ts +187 -0
- package/dist/src/tools/schemas.d.ts.map +1 -1
- package/dist/src/tools/schemas.js +169 -9
- package/dist/src/tools/schemas.js.map +1 -1
- package/dist/src/tools/{sign-payment.d.ts → x402-sign-payment.d.ts} +1 -1
- package/dist/src/tools/x402-sign-payment.d.ts.map +1 -0
- package/dist/src/tools/{sign-payment.js → x402-sign-payment.js} +2 -1
- package/dist/src/tools/x402-sign-payment.js.map +1 -0
- package/dist/src/tracking/config.d.ts +26 -0
- package/dist/src/tracking/config.d.ts.map +1 -0
- package/dist/src/tracking/config.js +46 -0
- package/dist/src/tracking/config.js.map +1 -0
- package/dist/src/tracking/format-tracking-request.d.ts +9 -0
- package/dist/src/tracking/format-tracking-request.d.ts.map +1 -0
- package/dist/src/tracking/format-tracking-request.js +38 -0
- package/dist/src/tracking/format-tracking-request.js.map +1 -0
- package/dist/src/tracking/identity.d.ts +10 -0
- package/dist/src/tracking/identity.d.ts.map +1 -0
- package/dist/src/tracking/identity.js +93 -0
- package/dist/src/tracking/identity.js.map +1 -0
- package/dist/src/tracking/tracker.d.ts +33 -0
- package/dist/src/tracking/tracker.d.ts.map +1 -0
- package/dist/src/tracking/tracker.js +214 -0
- package/dist/src/tracking/tracker.js.map +1 -0
- package/dist/src/tracking/tracking-invocation-context.d.ts +19 -0
- package/dist/src/tracking/tracking-invocation-context.d.ts.map +1 -0
- package/dist/src/tracking/tracking-invocation-context.js +86 -0
- package/dist/src/tracking/tracking-invocation-context.js.map +1 -0
- package/dist/src/tracking/with-tracking.d.ts +2 -0
- package/dist/src/tracking/with-tracking.d.ts.map +1 -0
- package/dist/src/tracking/with-tracking.js +72 -0
- package/dist/src/tracking/with-tracking.js.map +1 -0
- package/dist/src/utils/package-version.d.ts +3 -0
- package/dist/src/utils/package-version.d.ts.map +1 -0
- package/dist/src/utils/package-version.js +30 -0
- package/dist/src/utils/package-version.js.map +1 -0
- package/dist/src/wallets/plugin-wallet-client.d.ts +13 -0
- package/dist/src/wallets/plugin-wallet-client.d.ts.map +1 -1
- package/dist/src/wallets/plugin-wallet-client.js +3 -0
- package/dist/src/wallets/plugin-wallet-client.js.map +1 -1
- package/dist/src/x402/exactEvmScheme.js +1 -1
- package/dist/src/x402/exactEvmScheme.js.map +1 -1
- package/dist/src/x402/fetch.d.ts +4 -1
- package/dist/src/x402/fetch.d.ts.map +1 -1
- package/dist/src/x402/fetch.js +6 -1
- package/dist/src/x402/fetch.js.map +1 -1
- package/dist/src/x402/types.d.ts +7 -1
- package/dist/src/x402/types.d.ts.map +1 -1
- package/package.json +5 -1
- package/dist/src/tools/sign-payment.d.ts.map +0 -1
- package/dist/src/tools/sign-payment.js.map +0 -1
package/Readme.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# gatepay-local-mcp
|
|
2
2
|
|
|
3
|
-
`gatepay-local-mcp` is a local `stdio` MCP server for calling **X402 payment-protected
|
|
3
|
+
`gatepay-local-mcp` is a local `stdio` MCP server for calling **X402** and **MPP (Base + USDC)** payment-protected HTTP endpoints. It exposes MCP tools for X402 (`PAYMENT-REQUIRED`), Gate Pay centralized settlement, and MPP session flows (`WWW-Authenticate`, on-chain escrow, HTTP close / optional chain withdraw).
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
7
|
+
- **12 MCP Tools**: X402 order + signature flows, Gate Pay centralized payment, and **MPP (Base + USDC)** session tools (`mpp_*`)
|
|
8
8
|
- Built-in X402 payment flow under `src/x402/`
|
|
9
|
+
- **MPP session flow** under `src/mpp-base/` + `mppx`: on-chain escrow channel, `402` / `WWW-Authenticate` handling, HTTP settlement, and optional on-chain `requestClose` / `withdraw`
|
|
9
10
|
- **Multiple signing modes**: `local_private_key`, `quick_wallet`, `plugin_wallet`
|
|
10
11
|
- **Multi-chain support**: EVM (Ethereum, Base, Polygon, etc.) and Solana
|
|
11
12
|
- Works with Cursor, Claude Desktop, and other MCP clients
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
|
|
19
20
|
Send an HTTP request and return complete response information including headers, body, and the original request details.
|
|
20
21
|
|
|
21
|
-
**Use case**:
|
|
22
|
+
**Use case**: Probe a URL that may return `402 Payment Required` — detect whether the merchant uses **X402** (`PAYMENT-REQUIRED`) or **MPP** (`WWW-Authenticate`) before choosing tools.
|
|
22
23
|
|
|
23
24
|
**Parameters**:
|
|
24
25
|
```typescript
|
|
@@ -31,7 +32,10 @@ Send an HTTP request and return complete response information including headers,
|
|
|
31
32
|
}
|
|
32
33
|
```
|
|
33
34
|
|
|
34
|
-
**Returns**: Complete response with status code, headers
|
|
35
|
+
**Returns**: Complete response with status code, headers, body, original request details, and **`paymentType`** when detectable:
|
|
36
|
+
|
|
37
|
+
- **`x402`**: response includes a `PAYMENT-REQUIRED` header — use the X402 tools below (`x402_sign_payment`, or split create/submit).
|
|
38
|
+
- **`mpp`**: response includes `WWW-Authenticate` — **do not** use X402 signing tools; run **`mpp_init_session`** then **`mpp_fetch`** (see MPP sections).
|
|
35
39
|
|
|
36
40
|
---
|
|
37
41
|
|
|
@@ -137,6 +141,9 @@ Parse the Base64-encoded `PAYMENT-REQUIRED` header and complete the Gate Pay cen
|
|
|
137
141
|
```typescript
|
|
138
142
|
{
|
|
139
143
|
payment_required_header: string; // Base64-encoded PAYMENT-REQUIRED header (required)
|
|
144
|
+
resource_url: string; // Full http/https merchant URL after pay — same rules as x402_place_order `url` (required)
|
|
145
|
+
method?: "GET" | "POST" | "PUT" | "PATCH"; // default POST
|
|
146
|
+
body?: string; // JSON string for POST/PUT/PATCH; omit for GET
|
|
140
147
|
}
|
|
141
148
|
```
|
|
142
149
|
|
|
@@ -144,6 +151,112 @@ Parse the Base64-encoded `PAYMENT-REQUIRED` header and complete the Gate Pay cen
|
|
|
144
151
|
|
|
145
152
|
---
|
|
146
153
|
|
|
154
|
+
## MPP tools (Base + USDC session)
|
|
155
|
+
|
|
156
|
+
MPP (multi-party payment over an on-chain escrow channel) is separate from X402’s `PAYMENT-REQUIRED` header flow. The server caches one **session per EVM address** after `mpp_init_session`. Signing modes are the same three as X402 for EVM operations: `local_private_key`, `quick_wallet`, `plugin_wallet` (with `quick_wallet` / `plugin_wallet` needing `signTransaction` for on-chain channel steps).
|
|
157
|
+
|
|
158
|
+
**Important**
|
|
159
|
+
|
|
160
|
+
- Serialize **`mpp_fetch`** calls for a given session (one in flight at a time) so vouchers and channel state stay consistent.
|
|
161
|
+
- **`mpp_close_session`** (HTTP): merchant billing + `Payment-Receipt`, then clears the local cache.
|
|
162
|
+
- **`mpp_request_close`** / **`mpp_withdraw`**: **on-chain only**; they do not replace HTTP close. After `mpp_request_close`, wait for the contract-defined period before `mpp_withdraw`.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
### 8. `mpp_init_session`
|
|
167
|
+
|
|
168
|
+
Initialize the cached MPP session manager (max deposit, signer selection). Call this **before** any `mpp_fetch`.
|
|
169
|
+
|
|
170
|
+
**Use case**: First step for merchants that return `402` with `WWW-Authenticate` (MPP challenges).
|
|
171
|
+
|
|
172
|
+
**Parameters**:
|
|
173
|
+
```typescript
|
|
174
|
+
{
|
|
175
|
+
max_deposit?: string; // Human-readable max deposit, e.g. "10" (default "1")
|
|
176
|
+
sign_mode?: "local_private_key" | "quick_wallet" | "plugin_wallet"; // omit = auto: local → quick → plugin
|
|
177
|
+
wallet_login_provider?: "google" | "gate"; // when quick_wallet is used (default: gate)
|
|
178
|
+
decimals?: number; // Token decimals (default 6)
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Returns**: `sessionId`, effective `signMode`, `loadStrategy`, `loadAttempts` (explains auto-selection when `sign_mode` was omitted).
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
### 9. `mpp_fetch`
|
|
187
|
+
|
|
188
|
+
Perform an HTTP request through the cached MPP client: handles `402` / `WWW-Authenticate`, builds credentials, retries after payment negotiation.
|
|
189
|
+
|
|
190
|
+
**Use case**: Call the merchant URL after `mpp_init_session`. The first successful `402` flow establishes or confirms the on-chain escrow **channel**.
|
|
191
|
+
|
|
192
|
+
**Parameters**:
|
|
193
|
+
```typescript
|
|
194
|
+
{
|
|
195
|
+
url: string; // Full http/https resource URL (required)
|
|
196
|
+
method?: "GET" | "POST" | "PUT" | "PATCH"; // default POST
|
|
197
|
+
body?: string; // JSON string body (optional)
|
|
198
|
+
headers?: string; // Extra headers as JSON object string (optional)
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Returns**: HTTP result from the merchant after MPP negotiation (and receipt metadata when present).
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### 10. `mpp_close_session`
|
|
207
|
+
|
|
208
|
+
HTTP-side settlement: sign a **close** credential, `POST` to the **same resource URL last used by `mpp_fetch`**, parse `Payment-Receipt`, then clear the local session.
|
|
209
|
+
|
|
210
|
+
**Use case**: Normal end-of-session cleanup when the merchant should finalize billing and you want to drop the local MPP cache.
|
|
211
|
+
|
|
212
|
+
**Parameters**:
|
|
213
|
+
```typescript
|
|
214
|
+
{
|
|
215
|
+
account_address?: string; // Optional EVM address; if omitted, closes one active cached session
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**Returns**: Close / receipt outcome; local session cleared for that account.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### 11. `mpp_request_close`
|
|
224
|
+
|
|
225
|
+
On-chain only: call the escrow contract’s **`requestClose(channelId)`** to start closing the channel on Base.
|
|
226
|
+
|
|
227
|
+
**Use case**: Begin on-chain closure after you no longer need paid fetches; does **not** call the merchant, does **not** return `Payment-Receipt`, does **not** clear the local session.
|
|
228
|
+
|
|
229
|
+
**Parameters**:
|
|
230
|
+
```typescript
|
|
231
|
+
{
|
|
232
|
+
account_address?: string; // Optional EVM address for the cached session
|
|
233
|
+
rpc_url?: string; // Optional JSON-RPC override (else `MPP_BASE_RPC_URL` / `BASE_RPC_URL` or built-in defaults)
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Returns**: Transaction / chain result for `requestClose`.
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
### 12. `mpp_withdraw`
|
|
242
|
+
|
|
243
|
+
On-chain only: call **`withdraw(channelId)`** after `mpp_request_close` **and** the contract wait period — recovers remaining escrowed funds.
|
|
244
|
+
|
|
245
|
+
**Use case**: Recover on-chain balance after the channel is closable; too early and the contract reverts.
|
|
246
|
+
|
|
247
|
+
**Parameters**:
|
|
248
|
+
```typescript
|
|
249
|
+
{
|
|
250
|
+
account_address?: string; // Optional EVM address
|
|
251
|
+
channel_id?: string; // Optional 0x + 64 hex; omit if channel is still in local cache after paid fetches
|
|
252
|
+
rpc_url?: string; // Optional JSON-RPC override
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Returns**: Transaction / chain result for `withdraw`.
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
147
260
|
## Workflow Examples
|
|
148
261
|
|
|
149
262
|
### Single-Step Workflow (Recommended)
|
|
@@ -176,7 +289,24 @@ Parse the Base64-encoded `PAYMENT-REQUIRED` header and complete the Gate Pay cen
|
|
|
176
289
|
2. x402_place_order → Receive PAYMENT-REQUIRED header that encodes Gate Pay order info
|
|
177
290
|
3. x402_submit_payment → Use payment_signature + sign_mode: "centralized_payment" to call the merchant with Authorization: Bearer
|
|
178
291
|
或
|
|
179
|
-
3. x402_centralized_payment →
|
|
292
|
+
3. x402_centralized_payment → payment_required_header + resource_url (full http/https); pays then retries merchant with X-GatePay-Centralized-Merchant-No
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### MPP (WWW-Authenticate / Base escrow)
|
|
296
|
+
|
|
297
|
+
```
|
|
298
|
+
1. x402_place_order → If paymentType is mpp, note WWW-Authenticate / 402 body
|
|
299
|
+
2. mpp_init_session → Cache session + signer (local_private_key, quick_wallet, or plugin_wallet)
|
|
300
|
+
3. mpp_fetch → Same merchant URL/method/body; handles 402 + channel (serialize calls)
|
|
301
|
+
4. mpp_close_session → HTTP settlement + Payment-Receipt; clears local session
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Optional on-chain teardown (after you are done with HTTP billing and understand contract timing):
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
5. mpp_request_close → Escrow requestClose on-chain (session cache unchanged)
|
|
308
|
+
6. (wait for contract period)
|
|
309
|
+
7. mpp_withdraw → On-chain withdraw of remaining deposit
|
|
180
310
|
```
|
|
181
311
|
|
|
182
312
|
## Signing Modes
|
|
@@ -298,7 +428,7 @@ Use this when merchants expect Gate Pay centralized settlement instead of user-o
|
|
|
298
428
|
|
|
299
429
|
- Run `x402_gate_pay_auth` once per token lifecycle; it opens the Gate consent page and exchanges the code automatically.
|
|
300
430
|
- Use `x402_submit_payment` with `sign_mode: "centralized_payment"` after you create a `PAYMENT-SIGNATURE`, or
|
|
301
|
-
- Call `x402_centralized_payment`
|
|
431
|
+
- Call `x402_centralized_payment` with the Base64 `PAYMENT-REQUIRED` header plus required `resource_url` (same http/https rules as `x402_place_order`) when you prefer a single-step helper.
|
|
302
432
|
|
|
303
433
|
### Cursor / Claude Desktop with plugin wallet
|
|
304
434
|
|
|
@@ -339,6 +469,21 @@ The server loads `.env` from the repository or package root at startup.
|
|
|
339
469
|
| `QUICK_WALLET_API_KEY` | `quick_wallet` | API key for MCP wallet service (optional) |
|
|
340
470
|
| `PLUGIN_WALLET_TOKEN` | `plugin_wallet` | MCP token from browser extension wallet |
|
|
341
471
|
|
|
472
|
+
### MPP (Base session)
|
|
473
|
+
|
|
474
|
+
| Variable | Description |
|
|
475
|
+
| ---------------------------- | --------------------------------------------------------------------------- |
|
|
476
|
+
| `MPP_BASE_CHAIN_ID` | Base chain id for the MPP session (overrides `BASE_CHAIN_ID` and `GATE_PAY_ENV` preset) |
|
|
477
|
+
| `BASE_CHAIN_ID` | Fallback chain id when `MPP_BASE_CHAIN_ID` is unset |
|
|
478
|
+
| `GATE_PAY_ENV` | Preset when neither chain id is set: `test` → Base Sepolia `84532`, else Base mainnet `8453` |
|
|
479
|
+
| `MPP_BASE_ESCROW_CONTRACT` | Override escrow contract address (else `BASE_ESCROW_CONTRACT` or mpp-base default) |
|
|
480
|
+
| `BASE_ESCROW_CONTRACT` | Alternate env name for escrow contract override |
|
|
481
|
+
| `MPP_BASE_RPC_URL` | JSON-RPC URL for Base on-chain writes (`requestClose` / `withdraw`, channel reads) |
|
|
482
|
+
| `BASE_RPC_URL` | Fallback RPC URL when `MPP_BASE_RPC_URL` is unset |
|
|
483
|
+
| `QUICK_WALLET_MPP_EVM_CHAIN` | Gate MCP chain label for Quick Wallet tx signing (default `BASE`) when using `quick_wallet` with MPP |
|
|
484
|
+
|
|
485
|
+
`local_private_key` for MPP requires **`EVM_PRIVATE_KEY`** (or **`PRIVATE_KEY`**) for Base signing. `quick_wallet` / `plugin_wallet` must expose the signing APIs required for typed data and contract calls (see server errors if misconfigured).
|
|
486
|
+
|
|
342
487
|
### Gate Pay Centralized Payment
|
|
343
488
|
|
|
344
489
|
| Variable | Description |
|
|
@@ -363,6 +508,9 @@ The server loads `.env` from the repository or package root at startup.
|
|
|
363
508
|
| `RESOURCE_SERVER_URL` | `test/privateKey.test.ts` | `http://localhost:8080` | Base URL for the local private-key flow test |
|
|
364
509
|
| `ENDPOINT_PATH` | `test/privateKey.test.ts` | `/flight/order` | Endpoint path appended to `RESOURCE_SERVER_URL` |
|
|
365
510
|
| `GATEPAY_MCP_TEST_TIMEOUT_MS` | `test/mcp-x402-request-tool.ts` | `180000` | Timeout for the MCP tool integration test |
|
|
511
|
+
| `MPP_SESSION_TEST_URL` | `test/mpp-session.manual.ts` | `http://localhost:8080/api/image/generate` | Full URL for MPP manual init/fetch/close script |
|
|
512
|
+
| `MPP_SESSION_TEST_BODY` | `test/mpp-session.manual.ts` | `{"prompt":"mpp-session-manual-test"}` | POST body JSON string for the MPP manual script |
|
|
513
|
+
| `MPP_SESSION_TEST_REQUEST_CLOSE` | `test/mpp-session.manual.ts` | unset | Set to `1` to run on-chain `mpp_request_close` before HTTP close in the manual script |
|
|
366
514
|
|
|
367
515
|
## Usage Examples
|
|
368
516
|
|
|
@@ -436,7 +584,10 @@ The server loads `.env` from the repository or package root at startup.
|
|
|
436
584
|
{
|
|
437
585
|
"tool": "x402_centralized_payment",
|
|
438
586
|
"arguments": {
|
|
439
|
-
"payment_required_header": "<base64-from-place_order>"
|
|
587
|
+
"payment_required_header": "<base64-from-place_order>",
|
|
588
|
+
"resource_url": "https://api.example.com/order",
|
|
589
|
+
"method": "POST",
|
|
590
|
+
"body": "{\"orderId\":\"ORD-123\"}"
|
|
440
591
|
}
|
|
441
592
|
}
|
|
442
593
|
|
|
@@ -452,9 +603,45 @@ The server loads `.env` from the repository or package root at startup.
|
|
|
452
603
|
}
|
|
453
604
|
```
|
|
454
605
|
|
|
606
|
+
### Example 5: MPP session (place order → init → fetch → close)
|
|
607
|
+
|
|
608
|
+
```json
|
|
609
|
+
// Step 0: Discover payment type (mpp → WWW-Authenticate)
|
|
610
|
+
{
|
|
611
|
+
"tool": "x402_place_order",
|
|
612
|
+
"arguments": {
|
|
613
|
+
"url": "https://api.example.com/mpp/resource",
|
|
614
|
+
"method": "POST",
|
|
615
|
+
"body": "{\"prompt\":\"hello\"}"
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// Step 1: Init session (after confirming paymentType is mpp)
|
|
620
|
+
{
|
|
621
|
+
"tool": "mpp_init_session",
|
|
622
|
+
"arguments": {
|
|
623
|
+
"max_deposit": "5",
|
|
624
|
+
"sign_mode": "local_private_key"
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Step 2: Paid fetch (run fetches one at a time for this session)
|
|
629
|
+
{
|
|
630
|
+
"tool": "mpp_fetch",
|
|
631
|
+
"arguments": {
|
|
632
|
+
"url": "https://api.example.com/mpp/resource",
|
|
633
|
+
"method": "POST",
|
|
634
|
+
"body": "{\"prompt\":\"hello\"}"
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Step 3: HTTP close + receipt + clear cache
|
|
639
|
+
{ "tool": "mpp_close_session", "arguments": {} }
|
|
640
|
+
```
|
|
641
|
+
|
|
455
642
|
## Agent Skill
|
|
456
643
|
|
|
457
|
-
- `skills/SKILL.md` contains the `gatepay-x402` skill manifest and prompts so MCP-aware IDEs (Cursor, Claude Desktop, Codex CLI, etc.) know how to call every tool exposed by this server.
|
|
644
|
+
- `skills/SKILL.md` contains the `gatepay-x402` skill manifest and prompts so MCP-aware IDEs (Cursor, Claude Desktop, Codex CLI, etc.) know how to call every tool exposed by this server (including `mpp_*` when present in your build).
|
|
458
645
|
- `skills/gatepay-x402.md` (mirrored at `docs/gatepay-x402.md`) is a natural-language installation guide. Share that link with your AI host for a “one-click” experience: the host can follow the steps to download `gatepay-local-mcp`, register it in `mcpServers`, and copy the `gatepay-x402` skill into its skills directory automatically.
|
|
459
646
|
|
|
460
647
|
Tool names and arguments always match each tool’s MCP `inputSchema` on the server you connect to; check your client’s tool list if you ship a trimmed build.
|
|
@@ -480,6 +667,9 @@ npm run test:unit
|
|
|
480
667
|
# run the local private key flow test
|
|
481
668
|
npm run test:privateKey
|
|
482
669
|
|
|
670
|
+
# MPP session manual (init → fetch ×3 → close; optional on-chain steps via env)
|
|
671
|
+
npm run test:mpp-session
|
|
672
|
+
|
|
483
673
|
# MCP / x402 集成探针(需 build 后 dist)
|
|
484
674
|
npm run test:split-tools
|
|
485
675
|
```
|
|
@@ -30,4 +30,42 @@ export declare function getEnvironment(): Environment;
|
|
|
30
30
|
* 优先级:直接设置的环境变量 > GATE_PAY_ENV 预设配置 > 默认值
|
|
31
31
|
*/
|
|
32
32
|
export declare function getEnvConfig(): EnvironmentConfig;
|
|
33
|
+
/**
|
|
34
|
+
* MPP Base session 的 chainId。
|
|
35
|
+
* 优先级:MPP_BASE_CHAIN_ID、BASE_CHAIN_ID > GATE_PAY_ENV 预设(test→84532,prd→8453)
|
|
36
|
+
*/
|
|
37
|
+
export declare function getMppBaseSessionChainId(): number;
|
|
38
|
+
/** 埋点侧「与本 MCP 进程绑定」的固定维度;含默认上报 App Key(见 JSON `defaultAppKey`) */
|
|
39
|
+
export declare const TRACKING_PRODUCT_DEFAULTS: {
|
|
40
|
+
defaultReportHost: string;
|
|
41
|
+
defaultAppId: number;
|
|
42
|
+
defaultAppKey: string;
|
|
43
|
+
appName: string;
|
|
44
|
+
appPlatform: string;
|
|
45
|
+
accessMethod: string;
|
|
46
|
+
clientType: string;
|
|
47
|
+
businessModule: string;
|
|
48
|
+
productLine: string;
|
|
49
|
+
eventName: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 埋点上报所需配置(host / appId / appKey)及与产品文档对齐的固定维度。
|
|
53
|
+
* - 默认 `appKey` 见 `tracking-product-defaults.json` 的 `defaultAppKey`(gateio 主站),用户无需配置;分站等可用 `VOLC_TRACKING_APP_KEY` 覆盖。
|
|
54
|
+
* - `VOLC_TRACKING_ENABLED` 为 `false` 时关闭上报。
|
|
55
|
+
*/
|
|
56
|
+
export interface TrackingConfig {
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
reportHost: string;
|
|
59
|
+
appId: number;
|
|
60
|
+
appKey: string;
|
|
61
|
+
gatePayEnv: Environment;
|
|
62
|
+
appName: string;
|
|
63
|
+
appPlatform: string;
|
|
64
|
+
accessMethod: string;
|
|
65
|
+
clientType: string;
|
|
66
|
+
businessModule: string;
|
|
67
|
+
productLine: string;
|
|
68
|
+
eventName: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function getTrackingConfig(): TrackingConfig;
|
|
33
71
|
//# sourceMappingURL=env-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-config.d.ts","sourceRoot":"","sources":["../../../src/config/env-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"env-config.d.ts","sourceRoot":"","sources":["../../../src/config/env-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAEhC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAG1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IAGxB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;IACnB,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAoDD;;;GAGG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAG5C;AAUD;;;GAGG;AACH,wBAAgB,YAAY,IAAI,iBAAiB,CAsChD;AAsBD;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAMjD;AAOD,kEAAkE;AAClE,eAAO,MAAM,yBAAyB;;;;;;;;;;;CAA0B,CAAC;AAEjE;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,WAAW,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,iBAAiB,IAAI,cAAc,CA2BlD"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* 环境配置管理模块
|
|
3
3
|
* 支持通过 GATE_PAY_ENV 环境变量在 test 和 prd 环境间切换
|
|
4
4
|
*/
|
|
5
|
+
import trackingProductDefaults from "./tracking-product-defaults.json";
|
|
5
6
|
/**
|
|
6
7
|
* 测试环境配置
|
|
7
8
|
*/
|
|
@@ -98,4 +99,49 @@ function parseCallbackPort() {
|
|
|
98
99
|
const n = parseInt(portStr, 10);
|
|
99
100
|
return Number.isNaN(n) ? undefined : n;
|
|
100
101
|
}
|
|
102
|
+
function parsePositiveIntEnv(value) {
|
|
103
|
+
if (!value?.trim())
|
|
104
|
+
return undefined;
|
|
105
|
+
const n = Number(value.trim());
|
|
106
|
+
return Number.isFinite(n) && n > 0 ? n : undefined;
|
|
107
|
+
}
|
|
108
|
+
function getMppBaseChainIdPresetByEnv() {
|
|
109
|
+
return getEnvironment() === "test" ? 84532 : 8453;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* MPP Base session 的 chainId。
|
|
113
|
+
* 优先级:MPP_BASE_CHAIN_ID、BASE_CHAIN_ID > GATE_PAY_ENV 预设(test→84532,prd→8453)
|
|
114
|
+
*/
|
|
115
|
+
export function getMppBaseSessionChainId() {
|
|
116
|
+
return (parsePositiveIntEnv(process.env.MPP_BASE_CHAIN_ID) ??
|
|
117
|
+
parsePositiveIntEnv(process.env.BASE_CHAIN_ID) ??
|
|
118
|
+
getMppBaseChainIdPresetByEnv());
|
|
119
|
+
}
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// 火山 / Gate 埋点(DataFinder HTTP):固定产品维度 + 环境可覆盖项
|
|
122
|
+
// 默认值见 tracking-product-defaults.json(脚本 volc-tracking-ping.mjs 同步读取该 JSON)
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
/** 埋点侧「与本 MCP 进程绑定」的固定维度;含默认上报 App Key(见 JSON `defaultAppKey`) */
|
|
125
|
+
export const TRACKING_PRODUCT_DEFAULTS = trackingProductDefaults;
|
|
126
|
+
export function getTrackingConfig() {
|
|
127
|
+
const appKey = process.env.VOLC_TRACKING_APP_KEY?.trim() || trackingProductDefaults.defaultAppKey;
|
|
128
|
+
const enabled = process.env.VOLC_TRACKING_ENABLED?.trim().toLowerCase() !== "false";
|
|
129
|
+
const appId = parsePositiveIntEnv(process.env.VOLC_TRACKING_APP_ID) ??
|
|
130
|
+
trackingProductDefaults.defaultAppId;
|
|
131
|
+
const reportHost = process.env.VOLC_TRACKING_HOST?.trim() || trackingProductDefaults.defaultReportHost;
|
|
132
|
+
return {
|
|
133
|
+
enabled,
|
|
134
|
+
reportHost,
|
|
135
|
+
appId,
|
|
136
|
+
appKey,
|
|
137
|
+
gatePayEnv: getEnvironment(),
|
|
138
|
+
appName: trackingProductDefaults.appName,
|
|
139
|
+
appPlatform: trackingProductDefaults.appPlatform,
|
|
140
|
+
accessMethod: trackingProductDefaults.accessMethod,
|
|
141
|
+
clientType: trackingProductDefaults.clientType,
|
|
142
|
+
businessModule: trackingProductDefaults.businessModule,
|
|
143
|
+
productLine: trackingProductDefaults.productLine,
|
|
144
|
+
eventName: trackingProductDefaults.eventName,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
101
147
|
//# sourceMappingURL=env-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-config.js","sourceRoot":"","sources":["../../../src/config/env-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"env-config.js","sourceRoot":"","sources":["../../../src/config/env-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,uBAAuB,MAAM,kCAAkC,CAAC;AA4BvE;;GAEG;AACH,MAAM,WAAW,GAAsB;IACrC,WAAW;IACX,aAAa,EAAE,kBAAkB;IACjC,iBAAiB,EAAE,8CAA8C;IACjE,kBAAkB,EAAE,iCAAiC;IACrD,sBAAsB,EAAE,2BAA2B;IACnD,iBAAiB,EAAE,KAAK;IAExB,QAAQ;IACR,qBAAqB,EAAE,8EAA8E;IACrG,eAAe,EAAE,kBAAkB;IAEnC,OAAO;IACP,oBAAoB,EAAE,iDAAiD;IACvE,SAAS,EAAE,qDAAqD;IAChE,qBAAqB,EAAE,wCAAwC;IAE/D,OAAO;IACP,UAAU,EAAE,cAAc;IAC1B,uBAAuB,EAAE,YAAY;CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,GAAsB;IACpC,WAAW;IACX,aAAa,EAAE,kBAAkB;IACjC,iBAAiB,EAAE,8CAA8C;IACjE,kBAAkB,EAAE,wCAAwC;IAC5D,sBAAsB,EAAE,kBAAkB;IAC1C,iBAAiB,EAAE,KAAK;IAExB,QAAQ;IACR,qBAAqB,EAAE,+CAA+C;IACtE,eAAe,EAAE,kBAAkB;IAEnC,OAAO;IACP,oBAAoB,EAAE,gCAAgC;IACtD,qBAAqB,EAAE,gCAAgC;IACvD,SAAS,EAAE,mDAAmD;IAE9D,OAAO;IACP,UAAU,EAAE,cAAc;IAC1B,uBAAuB,EAAE,YAAY;CACtC,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;I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+
* 未配置时回退为原始 `toolName`,避免上报空串。
|
|
4
|
+
*/
|
|
5
|
+
export declare function getToolDisplayName(toolName: string): string;
|
|
6
|
+
/** 供文档 / 测试枚举全部已登记工具名 */
|
|
7
|
+
export declare function listTrackedToolNames(): string[];
|
|
8
|
+
//# sourceMappingURL=tool-display-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-display-names.d.ts","sourceRoot":"","sources":["../../../src/config/tool-display-names.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED,yBAAyB;AACzB,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAE/C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import toolDisplayNames from "./tool-display-names.json";
|
|
2
|
+
const TABLE = toolDisplayNames;
|
|
3
|
+
/**
|
|
4
|
+
* MCP 工具英文名 → 中文展示名(埋点 `tool_name_cn`)。
|
|
5
|
+
* 未配置时回退为原始 `toolName`,避免上报空串。
|
|
6
|
+
*/
|
|
7
|
+
export function getToolDisplayName(toolName) {
|
|
8
|
+
const v = TABLE[toolName];
|
|
9
|
+
return typeof v === "string" && v.trim() !== "" ? v : toolName;
|
|
10
|
+
}
|
|
11
|
+
/** 供文档 / 测试枚举全部已登记工具名 */
|
|
12
|
+
export function listTrackedToolNames() {
|
|
13
|
+
return Object.keys(TABLE);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=tool-display-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-display-names.js","sourceRoot":"","sources":["../../../src/config/tool-display-names.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,2BAA2B,CAAC;AAEzD,MAAM,KAAK,GAAG,gBAA0C,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AACjE,CAAC;AAED,yBAAyB;AACzB,MAAM,UAAU,oBAAoB;IAClC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"x402_place_order": "x402 下单探测(无自动签名)",
|
|
3
|
+
"x402_sign_payment": "x402 签名并支付",
|
|
4
|
+
"mpp_init_session": "MPP 初始化会话",
|
|
5
|
+
"mpp_fetch": "MPP 发起 HTTP 请求",
|
|
6
|
+
"mpp_close_session": "MPP 关闭会话",
|
|
7
|
+
"mpp_request_close": "MPP 链上请求关闭通道",
|
|
8
|
+
"mpp_withdraw": "MPP 链上提现",
|
|
9
|
+
"x402_create_signature": "x402 创建支付签名",
|
|
10
|
+
"x402_submit_payment": "x402 提交支付",
|
|
11
|
+
"x402_gate_pay_auth": "Gate Pay 授权登录",
|
|
12
|
+
"x402_quick_wallet_auth": "快捷钱包授权登录",
|
|
13
|
+
"x402_centralized_payment": "Gate Pay 中心化支付",
|
|
14
|
+
"x402_request": "x402 一站式请求(兼容旧版)"
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"defaultReportHost": "snssdk.gatedata.org",
|
|
3
|
+
"defaultAppId": 10000001,
|
|
4
|
+
"defaultAppKey": "dd447b6237008363f06bd97bbd4a27e0",
|
|
5
|
+
"appName": "gatepay_local_mcp",
|
|
6
|
+
"appPlatform": "server",
|
|
7
|
+
"accessMethod": "MCP",
|
|
8
|
+
"clientType": "gatepay-local-mcp",
|
|
9
|
+
"businessModule": "Pay",
|
|
10
|
+
"productLine": "LOCAL MCP",
|
|
11
|
+
"eventName": "mcp_tool_call"
|
|
12
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pay-token-store.d.ts","sourceRoot":"","sources":["../../../src/gate-pay/pay-token-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"pay-token-store.d.ts","sourceRoot":"","sources":["../../../src/gate-pay/pay-token-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,EAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,EAC5B,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI;AACvC,gDAAgD;AAChD,MAAM,CAAC,EAAE,MAAM,GACd,IAAI,CAqBN;AAiFD;;;GAGG;AACH,wBAAgB,6BAA6B,IAAI,OAAO,CAAC,OAAO,CAAC,CAMhE;AAED,wBAAgB,oBAAoB,IAAI,OAAO,CAG9C;AAED,wBAAgB,qBAAqB,IAAI,MAAM,GAAG,IAAI,CAGrD;AAED,sCAAsC;AACtC,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAGhD;AAED,wBAAgB,uBAAuB,IAAI,IAAI,CAQ9C"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { GATE_DEFAULT_CONFIG, gateOAuthConfigFromEnv, } from "./gate-oauth-config.js";
|
|
6
6
|
import { GateOAuth } from "./gate-oauth-class.js";
|
|
7
|
+
import { recordTrackingGateUid, clearTrackingGateUidSticky, } from "../tracking/tracking-invocation-context.js";
|
|
7
8
|
const EXPIRY_SKEW_MS = 60000;
|
|
8
9
|
/** 接口未返回 access 过期时间时,自签发起默认有效时长 */
|
|
9
10
|
const ACCESS_TOKEN_TTL_MS = 60 * 60 * 1000;
|
|
@@ -32,6 +33,12 @@ userId) {
|
|
|
32
33
|
}
|
|
33
34
|
if (userId !== undefined) {
|
|
34
35
|
gatePayUserId = userId.length > 0 ? userId : null;
|
|
36
|
+
if (userId.length > 0) {
|
|
37
|
+
recordTrackingGateUid(userId);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
clearTrackingGateUidSticky();
|
|
41
|
+
}
|
|
35
42
|
}
|
|
36
43
|
}
|
|
37
44
|
function effectiveExpiresAtMs() {
|
|
@@ -130,5 +137,6 @@ export function clearGatePayAccessToken() {
|
|
|
130
137
|
gatePayRefreshTokenExpiresAtMs = null;
|
|
131
138
|
gatePayTokenExpiresAtMs = null;
|
|
132
139
|
gatePayTokenIssuedAtMs = null;
|
|
140
|
+
clearTrackingGateUidSticky();
|
|
133
141
|
}
|
|
134
142
|
//# sourceMappingURL=pay-token-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pay-token-store.js","sourceRoot":"","sources":["../../../src/gate-pay/pay-token-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"pay-token-store.js","sourceRoot":"","sources":["../../../src/gate-pay/pay-token-store.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EACL,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,4CAA4C,CAAC;AAEpD,MAAM,cAAc,GAAG,KAAM,CAAC;AAC9B,oCAAoC;AACpC,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3C,IAAI,kBAAkB,GAAkB,IAAI,CAAC;AAC7C,0EAA0E;AAC1E,IAAI,aAAa,GAAkB,IAAI,CAAC;AACxC,IAAI,mBAAmB,GAAkB,IAAI,CA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CAAC;AACrC,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,mBAAmB,EAAE,CAAC;IACtB,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,gBAAgB;IAC9B,mBAAmB,EAAE,CAAC;IACtB,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,kBAAkB,GAAG,IAAI,CAAC;IAC1B,aAAa,GAAG,IAAI,CAAC;IACrB,mBAAmB,GAAG,IAAI,CAAC;IAC3B,8BAA8B,GAAG,IAAI,CAAC;IACtC,uBAAuB,GAAG,IAAI,CAAC;IAC/B,sBAAsB,GAAG,IAAI,CAAC;IAC9B,0BAA0B,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -14,7 +14,9 @@ import { LocalPrivateKeyMode } from "./modes/local-private-key.js";
|
|
|
14
14
|
import { PluginWalletMode } from "./modes/plugin-wallet.js";
|
|
15
15
|
import { createSignModeRegistry } from "./modes/registry.js";
|
|
16
16
|
import { QuickWalletMode } from "./modes/quick-wallet.js";
|
|
17
|
-
import { getPublicTools, handlePlaceOrder, handleSignPayment, handleCreateSignature, handleSubmitPayment, handleGatePayAuth, handleQuickWalletAuth, handleX402Request, handleCentralizedPayment, } from "./tools/index.js";
|
|
17
|
+
import { getPublicTools, handlePlaceOrder, handleSignPayment, handleMppInitSession, handleMppFetch, handleMppCloseSession, handleMppRequestClose, handleMppWithdraw, handleCreateSignature, handleSubmitPayment, handleGatePayAuth, handleQuickWalletAuth, handleX402Request, handleCentralizedPayment, } from "./tools/index.js";
|
|
18
|
+
import { withTracking } from "./tracking/with-tracking.js";
|
|
19
|
+
import { getTracker } from "./tracking/tracker.js";
|
|
18
20
|
import { createErrorResponse } from "./utils/response-helpers.js";
|
|
19
21
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
22
|
function findPackageRoot(startDir) {
|
|
@@ -54,36 +56,55 @@ async function main() {
|
|
|
54
56
|
}));
|
|
55
57
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
56
58
|
const { name, arguments: args } = request.params;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
59
|
+
return await withTracking(name, args, async () => {
|
|
60
|
+
if (name === "x402_place_order") {
|
|
61
|
+
return await handlePlaceOrder(args ?? {});
|
|
62
|
+
}
|
|
63
|
+
if (name === "x402_sign_payment") {
|
|
64
|
+
return await handleSignPayment(args ?? {}, signModeRegistry);
|
|
65
|
+
}
|
|
66
|
+
if (name === "mpp_init_session") {
|
|
67
|
+
return await handleMppInitSession(args ?? {});
|
|
68
|
+
}
|
|
69
|
+
if (name === "mpp_fetch") {
|
|
70
|
+
return await handleMppFetch(args ?? {});
|
|
71
|
+
}
|
|
72
|
+
if (name === "mpp_close_session") {
|
|
73
|
+
return await handleMppCloseSession(args ?? {});
|
|
74
|
+
}
|
|
75
|
+
if (name === "mpp_request_close") {
|
|
76
|
+
return await handleMppRequestClose(args ?? {});
|
|
77
|
+
}
|
|
78
|
+
if (name === "mpp_withdraw") {
|
|
79
|
+
return await handleMppWithdraw(args ?? {});
|
|
80
|
+
}
|
|
81
|
+
if (name === "x402_create_signature") {
|
|
82
|
+
return await handleCreateSignature(args ?? {}, signModeRegistry);
|
|
83
|
+
}
|
|
84
|
+
if (name === "x402_submit_payment") {
|
|
85
|
+
return await handleSubmitPayment(args ?? {});
|
|
86
|
+
}
|
|
87
|
+
if (name === "x402_gate_pay_auth") {
|
|
88
|
+
return await handleGatePayAuth();
|
|
89
|
+
}
|
|
90
|
+
if (name === "x402_quick_wallet_auth") {
|
|
91
|
+
return await handleQuickWalletAuth(args ?? {}, {
|
|
92
|
+
mcpWalletUrl: quickWalletMcpUrl,
|
|
93
|
+
mcpApiKey: quickWalletApiKey,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (name === "x402_centralized_payment") {
|
|
97
|
+
return await handleCentralizedPayment(args ?? {});
|
|
98
|
+
}
|
|
99
|
+
// Keep x402_request handler for backward compatibility (not exposed in ListTools)
|
|
100
|
+
if (name === "x402_request") {
|
|
101
|
+
return await handleX402Request(args ?? {}, signModeRegistry);
|
|
102
|
+
}
|
|
103
|
+
return createErrorResponse(`未知工具: ${name}`);
|
|
104
|
+
});
|
|
86
105
|
});
|
|
106
|
+
// 初始化埋点上报(注册退出钩子 + 定时器)
|
|
107
|
+
getTracker();
|
|
87
108
|
const stdio = new StdioServerTransport();
|
|
88
109
|
await server.connect(stdio);
|
|
89
110
|
}
|