x402-agent-pay 2.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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -0
  3. package/SKILL.md +125 -0
  4. package/dist/scripts/generate-pdf.d.ts +6 -0
  5. package/dist/scripts/generate-pdf.d.ts.map +1 -0
  6. package/dist/scripts/generate-pdf.js +179 -0
  7. package/dist/scripts/generate-pdf.js.map +1 -0
  8. package/dist/scripts/x402-fetch.d.ts +7 -0
  9. package/dist/scripts/x402-fetch.d.ts.map +1 -0
  10. package/dist/scripts/x402-fetch.js +162 -0
  11. package/dist/scripts/x402-fetch.js.map +1 -0
  12. package/dist/src/balance.d.ts +29 -0
  13. package/dist/src/balance.d.ts.map +1 -0
  14. package/dist/src/balance.js +94 -0
  15. package/dist/src/balance.js.map +1 -0
  16. package/dist/src/client.d.ts +90 -0
  17. package/dist/src/client.d.ts.map +1 -0
  18. package/dist/src/client.js +235 -0
  19. package/dist/src/client.js.map +1 -0
  20. package/dist/src/config.d.ts +91 -0
  21. package/dist/src/config.d.ts.map +1 -0
  22. package/dist/src/config.js +58 -0
  23. package/dist/src/config.js.map +1 -0
  24. package/dist/src/discovery.d.ts +98 -0
  25. package/dist/src/discovery.d.ts.map +1 -0
  26. package/dist/src/discovery.js +156 -0
  27. package/dist/src/discovery.js.map +1 -0
  28. package/dist/src/facilitator.d.ts +30 -0
  29. package/dist/src/facilitator.d.ts.map +1 -0
  30. package/dist/src/facilitator.js +50 -0
  31. package/dist/src/facilitator.js.map +1 -0
  32. package/dist/src/index.d.ts +19 -0
  33. package/dist/src/index.d.ts.map +1 -0
  34. package/dist/src/index.js +52 -0
  35. package/dist/src/index.js.map +1 -0
  36. package/dist/src/mcp-server.d.ts +16 -0
  37. package/dist/src/mcp-server.d.ts.map +1 -0
  38. package/dist/src/mcp-server.js +268 -0
  39. package/dist/src/mcp-server.js.map +1 -0
  40. package/dist/src/policy.d.ts +73 -0
  41. package/dist/src/policy.d.ts.map +1 -0
  42. package/dist/src/policy.js +271 -0
  43. package/dist/src/policy.js.map +1 -0
  44. package/dist/src/receipts.d.ts +52 -0
  45. package/dist/src/receipts.d.ts.map +1 -0
  46. package/dist/src/receipts.js +134 -0
  47. package/dist/src/receipts.js.map +1 -0
  48. package/mcp.json +41 -0
  49. package/package.json +65 -0
  50. package/registry.json +96 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/discovery.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAiLH,oCAKC;AAKD,4CA6BC;AArKD,gDAAgD;AAChD,MAAM,oBAAoB,GAAG,kFAAkF,CAAC;AAEhH;;;GAGG;AACH,MAAa,gBAAgB;IACnB,WAAW,CAAS;IACpB,KAAK,GAAyB,IAAI,CAAC;IACnC,SAAS,GAAW,CAAC,CAAC;IACtB,QAAQ,GAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;IAEtD,YAAY,cAAsB,oBAAoB;QACpD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,cAAc;QAClB,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QAED,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;YAC/D,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,IAAI,CAAC,KAAK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AAO,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,OAAO,EAAE,QAAQ,KAAK,SAAS,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,SAAS,CAAC,cAAc,EAAE,CAAC;AACpC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Facilitator Integration for x402 Protocol
