@haven_ai/mcp 0.1.34-alpha.0 → 0.1.35-alpha.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 +30 -3
- package/dist/cli.cjs +69 -14
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +69 -14
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +69 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +69 -14
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -220,12 +220,16 @@ var toolSchemas = {
|
|
|
220
220
|
asset: z.enum(["ETH", "USDC"]),
|
|
221
221
|
recipient: z.string().min(1),
|
|
222
222
|
amount: z.string().min(1),
|
|
223
|
+
idempotency_key: z.string().optional(),
|
|
224
|
+
/** Legacy spelling, accepted during the #2366 window. Warns; do not use. */
|
|
223
225
|
idempotencyKey: z.string().optional()
|
|
224
226
|
},
|
|
225
227
|
haven_pay_mcp_tool: {
|
|
226
228
|
merchant_url: z.string().url(),
|
|
227
229
|
tool_name: z.string().min(1),
|
|
228
230
|
arguments: z.record(z.string(), z.unknown()).optional(),
|
|
231
|
+
idempotency_key: z.string().optional(),
|
|
232
|
+
/** Legacy spelling, accepted during the #2366 window. Warns; do not use. */
|
|
229
233
|
idempotencyKey: z.string().optional()
|
|
230
234
|
},
|
|
231
235
|
haven_quote_x402: {
|
|
@@ -233,10 +237,14 @@ var toolSchemas = {
|
|
|
233
237
|
method: z.string().optional(),
|
|
234
238
|
headers: headersSchema,
|
|
235
239
|
body: z.string().optional(),
|
|
240
|
+
idempotency_key: z.string().optional(),
|
|
241
|
+
/** Legacy spelling, accepted during the #2366 window. Warns; do not use. */
|
|
236
242
|
idempotencyKey: z.string().optional()
|
|
237
243
|
},
|
|
238
244
|
haven_pay_x402_quote: {
|
|
239
245
|
quote: z.unknown(),
|
|
246
|
+
idempotency_key: z.string().optional(),
|
|
247
|
+
/** Legacy spelling, accepted during the #2366 window. Warns; do not use. */
|
|
240
248
|
idempotencyKey: z.string().optional()
|
|
241
249
|
},
|
|
242
250
|
haven_pay_x402: {
|
|
@@ -244,6 +252,8 @@ var toolSchemas = {
|
|
|
244
252
|
method: z.string().optional(),
|
|
245
253
|
headers: headersSchema,
|
|
246
254
|
body: z.string().optional(),
|
|
255
|
+
idempotency_key: z.string().optional(),
|
|
256
|
+
/** Legacy spelling, accepted during the #2366 window. Warns; do not use. */
|
|
247
257
|
idempotencyKey: z.string().optional()
|
|
248
258
|
},
|
|
249
259
|
haven_resume_x402_payment: {
|
|
@@ -296,8 +306,10 @@ var toolDescriptions = {
|
|
|
296
306
|
function createToolHandlers(haven) {
|
|
297
307
|
return {
|
|
298
308
|
haven_send: async (input) => {
|
|
309
|
+
const pf = preflight("haven_send", input);
|
|
310
|
+
if ("success" in pf) return pf;
|
|
311
|
+
const { args, warnings } = pf;
|
|
299
312
|
return runTool(async () => {
|
|
300
|
-
const args = objectInput("haven_send", input);
|
|
301
313
|
try {
|
|
302
314
|
const result = await haven.pay({
|
|
303
315
|
token: args.asset,
|
|
@@ -305,7 +317,7 @@ function createToolHandlers(haven) {
|
|
|
305
317
|
to: args.recipient,
|
|
306
318
|
// #1207: was accepted by the schema but silently dropped — now
|
|
307
319
|
// carried to the backend's replay contract.
|
|
308
|
-
idempotencyKey:
|
|
320
|
+
idempotencyKey: args.idempotencyKey
|
|
309
321
|
});
|
|
310
322
|
return {
|
|
311
323
|
payment_id: result.paymentId,
|
|
@@ -329,11 +341,13 @@ function createToolHandlers(haven) {
|
|
|
329
341
|
}
|
|
330
342
|
throw err;
|
|
331
343
|
}
|
|
332
|
-
});
|
|
344
|
+
}, warnings);
|
|
333
345
|
},
|
|
334
346
|
haven_pay_mcp_tool: async (input) => {
|
|
347
|
+
const pf = preflight("haven_pay_mcp_tool", input);
|
|
348
|
+
if ("success" in pf) return pf;
|
|
349
|
+
const { args, warnings } = pf;
|
|
335
350
|
return runTool(async () => {
|
|
336
|
-
const args = objectInput("haven_pay_mcp_tool", input);
|
|
337
351
|
const envelope = buildMcpToolsCallEnvelope(args.tool_name, args.arguments);
|
|
338
352
|
const init = {
|
|
339
353
|
method: "POST",
|
|
@@ -364,18 +378,23 @@ function createToolHandlers(haven) {
|
|
|
364
378
|
merchant_url: merchantUrl,
|
|
365
379
|
...merchantUrl !== args.merchant_url ? { merchant_url_discovered_from: args.merchant_url } : {}
|
|
366
380
|
};
|
|
367
|
-
});
|
|
381
|
+
}, warnings);
|
|
368
382
|
},
|
|
369
383
|
haven_quote_x402: async (input) => {
|
|
370
|
-
const
|
|
384
|
+
const pf = preflight("haven_quote_x402", input);
|
|
385
|
+
if ("success" in pf) return pf;
|
|
386
|
+
const { args, warnings } = pf;
|
|
371
387
|
try {
|
|
372
|
-
|
|
388
|
+
const data = await haven.quoteX402(args.url, requestInit(args), { idempotencyKey: args.idempotencyKey });
|
|
389
|
+
return warnings.length > 0 ? { success: true, data, warnings } : { success: true, data };
|
|
373
390
|
} catch (err) {
|
|
374
391
|
return normalizeError(err);
|
|
375
392
|
}
|
|
376
393
|
},
|
|
377
394
|
haven_pay_x402_quote: async (input) => {
|
|
378
|
-
const
|
|
395
|
+
const pf = preflight("haven_pay_x402_quote", input);
|
|
396
|
+
if ("success" in pf) return pf;
|
|
397
|
+
const { args, warnings } = pf;
|
|
379
398
|
const quote = args.quote;
|
|
380
399
|
if (!quote || typeof quote !== "object") {
|
|
381
400
|
return wrongTool(
|
|
@@ -394,14 +413,16 @@ function createToolHandlers(haven) {
|
|
|
394
413
|
return runTool(async () => {
|
|
395
414
|
const response = await haven.payX402Quote(args.quote, { idempotencyKey: args.idempotencyKey });
|
|
396
415
|
return responsePayload(response);
|
|
397
|
-
});
|
|
416
|
+
}, warnings);
|
|
398
417
|
},
|
|
399
418
|
haven_pay_x402: async (input) => {
|
|
400
|
-
const
|
|
419
|
+
const pf = preflight("haven_pay_x402", input);
|
|
420
|
+
if ("success" in pf) return pf;
|
|
421
|
+
const { args, warnings } = pf;
|
|
401
422
|
return runTool(async () => {
|
|
402
423
|
const response = await haven.fetch(args.url, requestInit(args), { idempotencyKey: args.idempotencyKey });
|
|
403
424
|
return responsePayload(response);
|
|
404
|
-
});
|
|
425
|
+
}, warnings);
|
|
405
426
|
},
|
|
406
427
|
haven_resume_x402_payment: async (input) => {
|
|
407
428
|
const args = objectInput("haven_resume_x402_payment", input);
|
|
@@ -499,6 +520,39 @@ function isPendingApproval(status) {
|
|
|
499
520
|
function wrongTool(code, message, suggested_tool) {
|
|
500
521
|
return { success: false, code, message, suggested_tool };
|
|
501
522
|
}
|
|
523
|
+
function preflight(name, input) {
|
|
524
|
+
let args;
|
|
525
|
+
try {
|
|
526
|
+
args = objectInput(name, input);
|
|
527
|
+
} catch (err) {
|
|
528
|
+
return normalizeError(err);
|
|
529
|
+
}
|
|
530
|
+
const idem = resolveIdempotencyKey(args);
|
|
531
|
+
if ("success" in idem) return idem;
|
|
532
|
+
if (idem.key !== void 0) args = { ...args, idempotencyKey: idem.key };
|
|
533
|
+
return { args, warnings: idem.warnings };
|
|
534
|
+
}
|
|
535
|
+
function resolveIdempotencyKey(args) {
|
|
536
|
+
const modern = typeof args.idempotency_key === "string" ? args.idempotency_key : void 0;
|
|
537
|
+
const legacy = typeof args.idempotencyKey === "string" ? args.idempotencyKey : void 0;
|
|
538
|
+
if (modern !== void 0 && legacy !== void 0 && modern !== legacy) {
|
|
539
|
+
return {
|
|
540
|
+
success: false,
|
|
541
|
+
code: "AMBIGUOUS_IDEMPOTENCY_KEY",
|
|
542
|
+
message: "Both idempotency_key and idempotencyKey were sent with different values. Nothing was contacted or spent. Send exactly one \u2014 idempotency_key is the current spelling; idempotencyKey is deprecated and will be removed."
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
if (modern !== void 0) return { key: modern, warnings: [] };
|
|
546
|
+
if (legacy !== void 0) {
|
|
547
|
+
return {
|
|
548
|
+
key: legacy,
|
|
549
|
+
warnings: [
|
|
550
|
+
"idempotencyKey is deprecated and will be removed in a future release of @haven_ai/mcp. Send idempotency_key instead \u2014 it is the spelling the hosted Haven MCP surface and every other Haven wire contract use."
|
|
551
|
+
]
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return { warnings: [] };
|
|
555
|
+
}
|
|
502
556
|
function buildMcpToolsCallEnvelope(toolName, args) {
|
|
503
557
|
return {
|
|
504
558
|
jsonrpc: "2.0",
|
|
@@ -521,9 +575,10 @@ function requestInit(input) {
|
|
|
521
575
|
body: input.body
|
|
522
576
|
};
|
|
523
577
|
}
|
|
524
|
-
async function runTool(fn) {
|
|
578
|
+
async function runTool(fn, warnings = []) {
|
|
525
579
|
try {
|
|
526
|
-
|
|
580
|
+
const data = await fn();
|
|
581
|
+
return warnings.length > 0 ? { success: true, data, warnings } : { success: true, data };
|
|
527
582
|
} catch (err) {
|
|
528
583
|
return normalizeError(err);
|
|
529
584
|
}
|
|
@@ -794,7 +849,7 @@ async function resolveHavenClient(options = {}) {
|
|
|
794
849
|
return { client, credentials };
|
|
795
850
|
}
|
|
796
851
|
var MCP_NAME = "@haven_ai/mcp";
|
|
797
|
-
var MCP_VERSION = "0.1.
|
|
852
|
+
var MCP_VERSION = "0.1.35-alpha.0";
|
|
798
853
|
var MCP_INSTRUCTIONS = [
|
|
799
854
|
"Haven local MCP server: signs in-process with the delegate key it holds on",
|
|
800
855
|
"this machine \u2014 the key never leaves this process. Call haven_get_agent",
|