@hpp-io/x402-mcp-bridge 0.0.2 → 0.1.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 +146 -123
- package/bin/hpp-x402.js +5 -0
- package/dist/a2a.d.ts +2 -2
- package/dist/a2a.js +14 -6
- package/dist/a2a.js.map +1 -1
- package/dist/autoTopup.d.ts +4 -1
- package/dist/autoTopup.js +4 -0
- package/dist/autoTopup.js.map +1 -1
- package/dist/cli/channel.d.ts +1 -1
- package/dist/cli/channel.js +1 -8
- package/dist/cli/channel.js.map +1 -1
- package/dist/cli/hpp-x402.d.ts +2 -0
- package/dist/cli/hpp-x402.js +377 -0
- package/dist/cli/hpp-x402.js.map +1 -0
- package/dist/cli/install-claude-code.d.ts +24 -0
- package/dist/cli/install-claude-code.js +50 -0
- package/dist/cli/install-claude-code.js.map +1 -0
- package/dist/cli/install-cursor.d.ts +7 -0
- package/dist/cli/install-cursor.js +26 -0
- package/dist/cli/install-cursor.js.map +1 -0
- package/dist/cli/install-mcp-host.d.ts +2 -2
- package/dist/cli/install-mcp-host.js.map +1 -1
- package/dist/cli/install-windsurf.d.ts +7 -0
- package/dist/cli/install-windsurf.js +37 -0
- package/dist/cli/install-windsurf.js.map +1 -0
- package/dist/cli/policy.d.ts +1 -1
- package/dist/cli/policy.js +1 -8
- package/dist/cli/policy.js.map +1 -1
- package/dist/cli/revoke.d.ts +1 -1
- package/dist/cli/revoke.js +1 -5
- package/dist/cli/revoke.js.map +1 -1
- package/dist/cli/safe.d.ts +62 -62
- package/dist/cli/serve.d.ts +1 -0
- package/dist/cli/serve.js +128 -0
- package/dist/cli/serve.js.map +1 -0
- package/dist/cli/setup.d.ts +1 -1
- package/dist/cli/setup.js +1 -5
- package/dist/cli/setup.js.map +1 -1
- package/dist/client.d.ts +6 -2
- package/dist/client.js +34 -15
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +71 -15
- package/dist/config.js +66 -10
- package/dist/config.js.map +1 -1
- package/dist/discovery.d.ts +43 -0
- package/dist/discovery.js +62 -0
- package/dist/discovery.js.map +1 -0
- package/dist/discoveryTools.d.ts +75 -0
- package/dist/discoveryTools.js +101 -0
- package/dist/discoveryTools.js.map +1 -0
- package/dist/funds/direct-balance.d.ts +28 -0
- package/dist/funds/direct-balance.js +61 -0
- package/dist/funds/direct-balance.js.map +1 -0
- package/dist/funds.d.ts +32 -0
- package/dist/funds.js +2 -0
- package/dist/funds.js.map +1 -0
- package/dist/httpX402.d.ts +8 -2
- package/dist/httpX402.js +26 -13
- package/dist/httpX402.js.map +1 -1
- package/dist/index.js +66 -11
- package/dist/index.js.map +1 -1
- package/dist/sellerTools.d.ts +247 -0
- package/dist/sellerTools.js +202 -0
- package/dist/sellerTools.js.map +1 -0
- package/dist/server.d.ts +8 -2
- package/dist/server.js +165 -64
- package/dist/server.js.map +1 -1
- package/dist/spendGuard.d.ts +24 -0
- package/dist/spendGuard.js +124 -0
- package/dist/spendGuard.js.map +1 -0
- package/package.json +13 -12
- package/bin/hpp-x402-channel.js +0 -5
- package/bin/hpp-x402-keychain.js +0 -5
- package/bin/hpp-x402-policy.js +0 -5
- package/bin/hpp-x402-safe-revoke.js +0 -5
- package/bin/hpp-x402-safe-setup.js +0 -5
- package/dist/autoSettlePickup.d.ts +0 -69
- package/dist/autoSettlePickup.js +0 -150
- package/dist/autoSettlePickup.js.map +0 -1
- package/dist/cli/keychain.d.ts +0 -1
- package/dist/cli/keychain.js +0 -147
- package/dist/cli/keychain.js.map +0 -1
package/dist/server.js
CHANGED
|
@@ -14,17 +14,63 @@
|
|
|
14
14
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
15
15
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
16
16
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
17
|
-
import { parseComputeResultText, startAutoSettlePoller, } from "./autoSettlePickup.js";
|
|
18
17
|
import { PAY_A2A_TOOL, payA2aAgent } from "./a2a.js";
|
|
19
18
|
import { X402_HTTP_TOOL, x402HttpCall } from "./httpX402.js";
|
|
19
|
+
import { HPP_DISCOVER_TOOL, HPP_CALL_TOOL, hppDiscover, hppCall, } from "./discoveryTools.js";
|
|
20
|
+
import { SELLER_TOOLS, SELLER_CREATE_REQUIREMENTS_TOOL, SELLER_GENERATE_402_TOOL, SELLER_DECODE_PAYMENT_TOOL, SELLER_VERIFY_TOOL, SELLER_SETTLE_TOOL, sellerCreateRequirements, sellerGenerate402, sellerDecodePayment, sellerVerify, sellerSettle, } from "./sellerTools.js";
|
|
21
|
+
import { walletSpendStatus, setWalletLimits } from "./spendGuard.js";
|
|
20
22
|
import { log } from "./log.js";
|
|
23
|
+
const WALLET_GET_LIMITS_TOOL = {
|
|
24
|
+
name: "wallet_get_limits",
|
|
25
|
+
description: "Show the wallet's spend limits (per-call + per-day in atomic USDC.e units) " +
|
|
26
|
+
"and how much has been spent today. Empty limits = uncapped.",
|
|
27
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
28
|
+
};
|
|
29
|
+
const WALLET_SET_LIMIT_TOOL = {
|
|
30
|
+
name: "wallet_set_limit",
|
|
31
|
+
description: "Set the wallet's spend guard: a per-call cap and/or a per-day cap in atomic " +
|
|
32
|
+
"USDC.e units (e.g. '10000' = 0.01 USDC.e). These bind across ALL payment " +
|
|
33
|
+
"tools and are enforced locally before signing (complements the Safe's " +
|
|
34
|
+
"on-chain cap). Omit a field to leave it unchanged.",
|
|
35
|
+
inputSchema: {
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: {
|
|
38
|
+
maxPerCallAtomic: { type: "string", description: "Max atomic units per single payment." },
|
|
39
|
+
maxPerDayAtomic: { type: "string", description: "Max atomic units per UTC day (all tools combined)." },
|
|
40
|
+
},
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const WALLET_BALANCE_TOOL = {
|
|
45
|
+
name: "wallet_balance",
|
|
46
|
+
description: "Show the wallet's current USDC.e balance — what it can spend right now. In " +
|
|
47
|
+
"Safe mode this is the delegate's immediately-spendable balance (the Safe " +
|
|
48
|
+
"tops up more on demand).",
|
|
49
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
50
|
+
};
|
|
51
|
+
const WALLET_ADDRESS_TOOL = {
|
|
52
|
+
name: "wallet_address",
|
|
53
|
+
description: "Return this agent's own wallet address (to receive/fund USDC.e) and its " +
|
|
54
|
+
"network. Use when the user asks 'what's my address' or where to send funds.",
|
|
55
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
56
|
+
};
|
|
21
57
|
export async function startBridgeServer(opts) {
|
|
22
58
|
const server = new Server({ name: opts.name, version: opts.version }, { capabilities: { tools: {} } });
|
|
23
59
|
// ---- listTools — upstream tools (if any) + local tools --------------
|
|
24
60
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
25
61
|
const upstreamTools = opts.upstream ? await opts.upstream.base.listTools() : { tools: [] };
|
|
26
|
-
|
|
27
|
-
|
|
62
|
+
const localTools = [
|
|
63
|
+
WALLET_ADDRESS_TOOL,
|
|
64
|
+
WALLET_BALANCE_TOOL,
|
|
65
|
+
WALLET_GET_LIMITS_TOOL,
|
|
66
|
+
WALLET_SET_LIMIT_TOOL,
|
|
67
|
+
PAY_A2A_TOOL,
|
|
68
|
+
X402_HTTP_TOOL,
|
|
69
|
+
...(opts.discovery ? [HPP_DISCOVER_TOOL, HPP_CALL_TOOL] : []),
|
|
70
|
+
...(opts.seller ? SELLER_TOOLS : []),
|
|
71
|
+
];
|
|
72
|
+
log.debug("listTools", { count: upstreamTools.tools.length + localTools.length });
|
|
73
|
+
return { tools: [...upstreamTools.tools, ...localTools] };
|
|
28
74
|
});
|
|
29
75
|
// ---- callTool — forward through x402-aware wrapper ------------------
|
|
30
76
|
//
|
|
@@ -43,13 +89,81 @@ export async function startBridgeServer(opts) {
|
|
|
43
89
|
server.setRequestHandler(CallToolRequestSchema, async (req, extra) => {
|
|
44
90
|
const { name, arguments: args } = req.params;
|
|
45
91
|
log.info("callTool.start", { name });
|
|
92
|
+
// Local tool: report our own wallet address (for funding).
|
|
93
|
+
if (name === WALLET_ADDRESS_TOOL.name) {
|
|
94
|
+
const address = opts.signer.address;
|
|
95
|
+
return {
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: "text",
|
|
99
|
+
text: JSON.stringify({
|
|
100
|
+
address,
|
|
101
|
+
network: opts.network,
|
|
102
|
+
fund: `Send USDC.e to ${address} on ${opts.network} — no native gas needed (gasless settlement).`,
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Local tool: read the wallet's current USDC.e balance.
|
|
109
|
+
if (name === WALLET_BALANCE_TOOL.name) {
|
|
110
|
+
if (!opts.funds) {
|
|
111
|
+
return { content: [{ type: "text", text: "no funds source configured" }], isError: true };
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const atomic = await opts.funds.balance();
|
|
115
|
+
const s = atomic.toString().padStart(7, "0");
|
|
116
|
+
const usdce = `${s.slice(0, -6)}.${s.slice(-6)}`;
|
|
117
|
+
return {
|
|
118
|
+
content: [
|
|
119
|
+
{
|
|
120
|
+
type: "text",
|
|
121
|
+
text: JSON.stringify({
|
|
122
|
+
address: opts.signer.address,
|
|
123
|
+
balanceAtomic: atomic.toString(),
|
|
124
|
+
balanceUsdce: usdce,
|
|
125
|
+
network: opts.network,
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
133
|
+
return { content: [{ type: "text", text: `wallet_balance error: ${msg}` }], isError: true };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Local tool: read the wallet's spend limits + today's usage.
|
|
137
|
+
if (name === WALLET_GET_LIMITS_TOOL.name) {
|
|
138
|
+
return { content: [{ type: "text", text: JSON.stringify(walletSpendStatus()) }] };
|
|
139
|
+
}
|
|
140
|
+
// Local tool: set the wallet's per-call / per-day spend caps.
|
|
141
|
+
if (name === WALLET_SET_LIMIT_TOOL.name) {
|
|
142
|
+
const a = (args ?? {});
|
|
143
|
+
const DIGITS = /^\d+$/;
|
|
144
|
+
const next = {};
|
|
145
|
+
for (const k of ["maxPerCallAtomic", "maxPerDayAtomic"]) {
|
|
146
|
+
const v = a[k];
|
|
147
|
+
if (v === undefined)
|
|
148
|
+
continue;
|
|
149
|
+
if (typeof v !== "string" || !DIGITS.test(v)) {
|
|
150
|
+
return { content: [{ type: "text", text: `${k} must be a decimal atomic-units string` }], isError: true };
|
|
151
|
+
}
|
|
152
|
+
next[k] = v;
|
|
153
|
+
}
|
|
154
|
+
if (next.maxPerCallAtomic === undefined && next.maxPerDayAtomic === undefined) {
|
|
155
|
+
return { content: [{ type: "text", text: "provide maxPerCallAtomic and/or maxPerDayAtomic" }], isError: true };
|
|
156
|
+
}
|
|
157
|
+
setWalletLimits(next);
|
|
158
|
+
return { content: [{ type: "text", text: JSON.stringify({ updated: true, ...walletSpendStatus() }) }] };
|
|
159
|
+
}
|
|
46
160
|
// Local tool: pay an external A2A agent (not an upstream MCP tool).
|
|
47
161
|
if (name === PAY_A2A_TOOL.name) {
|
|
48
162
|
try {
|
|
49
163
|
return await payA2aAgent({
|
|
50
164
|
signer: opts.signer,
|
|
51
165
|
network: opts.network,
|
|
52
|
-
|
|
166
|
+
funds: opts.funds,
|
|
53
167
|
rpcTimeoutMs: opts.a2aRpcTimeoutMs,
|
|
54
168
|
}, (args ?? {}));
|
|
55
169
|
}
|
|
@@ -67,7 +181,7 @@ export async function startBridgeServer(opts) {
|
|
|
67
181
|
return await x402HttpCall({
|
|
68
182
|
signer: opts.signer,
|
|
69
183
|
network: opts.network,
|
|
70
|
-
|
|
184
|
+
funds: opts.funds,
|
|
71
185
|
}, (args ?? {}));
|
|
72
186
|
}
|
|
73
187
|
catch (err) {
|
|
@@ -76,6 +190,52 @@ export async function startBridgeServer(opts) {
|
|
|
76
190
|
return { content: [{ type: "text", text: `x402_http_call error: ${msg}` }], isError: true };
|
|
77
191
|
}
|
|
78
192
|
}
|
|
193
|
+
// Local tool: discover curated x402 services (read-only, no payment).
|
|
194
|
+
if (opts.discovery && name === HPP_DISCOVER_TOOL.name) {
|
|
195
|
+
try {
|
|
196
|
+
return await hppDiscover(opts.discovery, (args ?? {}));
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
200
|
+
log.error("hpp_discover.failed", { err: msg });
|
|
201
|
+
return { content: [{ type: "text", text: `hpp_discover error: ${msg}` }], isError: true };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Local tool: call a discovered service by id (payment via our wallet).
|
|
205
|
+
if (opts.discovery && name === HPP_CALL_TOOL.name) {
|
|
206
|
+
try {
|
|
207
|
+
return await hppCall({ signer: opts.signer, network: opts.network, funds: opts.funds }, opts.discovery, (args ?? {}));
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
211
|
+
log.error("hpp_call.failed", { err: msg });
|
|
212
|
+
return { content: [{ type: "text", text: `hpp_call error: ${msg}` }], isError: true };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Local tools: seller building blocks (charge others over x402).
|
|
216
|
+
if (opts.seller && name.startsWith("seller_")) {
|
|
217
|
+
const s = opts.seller;
|
|
218
|
+
const a = (args ?? {});
|
|
219
|
+
try {
|
|
220
|
+
switch (name) {
|
|
221
|
+
case SELLER_CREATE_REQUIREMENTS_TOOL.name:
|
|
222
|
+
return sellerCreateRequirements(s, a);
|
|
223
|
+
case SELLER_GENERATE_402_TOOL.name:
|
|
224
|
+
return sellerGenerate402(a);
|
|
225
|
+
case SELLER_DECODE_PAYMENT_TOOL.name:
|
|
226
|
+
return sellerDecodePayment(a);
|
|
227
|
+
case SELLER_VERIFY_TOOL.name:
|
|
228
|
+
return await sellerVerify(s, a);
|
|
229
|
+
case SELLER_SETTLE_TOOL.name:
|
|
230
|
+
return await sellerSettle(s, a);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
235
|
+
log.error(`${name}.failed`, { err: msg });
|
|
236
|
+
return { content: [{ type: "text", text: `${name} error: ${msg}` }], isError: true };
|
|
237
|
+
}
|
|
238
|
+
}
|
|
79
239
|
// Beyond the local tools above, everything is an upstream resource-server
|
|
80
240
|
// tool. In local-tools-only mode there's no upstream to forward to.
|
|
81
241
|
if (!opts.upstream) {
|
|
@@ -118,22 +278,6 @@ export async function startBridgeServer(opts) {
|
|
|
118
278
|
const result = await up.x402.callTool(name, (args ?? {}), upstreamOptions);
|
|
119
279
|
const paymentMade = result.paymentMade ?? false;
|
|
120
280
|
log.info("callTool.done", { name, paymentMade });
|
|
121
|
-
// F-3a auto-refund hook. If the server's inline wait returned
|
|
122
|
-
// status:pending for a paid compute, start a background poller
|
|
123
|
-
// that watches get_compute_result(jobId). On terminal `failed`
|
|
124
|
-
// we fire batchScheme.refund() so the buyer recovers funds
|
|
125
|
-
// without manual intervention.
|
|
126
|
-
// Skip silently when:
|
|
127
|
-
// - this wasn't a paid compute tool (name doesn't start with compute_)
|
|
128
|
-
// - payment didn't actually happen this turn (already in channel cache)
|
|
129
|
-
// - response isn't the pending shape (server returned an actual
|
|
130
|
-
// result inline, or some non-JSON text like "hello world ...")
|
|
131
|
-
// - we don't have a channelId to act on
|
|
132
|
-
// - the payment scheme wasn't batch-settlement (exact settles on
|
|
133
|
-
// the first response so the buyer already has its PAYMENT-RESPONSE)
|
|
134
|
-
if (paymentMade && name.startsWith("compute_")) {
|
|
135
|
-
maybeStartAutoSettlePoller(up, result, name);
|
|
136
|
-
}
|
|
137
281
|
// Strip bridge-internal fields (paymentMade, paymentResponse) before
|
|
138
282
|
// returning to host — they're not part of the MCP CallToolResult shape.
|
|
139
283
|
return {
|
|
@@ -154,47 +298,4 @@ export async function startBridgeServer(opts) {
|
|
|
154
298
|
await server.connect(transport);
|
|
155
299
|
log.info("bridge.ready");
|
|
156
300
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Inspect a freshly-returned paid compute result. If the server
|
|
159
|
-
* reported `status: "pending"` (its inline-wait timed out) AND the
|
|
160
|
-
* payment used batch-settlement, kick off the background poller so
|
|
161
|
-
* the eventual result-poll picks up the PAYMENT-RESPONSE and updates
|
|
162
|
-
* the buyer's local cumulative. All failure paths are silent
|
|
163
|
-
* best-effort, never throwing into the caller.
|
|
164
|
-
*
|
|
165
|
-
* Deferred-settle replaces F-3a: the server never settles the pending
|
|
166
|
-
* voucher, so failed compute leaves the buyer's budget intact and
|
|
167
|
-
* there's nothing to refund. The poller now only applies settle when
|
|
168
|
-
* the compute succeeds and the server attaches PAYMENT-RESPONSE.
|
|
169
|
-
*/
|
|
170
|
-
function maybeStartAutoSettlePoller(upstream, result, toolName) {
|
|
171
|
-
const content = result.content;
|
|
172
|
-
const text = content?.[0]?.type === "text" ? content[0]?.text : undefined;
|
|
173
|
-
if (!text)
|
|
174
|
-
return;
|
|
175
|
-
const parsed = parseComputeResultText(text);
|
|
176
|
-
if (parsed?.status !== "pending" || !parsed.jobId)
|
|
177
|
-
return;
|
|
178
|
-
const payResp = result.paymentResponse;
|
|
179
|
-
const schemeName = payResp?.scheme;
|
|
180
|
-
const channelId = payResp?.extra?.channelState?.channelId;
|
|
181
|
-
if (schemeName !== "batch-settlement" || !channelId) {
|
|
182
|
-
log.debug("autoSettle.skipped", {
|
|
183
|
-
jobId: parsed.jobId,
|
|
184
|
-
reason: schemeName !== "batch-settlement"
|
|
185
|
-
? "scheme_not_batch_settlement"
|
|
186
|
-
: "no_channel_id",
|
|
187
|
-
scheme: schemeName,
|
|
188
|
-
});
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
startAutoSettlePoller({
|
|
192
|
-
base: upstream.base,
|
|
193
|
-
batchScheme: upstream.batchScheme,
|
|
194
|
-
}, {
|
|
195
|
-
jobId: parsed.jobId,
|
|
196
|
-
channelId,
|
|
197
|
-
toolName,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
301
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAmB,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAqB,MAAM,eAAe,CAAC;AAIhF,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAmB/B,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAyB;IAC/D,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAC1C,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAChC,CAAC;IAEF,wEAAwE;IACxE,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS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oBACP,CAAC;oBACH,CAAC,CAAC,SAAS;aAChB,CAAC;YACF,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CACnC,IAAI,EACJ,CAAC,IAAI,IAAI,EAAE,CAA4B,EACvC,eAAyD,CAC1D,CAAC;YAEF,MAAM,WAAW,GACd,MAAoC,CAAC,WAAW,IAAI,KAAK,CAAC;YAC7D,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;YAEjD,qEAAqE;YACrE,wEAAwE;YACxE,OAAO;gBACL,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC7D,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;YACjD,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,iBAAiB,GAAG,EAAE,EAAE,CAAC;gBAClE,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Wallet-wide atomic units spent so far today (UTC). */
|
|
2
|
+
export declare function spentToday(): bigint;
|
|
3
|
+
/**
|
|
4
|
+
* Returns a human-readable deny reason if paying `amount` would breach the
|
|
5
|
+
* wallet-wide per-call or per-day cap, else null. No-op (null) when no caps set.
|
|
6
|
+
*/
|
|
7
|
+
export declare function checkWalletSpend(amount: bigint): string | null;
|
|
8
|
+
/** Record a *successful* payment against today's wallet-wide total. */
|
|
9
|
+
export declare function recordWalletSpend(amount: bigint): void;
|
|
10
|
+
/**
|
|
11
|
+
* Set the wallet-wide spend limits (persisted to policy._defaults.limits), so
|
|
12
|
+
* the guard enforces them. Omitted fields are left unchanged. Atomic strings.
|
|
13
|
+
*/
|
|
14
|
+
export declare function setWalletLimits(next: {
|
|
15
|
+
maxPerCallAtomic?: string;
|
|
16
|
+
maxPerDayAtomic?: string;
|
|
17
|
+
}): void;
|
|
18
|
+
/** Current limits + today's usage, for `wallet_get_limits` / `status`. */
|
|
19
|
+
export declare function walletSpendStatus(): {
|
|
20
|
+
spentTodayAtomic: string;
|
|
21
|
+
maxPerCallAtomic?: string;
|
|
22
|
+
maxPerDayAtomic?: string;
|
|
23
|
+
remainingTodayAtomic?: string;
|
|
24
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet-wide spend guard — the runaway-agent brake.
|
|
3
|
+
*
|
|
4
|
+
* Enforces two caps *uniformly across every payment path* (x402_http_call,
|
|
5
|
+
* hpp_call, pay_a2a_agent), so no single tool can bypass them:
|
|
6
|
+
* - per-call: a single payment may not exceed `maxPerCallAtomic`
|
|
7
|
+
* - per-day: the wallet's total spend in a UTC day may not exceed
|
|
8
|
+
* `maxPerDayAtomic` (this is the daily "ledger" that policy.ts
|
|
9
|
+
* declared as a follow-up — now implemented)
|
|
10
|
+
*
|
|
11
|
+
* Limits are read from `policy._defaults.limits` (wallet-wide). When unset the
|
|
12
|
+
* guard is a no-op, so existing setups are unaffected — the caps only bite once
|
|
13
|
+
* a user sets them (via `wallet_set_limit` / `hpp-x402 policy defaults`).
|
|
14
|
+
*
|
|
15
|
+
* This is a *soft* guard the bridge enforces before signing: it protects
|
|
16
|
+
* against the agent overspending (misbehaviour / prompt injection), NOT against
|
|
17
|
+
* an attacker with machine access (that's the Safe's on-chain cap). Two
|
|
18
|
+
* complementary layers.
|
|
19
|
+
*
|
|
20
|
+
* The daily ledger lives at `${HPP_X402_HOME|~/.hpp-x402}/ledger.json` and only
|
|
21
|
+
* keeps today + yesterday (rolling).
|
|
22
|
+
*/
|
|
23
|
+
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
24
|
+
import { homedir } from "node:os";
|
|
25
|
+
import { resolve as pathResolve } from "node:path";
|
|
26
|
+
import { loadPolicy, savePolicy } from "./policy.js";
|
|
27
|
+
import { log } from "./log.js";
|
|
28
|
+
function home() {
|
|
29
|
+
return process.env.HPP_X402_HOME ?? pathResolve(homedir(), ".hpp-x402");
|
|
30
|
+
}
|
|
31
|
+
function ledgerPath() {
|
|
32
|
+
return pathResolve(home(), "ledger.json");
|
|
33
|
+
}
|
|
34
|
+
function dayKey(offsetDays = 0) {
|
|
35
|
+
const d = new Date();
|
|
36
|
+
d.setUTCDate(d.getUTCDate() + offsetDays);
|
|
37
|
+
return d.toISOString().slice(0, 10); // UTC yyyy-mm-dd
|
|
38
|
+
}
|
|
39
|
+
function loadLedger() {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(readFileSync(ledgerPath(), "utf-8"));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function saveLedger(l) {
|
|
48
|
+
const keep = new Set([dayKey(0), dayKey(-1)]);
|
|
49
|
+
for (const k of Object.keys(l))
|
|
50
|
+
if (!keep.has(k))
|
|
51
|
+
delete l[k];
|
|
52
|
+
try {
|
|
53
|
+
mkdirSync(home(), { recursive: true });
|
|
54
|
+
writeFileSync(ledgerPath(), JSON.stringify(l), { mode: 0o600 });
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
log.debug("spendGuard.saveFailed", { err: err.message });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function walletLimits() {
|
|
61
|
+
const d = loadPolicy()._defaults?.limits ?? {};
|
|
62
|
+
return {
|
|
63
|
+
maxPerCall: d.maxPerCallAtomic != null ? BigInt(d.maxPerCallAtomic) : undefined,
|
|
64
|
+
maxPerDay: d.maxPerDayAtomic != null ? BigInt(d.maxPerDayAtomic) : undefined,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Wallet-wide atomic units spent so far today (UTC). */
|
|
68
|
+
export function spentToday() {
|
|
69
|
+
return BigInt(loadLedger()[dayKey(0)] ?? "0");
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns a human-readable deny reason if paying `amount` would breach the
|
|
73
|
+
* wallet-wide per-call or per-day cap, else null. No-op (null) when no caps set.
|
|
74
|
+
*/
|
|
75
|
+
export function checkWalletSpend(amount) {
|
|
76
|
+
const { maxPerCall, maxPerDay } = walletLimits();
|
|
77
|
+
if (maxPerCall != null && amount > maxPerCall) {
|
|
78
|
+
return `wallet per-call cap exceeded: ${amount} > ${maxPerCall} atomic. Raise it with wallet_set_limit (or hpp-x402 policy defaults --max-per-call).`;
|
|
79
|
+
}
|
|
80
|
+
if (maxPerDay != null) {
|
|
81
|
+
const after = spentToday() + amount;
|
|
82
|
+
if (after > maxPerDay) {
|
|
83
|
+
return `wallet daily cap exceeded: ${spentToday()} spent + ${amount} = ${after} > ${maxPerDay} atomic today. Resets at UTC midnight; raise with wallet_set_limit.`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/** Record a *successful* payment against today's wallet-wide total. */
|
|
89
|
+
export function recordWalletSpend(amount) {
|
|
90
|
+
if (amount <= 0n)
|
|
91
|
+
return;
|
|
92
|
+
const l = loadLedger();
|
|
93
|
+
l[dayKey(0)] = (BigInt(l[dayKey(0)] ?? "0") + amount).toString();
|
|
94
|
+
saveLedger(l);
|
|
95
|
+
log.debug("spendGuard.recorded", { amount: amount.toString(), spentToday: l[dayKey(0)] });
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Set the wallet-wide spend limits (persisted to policy._defaults.limits), so
|
|
99
|
+
* the guard enforces them. Omitted fields are left unchanged. Atomic strings.
|
|
100
|
+
*/
|
|
101
|
+
export function setWalletLimits(next) {
|
|
102
|
+
const policy = loadPolicy();
|
|
103
|
+
const defaults = policy._defaults ?? {};
|
|
104
|
+
const limits = { ...(defaults.limits ?? {}) };
|
|
105
|
+
if (next.maxPerCallAtomic !== undefined)
|
|
106
|
+
limits.maxPerCallAtomic = next.maxPerCallAtomic;
|
|
107
|
+
if (next.maxPerDayAtomic !== undefined)
|
|
108
|
+
limits.maxPerDayAtomic = next.maxPerDayAtomic;
|
|
109
|
+
policy._defaults = { ...defaults, limits };
|
|
110
|
+
savePolicy(policy);
|
|
111
|
+
log.info("spendGuard.limitsUpdated", { ...limits });
|
|
112
|
+
}
|
|
113
|
+
/** Current limits + today's usage, for `wallet_get_limits` / `status`. */
|
|
114
|
+
export function walletSpendStatus() {
|
|
115
|
+
const { maxPerCall, maxPerDay } = walletLimits();
|
|
116
|
+
const spent = spentToday();
|
|
117
|
+
return {
|
|
118
|
+
spentTodayAtomic: spent.toString(),
|
|
119
|
+
maxPerCallAtomic: maxPerCall?.toString(),
|
|
120
|
+
maxPerDayAtomic: maxPerDay?.toString(),
|
|
121
|
+
remainingTodayAtomic: maxPerDay != null ? (maxPerDay > spent ? (maxPerDay - spent).toString() : "0") : undefined,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=spendGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spendGuard.js","sourceRoot":"","sources":["../src/spendGuard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,OAA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,CAAC;IAC3C,UAAU,CAAC,MAAM,CAAC,CAAC;IACnB,GAAG,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AACtD,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,iBAAiB;IAM/B,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,YAAY,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;IAC3B,OAAO;QACL,gBAAgB,EAAE,KAAK,CAAC,QAAQ,EAAE;QAClC,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAE;QACxC,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE;QACtC,oBAAoB,EAClB,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;KAC7F,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpp-io/x402-mcp-bridge",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "MCP stdio bridge that lets Claude Desktop / OpenClaw / other MCP hosts make x402 payments on HPP — autoTopup from a Safe via AllowanceModule, signs EIP-3009 with a delegate EOA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -8,11 +8,7 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"bin": {
|
|
10
10
|
"x402-mcp-bridge": "bin/x402-mcp-bridge.js",
|
|
11
|
-
"hpp-x402
|
|
12
|
-
"hpp-x402-safe-revoke": "bin/hpp-x402-safe-revoke.js",
|
|
13
|
-
"hpp-x402-keychain": "bin/hpp-x402-keychain.js",
|
|
14
|
-
"hpp-x402-channel": "bin/hpp-x402-channel.js",
|
|
15
|
-
"hpp-x402-policy": "bin/hpp-x402-policy.js"
|
|
11
|
+
"hpp-x402": "bin/hpp-x402.js"
|
|
16
12
|
},
|
|
17
13
|
"files": [
|
|
18
14
|
"dist",
|
|
@@ -27,27 +23,32 @@
|
|
|
27
23
|
"scripts": {
|
|
28
24
|
"build": "tsc",
|
|
29
25
|
"dev": "tsx src/index.ts",
|
|
26
|
+
"test": "vitest run",
|
|
30
27
|
"typecheck": "tsc --noEmit",
|
|
31
28
|
"postinstall": "patch-package || true",
|
|
32
29
|
"prepublishOnly": "npm run typecheck && npm run build"
|
|
33
30
|
},
|
|
34
31
|
"publishConfig": {
|
|
35
|
-
"access": "public"
|
|
36
|
-
"provenance": true
|
|
32
|
+
"access": "public"
|
|
37
33
|
},
|
|
38
34
|
"dependencies": {
|
|
39
35
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
40
36
|
"@napi-rs/keyring": "^1.3.0",
|
|
41
|
-
"@x402/core": "^2.
|
|
42
|
-
"@x402/evm": "^2.
|
|
43
|
-
"@x402/
|
|
37
|
+
"@x402/core": "^2.14.0",
|
|
38
|
+
"@x402/evm": "^2.14.0",
|
|
39
|
+
"@x402/express": "^2.17.0",
|
|
40
|
+
"@x402/mcp": "^2.14.0",
|
|
41
|
+
"commander": "^12.1.0",
|
|
42
|
+
"express": "^4.22.2",
|
|
44
43
|
"viem": "^2.21.54",
|
|
45
44
|
"zod": "^3.23.8"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
47
|
+
"@types/express": "^4.17.25",
|
|
48
48
|
"@types/node": "^20.0.0",
|
|
49
49
|
"patch-package": "^8.0.1",
|
|
50
50
|
"tsx": "^4.0.0",
|
|
51
|
-
"typescript": "^5.4.0"
|
|
51
|
+
"typescript": "^5.4.0",
|
|
52
|
+
"vitest": "^4.1.10"
|
|
52
53
|
}
|
|
53
54
|
}
|
package/bin/hpp-x402-channel.js
DELETED
package/bin/hpp-x402-keychain.js
DELETED
package/bin/hpp-x402-policy.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto settle pickup for the deferred-settle batch-settlement model.
|
|
3
|
-
*
|
|
4
|
-
* Replaces the F-3a auto-refund poller. The server side moved settle
|
|
5
|
-
* out of the inline-pending response into the result poll endpoints
|
|
6
|
-
* (`get_compute_result` for MCP, `GET /paid/jobs/:jobId` for HTTP); the
|
|
7
|
-
* buyer is therefore *not* charged until the result actually arrives.
|
|
8
|
-
* Refund-on-failure is no longer needed — failed compute simply never
|
|
9
|
-
* settles, so the channel state is unchanged.
|
|
10
|
-
*
|
|
11
|
-
* What this poller does:
|
|
12
|
-
*
|
|
13
|
-
* 1. After a paid compute call returns `status: "pending"`, start a
|
|
14
|
-
* background loop that calls `get_compute_result(jobId)` every
|
|
15
|
-
* POLL_INTERVAL_MS.
|
|
16
|
-
* 2. When the response includes a PAYMENT-RESPONSE under
|
|
17
|
-
* `_meta["x402/payment-response"]`, hand it to the batch scheme's
|
|
18
|
-
* `processSettleResponse` so the local `chargedCumulativeAmount`
|
|
19
|
-
* tracks the now-settled cumulative.
|
|
20
|
-
* 3. On terminal `failed`, just exit — the server discarded the
|
|
21
|
-
* pending voucher, so the buyer keeps their full cumulative budget.
|
|
22
|
-
*
|
|
23
|
-
* Spec refs:
|
|
24
|
-
* docs/design/03-BUYER-SDK-SYNC §D — autoSettlePickup contract
|
|
25
|
-
* docs/design/03-BUYER-SDK-SYNC §H — operational envelope (poll
|
|
26
|
-
* interval, max attempts)
|
|
27
|
-
*
|
|
28
|
-
* Opt-out: `HPP_X402_AUTO_POLL=false` (default = on).
|
|
29
|
-
*
|
|
30
|
-
* Exact scheme isn't covered — exact settles on the initial response,
|
|
31
|
-
* so there's nothing left to pick up.
|
|
32
|
-
*/
|
|
33
|
-
import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
34
|
-
import type { BatchSettlementEvmScheme } from "@x402/evm/batch-settlement/client";
|
|
35
|
-
import type { SettleResponse } from "@x402/core/types";
|
|
36
|
-
export interface AutoSettlePickupDeps {
|
|
37
|
-
/** Same upstream MCP client used by the bridge's callTool path. */
|
|
38
|
-
base: Client;
|
|
39
|
-
/** The batch-settlement scheme instance for the buyer's local channel. */
|
|
40
|
-
batchScheme: BatchSettlementEvmScheme;
|
|
41
|
-
}
|
|
42
|
-
export interface AutoSettlePickupContext {
|
|
43
|
-
jobId: string;
|
|
44
|
-
channelId: string;
|
|
45
|
-
/** Compute tool name — for logging only. */
|
|
46
|
-
toolName: string;
|
|
47
|
-
}
|
|
48
|
-
/** Returns true unless the env explicitly opts out. */
|
|
49
|
-
export declare function isAutoPollEnabled(): boolean;
|
|
50
|
-
/** Parsed payload from a compute tool's text content. */
|
|
51
|
-
interface ComputeResultPayload {
|
|
52
|
-
status?: string;
|
|
53
|
-
jobId?: string;
|
|
54
|
-
error?: string;
|
|
55
|
-
}
|
|
56
|
-
export declare function parseComputeResultText(text: string): ComputeResultPayload | null;
|
|
57
|
-
/**
|
|
58
|
-
* Pulls a `SettleResponse` out of an MCP tool result's `_meta`, if
|
|
59
|
-
* present. Returns `undefined` when the server didn't attach one
|
|
60
|
-
* (the result is still pending, or this is a non-batch path).
|
|
61
|
-
*/
|
|
62
|
-
export declare function extractSettleResponse(meta: unknown): SettleResponse | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* Fire-and-forget background poller. Polls until terminal then either
|
|
65
|
-
* applies the settle pickup or just exits on failure. Errors inside
|
|
66
|
-
* the poller never propagate — they're logged and the task ends.
|
|
67
|
-
*/
|
|
68
|
-
export declare function startAutoSettlePoller(deps: AutoSettlePickupDeps, ctx: AutoSettlePickupContext): void;
|
|
69
|
-
export {};
|