3
+ * Connects to Coinbase's x402 facilitator for payment verification and settlement
4
+ */
5
+ import { HTTPFacilitatorClient } from '@x402/core/http';
6
+ export declare const DEFAULT_FACILITATOR_URL = "https://x402.org/facilitator";
7
+ export interface FacilitatorConfig {
8
+ url?: string;
9
+ timeout?: number;
10
+ }
11
+ /**
12
+ * Create a facilitator client for payment verification/settlement
13
+ */
14
+ export declare function createFacilitatorClient(config?: FacilitatorConfig): HTTPFacilitatorClient;
15
+ /**
16
+ * Verify a payment through the facilitator
17
+ */
18
+ export declare function verifyPayment(facilitator: HTTPFacilitatorClient, paymentPayload: unknown, requirements: unknown): Promise<{
19
+ isValid: boolean;
20
+ error?: string;
21
+ }>;
22
+ /**
23
+ * Settle a payment through the facilitator
24
+ */
25
+ export declare function settlePayment(facilitator: HTTPFacilitatorClient, paymentPayload: unknown, requirements: unknown): Promise<{
26
+ success: boolean;
27
+ txHash?: string;
28
+ error?: string;
29
+ }>;
30
+ //# sourceMappingURL=facilitator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../src/facilitator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGxD,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AAEtE,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,GAAE,iBAAsB,GAAG,qBAAqB,CAI7F;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,qBAAqB,EAClC,cAAc,EAAE,OAAO,EACvB,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAO/C;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,qBAAqB,EAClC,cAAc,EAAE,OAAO,EACvB,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAWhE"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ /**
3
+ * Facilitator Integration for x402 Protocol
4
+ * Connects to Coinbase's x402 facilitator for payment verification and settlement
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DEFAULT_FACILITATOR_URL = void 0;
8
+ exports.createFacilitatorClient = createFacilitatorClient;
9
+ exports.verifyPayment = verifyPayment;
10
+ exports.settlePayment = settlePayment;
11
+ const http_1 = require("@x402/core/http");
12
+ // Default Coinbase facilitator URL
13
+ exports.DEFAULT_FACILITATOR_URL = 'https://x402.org/facilitator';
14
+ /**
15
+ * Create a facilitator client for payment verification/settlement
16
+ */
17
+ function createFacilitatorClient(config = {}) {
18
+ return new http_1.HTTPFacilitatorClient({
19
+ url: config.url || exports.DEFAULT_FACILITATOR_URL,
20
+ });
21
+ }
22
+ /**
23
+ * Verify a payment through the facilitator
24
+ */
25
+ async function verifyPayment(facilitator, paymentPayload, requirements) {
26
+ try {
27
+ const result = await facilitator.verify(paymentPayload, requirements);
28
+ return { isValid: result.isValid, error: result.isValid ? undefined : 'Verification failed' };
29
+ }
30
+ catch (error) {
31
+ return { isValid: false, error: error instanceof Error ? error.message : 'Unknown error' };
32
+ }
33
+ }
34
+ /**
35
+ * Settle a payment through the facilitator
36
+ */
37
+ async function settlePayment(facilitator, paymentPayload, requirements) {
38
+ try {
39
+ const result = await facilitator.settle(paymentPayload, requirements);
40
+ return {
41
+ success: result.success,
42
+ txHash: result.transaction,
43
+ error: result.success ? undefined : 'Settlement failed'
44
+ };
45
+ }
46
+ catch (error) {
47
+ return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
48
+ }
49
+ }
50
+ //# sourceMappingURL=facilitator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facilitator.js","sourceRoot":"","sources":["../../src/facilitator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAeH,0DAIC;AAKD,sCAWC;AAKD,sCAeC;AArDD,0CAAwD;AAExD,mCAAmC;AACtB,QAAA,uBAAuB,GAAG,8BAA8B,CAAC;AAOtE;;GAEG;AACH,SAAgB,uBAAuB,CAAC,SAA4B,EAAE;IACpE,OAAO,IAAI,4BAAqB,CAAC;QAC/B,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,+BAAuB;KAC3C,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,aAAa,CACjC,WAAkC,EAClC,cAAuB,EACvB,YAAqB;IAErB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,cAAqB,EAAE,YAAmB,CAAC,CAAC;QACpF,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,qBAAqB,EAAE,CAAC;IAChG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;IAC7F,CAAC;AACH,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,aAAa,CACjC,WAAkC,EAClC,cAAuB,EACvB,YAAqB;IAErB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,cAAqB,EAAE,YAAmB,CAAC,CAAC;QACpF,OAAO;YACL,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,MAAM,CAAC,WAAiC;YAChD,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAmB;SACxD,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;IAC7F,CAAC;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * x402-agent-pay
3
+ * Seamless USDC payments for AI agents using the x402 protocol
4
+ *
5
+ * Built on the official @x402/fetch SDK with added:
6
+ * - Spending controls (per-tx limits, daily/weekly/monthly limits, velocity limits)
7
+ * - Recipient whitelist/blacklist
8
+ * - Receipt storage and audit trail
9
+ * - Facilitator integration
10
+ * - Policy enforcement for autonomous agents
11
+ */
12
+ export { AgentPayClient, PaymentBlockedError, createSimpleFetch } from './client';
13
+ export { checkBalance, checkAllBalances, hasSufficientBalance, getUsdcAddress } from './balance';
14
+ export { PolicyEnforcer } from './policy';
15
+ export { ReceiptStore } from './receipts';
16
+ export { createFacilitatorClient, verifyPayment, settlePayment, DEFAULT_FACILITATOR_URL, type FacilitatorConfig, } from './facilitator';
17
+ export { NETWORK_IDS, CHAINS, USDC_ADDRESSES, FACILITATOR_URL, PROTOCOL_FEE_ADDRESS, PROTOCOL_FEE_BPS, DEFAULT_POLICY, type NetworkName, type PaymentPolicy, type PaymentReceipt, type AgentPayConfig, } from './config';
18
+ export { ServiceDiscovery, getDiscovery, discoverServices, type X402Service, type X402Endpoint, type ServiceCategory, } from './discovery';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAGlF,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGjG,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,aAAa,EACb,uBAAuB,EACvB,KAAK,iBAAiB,GACvB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,WAAW,EACX,MAAM,EACN,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * x402-agent-pay
4
+ * Seamless USDC payments for AI agents using the x402 protocol
5
+ *
6
+ * Built on the official @x402/fetch SDK with added:
7
+ * - Spending controls (per-tx limits, daily/weekly/monthly limits, velocity limits)
8
+ * - Recipient whitelist/blacklist
9
+ * - Receipt storage and audit trail
10
+ * - Facilitator integration
11
+ * - Policy enforcement for autonomous agents
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.discoverServices = exports.getDiscovery = exports.ServiceDiscovery = exports.DEFAULT_POLICY = exports.PROTOCOL_FEE_BPS = exports.PROTOCOL_FEE_ADDRESS = exports.FACILITATOR_URL = exports.USDC_ADDRESSES = exports.CHAINS = exports.NETWORK_IDS = exports.DEFAULT_FACILITATOR_URL = exports.settlePayment = exports.verifyPayment = exports.createFacilitatorClient = exports.ReceiptStore = exports.PolicyEnforcer = exports.getUsdcAddress = exports.hasSufficientBalance = exports.checkAllBalances = exports.checkBalance = exports.createSimpleFetch = exports.PaymentBlockedError = exports.AgentPayClient = void 0;
15
+ // Main client
16
+ var client_1 = require("./client");
17
+ Object.defineProperty(exports, "AgentPayClient", { enumerable: true, get: function () { return client_1.AgentPayClient; } });
18
+ Object.defineProperty(exports, "PaymentBlockedError", { enumerable: true, get: function () { return client_1.PaymentBlockedError; } });
19
+ Object.defineProperty(exports, "createSimpleFetch", { enumerable: true, get: function () { return client_1.createSimpleFetch; } });
20
+ // Balance utilities
21
+ var balance_1 = require("./balance");
22
+ Object.defineProperty(exports, "checkBalance", { enumerable: true, get: function () { return balance_1.checkBalance; } });
23
+ Object.defineProperty(exports, "checkAllBalances", { enumerable: true, get: function () { return balance_1.checkAllBalances; } });
24
+ Object.defineProperty(exports, "hasSufficientBalance", { enumerable: true, get: function () { return balance_1.hasSufficientBalance; } });
25
+ Object.defineProperty(exports, "getUsdcAddress", { enumerable: true, get: function () { return balance_1.getUsdcAddress; } });
26
+ // Policy enforcement
27
+ var policy_1 = require("./policy");
28
+ Object.defineProperty(exports, "PolicyEnforcer", { enumerable: true, get: function () { return policy_1.PolicyEnforcer; } });
29
+ // Receipt storage
30
+ var receipts_1 = require("./receipts");
31
+ Object.defineProperty(exports, "ReceiptStore", { enumerable: true, get: function () { return receipts_1.ReceiptStore; } });
32
+ // Facilitator integration
33
+ var facilitator_1 = require("./facilitator");
34
+ Object.defineProperty(exports, "createFacilitatorClient", { enumerable: true, get: function () { return facilitator_1.createFacilitatorClient; } });
35
+ Object.defineProperty(exports, "verifyPayment", { enumerable: true, get: function () { return facilitator_1.verifyPayment; } });
36
+ Object.defineProperty(exports, "settlePayment", { enumerable: true, get: function () { return facilitator_1.settlePayment; } });
37
+ Object.defineProperty(exports, "DEFAULT_FACILITATOR_URL", { enumerable: true, get: function () { return facilitator_1.DEFAULT_FACILITATOR_URL; } });
38
+ // Configuration and types
39
+ var config_1 = require("./config");
40
+ Object.defineProperty(exports, "NETWORK_IDS", { enumerable: true, get: function () { return config_1.NETWORK_IDS; } });
41
+ Object.defineProperty(exports, "CHAINS", { enumerable: true, get: function () { return config_1.CHAINS; } });
42
+ Object.defineProperty(exports, "USDC_ADDRESSES", { enumerable: true, get: function () { return config_1.USDC_ADDRESSES; } });
43
+ Object.defineProperty(exports, "FACILITATOR_URL", { enumerable: true, get: function () { return config_1.FACILITATOR_URL; } });
44
+ Object.defineProperty(exports, "PROTOCOL_FEE_ADDRESS", { enumerable: true, get: function () { return config_1.PROTOCOL_FEE_ADDRESS; } });
45
+ Object.defineProperty(exports, "PROTOCOL_FEE_BPS", { enumerable: true, get: function () { return config_1.PROTOCOL_FEE_BPS; } });
46
+ Object.defineProperty(exports, "DEFAULT_POLICY", { enumerable: true, get: function () { return config_1.DEFAULT_POLICY; } });
47
+ // Service Discovery - find x402-enabled APIs programmatically
48
+ var discovery_1 = require("./discovery");
49
+ Object.defineProperty(exports, "ServiceDiscovery", { enumerable: true, get: function () { return discovery_1.ServiceDiscovery; } });
50
+ Object.defineProperty(exports, "getDiscovery", { enumerable: true, get: function () { return discovery_1.getDiscovery; } });
51
+ Object.defineProperty(exports, "discoverServices", { enumerable: true, get: function () { return discovery_1.discoverServices; } });
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,cAAc;AACd,mCAAkF;AAAzE,wGAAA,cAAc,OAAA;AAAE,6GAAA,mBAAmB,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAE/D,oBAAoB;AACpB,qCAAiG;AAAxF,uGAAA,YAAY,OAAA;AAAE,2GAAA,gBAAgB,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAAE,yGAAA,cAAc,OAAA;AAE7E,qBAAqB;AACrB,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AAEvB,kBAAkB;AAClB,uCAA0C;AAAjC,wGAAA,YAAY,OAAA;AAErB,0BAA0B;AAC1B,6CAMuB;AALrB,sHAAA,uBAAuB,OAAA;AACvB,4GAAA,aAAa,OAAA;AACb,4GAAA,aAAa,OAAA;AACb,sHAAA,uBAAuB,OAAA;AAIzB,0BAA0B;AAC1B,mCAYkB;AAXhB,qGAAA,WAAW,OAAA;AACX,gGAAA,MAAM,OAAA;AACN,wGAAA,cAAc,OAAA;AACd,yGAAA,eAAe,OAAA;AACf,8GAAA,oBAAoB,OAAA;AACpB,0GAAA,gBAAgB,OAAA;AAChB,wGAAA,cAAc,OAAA;AAOhB,8DAA8D;AAC9D,yCAOqB;AANnB,6GAAA,gBAAgB,OAAA;AAChB,yGAAA,YAAY,OAAA;AACZ,6GAAA,gBAAgB,OAAA"}
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * x402-agent-pay MCP Server
4
+ * Model Context Protocol server for LLM agent integration
5
+ *
6
+ * Works with Claude, GPT, and other MCP-compatible agents
7
+ *
8
+ * Tools exposed:
9
+ * - x402_pay: Make a payment to an x402-enabled endpoint
10
+ * - x402_discover: Find x402 services by category/price/network
11
+ * - x402_balance: Check USDC balance on a network
12
+ * - x402_status: Get current spending status
13
+ * - x402_history: Get recent payment history
14
+ */
15
+ export {};
16
+ //# sourceMappingURL=mcp-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/mcp-server.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,268 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * x402-agent-pay MCP Server
5
+ * Model Context Protocol server for LLM agent integration
6
+ *
7
+ * Works with Claude, GPT, and other MCP-compatible agents
8
+ *
9
+ * Tools exposed:
10
+ * - x402_pay: Make a payment to an x402-enabled endpoint
11
+ * - x402_discover: Find x402 services by category/price/network
12
+ * - x402_balance: Check USDC balance on a network
13
+ * - x402_status: Get current spending status
14
+ * - x402_history: Get recent payment history
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
18
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
19
+ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
20
+ const client_1 = require("./client");
21
+ const discovery_1 = require("./discovery");
22
+ const balance_1 = require("./balance");
23
+ // Get wallet key from environment
24
+ const WALLET_KEY = process.env.X402_WALLET_KEY || process.env.WALLET_PRIVATE_KEY;
25
+ if (!WALLET_KEY) {
26
+ console.error('Error: X402_WALLET_KEY or WALLET_PRIVATE_KEY environment variable required');
27
+ process.exit(1);
28
+ }
29
+ // Initialize client
30
+ const client = new client_1.AgentPayClient({
31
+ privateKey: WALLET_KEY,
32
+ network: process.env.X402_NETWORK || 'base',
33
+ });
34
+ // Define MCP tools
35
+ const tools = [
36
+ {
37
+ name: 'x402_pay',
38
+ description: 'Make a payment to an x402-enabled API endpoint. Handles 402 Payment Required automatically.',
39
+ inputSchema: {
40
+ type: 'object',
41
+ properties: {
42
+ url: {
43
+ type: 'string',
44
+ description: 'The URL to make a paid request to',
45
+ },
46
+ method: {
47
+ type: 'string',
48
+ enum: ['GET', 'POST', 'PUT', 'DELETE'],
49
+ description: 'HTTP method (default: GET)',
50
+ },
51
+ body: {
52
+ type: 'string',
53
+ description: 'Request body for POST/PUT requests (JSON string)',
54
+ },
55
+ network: {
56
+ type: 'string',
57
+ enum: ['base', 'ethereum', 'arbitrum', 'optimism', 'polygon', 'baseSepolia'],
58
+ description: 'Network for payment (default: base)',
59
+ },
60
+ },
61
+ required: ['url'],
62
+ },
63
+ },
64
+ {
65
+ name: 'x402_discover',
66
+ description: 'Discover x402-enabled services. Find paid APIs by category, price, or network.',
67
+ inputSchema: {
68
+ type: 'object',
69
+ properties: {
70
+ category: {
71
+ type: 'string',
72
+ enum: ['weather', 'data', 'ai', 'compute', 'storage', 'oracle', 'search', 'media', 'finance', 'other'],
73
+ description: 'Service category to search',
74
+ },
75
+ maxPrice: {
76
+ type: 'number',
77
+ description: 'Maximum price in USDC',
78
+ },
79
+ network: {
80
+ type: 'string',
81
+ description: 'Network filter (e.g., eip155:8453 for Base)',
82
+ },
83
+ query: {
84
+ type: 'string',
85
+ description: 'Search query for service name/description',
86
+ },
87
+ },
88
+ },
89
+ },
90
+ {
91
+ name: 'x402_balance',
92
+ description: 'Check USDC balance for the configured wallet on a specific network.',
93
+ inputSchema: {
94
+ type: 'object',
95
+ properties: {
96
+ network: {
97
+ type: 'string',
98
+ enum: ['base', 'ethereum', 'arbitrum', 'optimism', 'polygon', 'baseSepolia'],
99
+ description: 'Network to check balance on (default: base)',
100
+ },
101
+ },
102
+ },
103
+ },
104
+ {
105
+ name: 'x402_status',
106
+ description: 'Get current spending status including daily/weekly/monthly totals and remaining limits.',
107
+ inputSchema: {
108
+ type: 'object',
109
+ properties: {},
110
+ },
111
+ },
112
+ {
113
+ name: 'x402_history',
114
+ description: 'Get recent payment history with receipts.',
115
+ inputSchema: {
116
+ type: 'object',
117
+ properties: {
118
+ limit: {
119
+ type: 'number',
120
+ description: 'Number of recent payments to return (default: 10)',
121
+ },
122
+ },
123
+ },
124
+ },
125
+ ];
126
+ // Create MCP server
127
+ const server = new index_js_1.Server({
128
+ name: 'x402-agent-pay',
129
+ version: '2.1.0',
130
+ }, {
131
+ capabilities: {
132
+ tools: {},
133
+ },
134
+ });
135
+ // Handle list tools
136
+ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => ({
137
+ tools,
138
+ }));
139
+ // Handle tool calls
140
+ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
141
+ const { name, arguments: args } = request.params;
142
+ try {
143
+ switch (name) {
144
+ case 'x402_pay': {
145
+ const { url, method = 'GET', body, network } = args;
146
+ const init = { method };
147
+ if (body && (method === 'POST' || method === 'PUT')) {
148
+ init.body = body;
149
+ init.headers = { 'Content-Type': 'application/json' };
150
+ }
151
+ const response = await client.fetch(url, init, { network });
152
+ const data = await response.text();
153
+ return {
154
+ content: [
155
+ {
156
+ type: 'text',
157
+ text: JSON.stringify({
158
+ status: response.status,
159
+ statusText: response.statusText,
160
+ data: tryParseJson(data),
161
+ }, null, 2),
162
+ },
163
+ ],
164
+ };
165
+ }
166
+ case 'x402_discover': {
167
+ const { category, maxPrice, network, query } = args;
168
+ const services = await (0, discovery_1.discoverServices)({ category, maxPrice, network, query });
169
+ return {
170
+ content: [
171
+ {
172
+ type: 'text',
173
+ text: JSON.stringify({
174
+ count: services.length,
175
+ services: services.map(s => ({
176
+ name: s.name,
177
+ description: s.description,
178
+ url: s.url,
179
+ category: s.category,
180
+ priceRange: s.priceRange,
181
+ endpoints: s.endpoints,
182
+ })),
183
+ }, null, 2),
184
+ },
185
+ ],
186
+ };
187
+ }
188
+ case 'x402_balance': {
189
+ const { network = 'base' } = args;
190
+ const address = client.getAddress();
191
+ const balance = await (0, balance_1.checkBalance)(address, network);
192
+ return {
193
+ content: [
194
+ {
195
+ type: 'text',
196
+ text: JSON.stringify({
197
+ address,
198
+ network,
199
+ balanceUsdc: balance,
200
+ }, null, 2),
201
+ },
202
+ ],
203
+ };
204
+ }
205
+ case 'x402_status': {
206
+ const status = client.getSpendingStatus();
207
+ return {
208
+ content: [
209
+ {
210
+ type: 'text',
211
+ text: JSON.stringify(status, null, 2),
212
+ },
213
+ ],
214
+ };
215
+ }
216
+ case 'x402_history': {
217
+ const { limit = 10 } = args;
218
+ const history = client.getHistory(limit);
219
+ return {
220
+ content: [
221
+ {
222
+ type: 'text',
223
+ text: JSON.stringify({
224
+ count: history.length,
225
+ receipts: history,
226
+ }, null, 2),
227
+ },
228
+ ],
229
+ };
230
+ }
231
+ default:
232
+ return {
233
+ content: [{ type: 'text', text: `Unknown tool: ${name}` }],
234
+ isError: true,
235
+ };
236
+ }
237
+ }
238
+ catch (error) {
239
+ return {
240
+ content: [
241
+ {
242
+ type: 'text',
243
+ text: JSON.stringify({
244
+ error: error.message || String(error),
245
+ name: error.name,
246
+ }, null, 2),
247
+ },
248
+ ],
249
+ isError: true,
250
+ };
251
+ }
252
+ });
253
+ function tryParseJson(text) {
254
+ try {
255
+ return JSON.parse(text);
256
+ }
257
+ catch {
258
+ return text;
259
+ }
260
+ }
261
+ // Start server
262
+ async function main() {
263
+ const transport = new stdio_js_1.StdioServerTransport();
264
+ await server.connect(transport);
265
+ console.error('x402-agent-pay MCP server running');
266
+ }
267
+ main().catch(console.error);
268
+ //# sourceMappingURL=mcp-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../src/mcp-server.ts"],"names":[],"mappings":";;AACA;;;;;;;;;;;;GAYG;;AAEH,wEAAmE;AACnE,wEAAiF;AACjF,iEAI4C;AAE5C,qCAA0C;AAC1C,2CAAgE;AAChE,uCAAyC;AAGzC,kCAAkC;AAClC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAEjF,IAAI,CAAC,UAAU,EAAE,CAAC;IAChB,OAAO,CAAC,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAC5F,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,oBAAoB;AACpB,MAAM,MAAM,GAAG,IAAI,uBAAc,CAAC;IAChC,UAAU,EAAE,UAAU;IACtB,OAAO,EAAG,OAAO,CAAC,GAAG,CAAC,YAA4B,IAAI,MAAM;CAC7D,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AAmC,CAAC,CAAC;AACrD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Enhanced Payment Policy Enforcement
3
+ * Spending controls and safety guards for autonomous agents
4
+ *
5
+ * Features:
6
+ * - Per-transaction limits
7
+ * - Daily/weekly/monthly limits
8
+ * - Velocity limits (max transactions per hour)
9
+ * - Per-recipient limits
10
+ * - Recipient whitelist/blacklist
11
+ * - Simulation mode (dry-run before paying)
12
+ */
13
+ import { PaymentPolicy } from './config';
14
+ /**
15
+ * Policy enforcer that tracks spending and enforces limits
16
+ */
17
+ export declare class PolicyEnforcer {
18
+ private policy;
19
+ private spendingPath;
20
+ private state;
21
+ constructor(policy?: PaymentPolicy, spendingPath?: string);
22
+ private getDateKeys;
23
+ private loadState;
24
+ private saveState;
25
+ /**
26
+ * Check if a payment is allowed by policy
27
+ * Returns { allowed: true } or { allowed: false, reason: string }
28
+ */
29
+ checkPayment(amountUsdc: number, recipient: string): {
30
+ allowed: boolean;
31
+ reason?: string;
32
+ };
33
+ /**
34
+ * Record a successful payment
35
+ */
36
+ recordPayment(amountUsdc: number, recipient: string): void;
37
+ /**
38
+ * Get current spending status
39
+ */
40
+ getStatus(): {
41
+ daily: {
42
+ spent: number;
43
+ limit: number;
44
+ remaining: number;
45
+ transactions: number;
46
+ };
47
+ weekly?: {
48
+ spent: number;
49
+ limit: number;
50
+ remaining: number;
51
+ };
52
+ monthly?: {
53
+ spent: number;
54
+ limit: number;
55
+ remaining: number;
56
+ };
57
+ velocity?: {
58
+ count: number;
59
+ limit: number;
60
+ remaining: number;
61
+ };
62
+ policy: PaymentPolicy;
63
+ };
64
+ /**
65
+ * Check if amount requires explicit approval (vs auto-approve)
66
+ */
67
+ requiresApproval(amountUsdc: number): boolean;
68
+ /**
69
+ * Emergency freeze - block all payments
70
+ */
71
+ freeze(): void;
72
+ }
73
+ //# sourceMappingURL=policy.d.ts.map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