@ampersend_ai/ampersend-sdk 0.0.19 → 0.0.21
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/dist/ampersend/client.d.ts +4 -9
- package/dist/ampersend/client.d.ts.map +1 -1
- package/dist/ampersend/client.js +25 -21
- package/dist/ampersend/client.js.map +1 -1
- package/dist/ampersend/treasurer.d.ts +14 -79
- package/dist/ampersend/treasurer.d.ts.map +1 -1
- package/dist/ampersend/treasurer.js +34 -102
- package/dist/ampersend/treasurer.js.map +1 -1
- package/dist/ampersend/types.d.ts +342 -336
- package/dist/ampersend/types.d.ts.map +1 -1
- package/dist/ampersend/types.js +110 -149
- package/dist/ampersend/types.js.map +1 -1
- package/dist/ampersend/zod-bridge.d.ts +15 -0
- package/dist/ampersend/zod-bridge.d.ts.map +1 -0
- package/dist/ampersend/zod-bridge.js +29 -0
- package/dist/ampersend/zod-bridge.js.map +1 -0
- package/dist/cli/commands/fetch.d.ts.map +1 -1
- package/dist/cli/commands/fetch.js.map +1 -1
- package/dist/cli/commands/setup.d.ts.map +1 -1
- package/dist/cli/commands/setup.js +6 -1
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/client/client.d.ts +0 -3
- package/dist/mcp/client/client.d.ts.map +1 -1
- package/dist/mcp/client/client.js +10 -14
- package/dist/mcp/client/client.js.map +1 -1
- package/dist/mcp/client/factory.d.ts +0 -2
- package/dist/mcp/client/factory.d.ts.map +1 -1
- package/dist/mcp/client/factory.js +0 -3
- package/dist/mcp/client/factory.js.map +1 -1
- package/dist/mcp/client/middleware.d.ts +0 -3
- package/dist/mcp/client/middleware.d.ts.map +1 -1
- package/dist/mcp/client/middleware.js +9 -12
- package/dist/mcp/client/middleware.js.map +1 -1
- package/dist/mcp/client/protocol.d.ts +81 -85
- package/dist/mcp/client/protocol.d.ts.map +1 -1
- package/dist/mcp/client/protocol.js +17 -15
- package/dist/mcp/client/protocol.js.map +1 -1
- package/dist/mcp/client/types.d.ts +6 -19
- package/dist/mcp/client/types.d.ts.map +1 -1
- package/dist/mcp/proxy/cli.d.ts.map +1 -1
- package/dist/mcp/proxy/cli.js +0 -1
- package/dist/mcp/proxy/cli.js.map +1 -1
- package/dist/mcp/proxy/env.d.ts +0 -9
- package/dist/mcp/proxy/env.d.ts.map +1 -1
- package/dist/mcp/proxy/env.js +0 -2
- package/dist/mcp/proxy/env.js.map +1 -1
- package/dist/mcp/proxy/factory.d.ts +0 -2
- package/dist/mcp/proxy/factory.d.ts.map +1 -1
- package/dist/mcp/proxy/factory.js +0 -3
- package/dist/mcp/proxy/factory.js.map +1 -1
- package/dist/mcp/server/fastmcp/middleware.d.ts +9 -29
- package/dist/mcp/server/fastmcp/middleware.d.ts.map +1 -1
- package/dist/mcp/server/fastmcp/middleware.js +10 -42
- package/dist/mcp/server/fastmcp/middleware.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/x402/envelopes.d.ts +62 -0
- package/dist/x402/envelopes.d.ts.map +1 -0
- package/dist/x402/envelopes.js +73 -0
- package/dist/x402/envelopes.js.map +1 -0
- package/dist/x402/http/client.d.ts +37 -0
- package/dist/x402/http/client.d.ts.map +1 -0
- package/dist/x402/http/client.js +159 -0
- package/dist/x402/http/client.js.map +1 -0
- package/dist/x402/http/factory.d.ts +11 -25
- package/dist/x402/http/factory.d.ts.map +1 -1
- package/dist/x402/http/factory.js +11 -22
- package/dist/x402/http/factory.js.map +1 -1
- package/dist/x402/http/index.d.ts +4 -1
- package/dist/x402/http/index.d.ts.map +1 -1
- package/dist/x402/http/index.js +2 -1
- package/dist/x402/http/index.js.map +1 -1
- package/dist/x402/index.d.ts +4 -1
- package/dist/x402/index.d.ts.map +1 -1
- package/dist/x402/index.js +3 -2
- package/dist/x402/index.js.map +1 -1
- package/dist/x402/treasurer.d.ts +22 -47
- package/dist/x402/treasurer.d.ts.map +1 -1
- package/dist/x402/treasurers/naive.d.ts +4 -40
- package/dist/x402/treasurers/naive.d.ts.map +1 -1
- package/dist/x402/treasurers/naive.js +7 -44
- package/dist/x402/treasurers/naive.js.map +1 -1
- package/dist/x402/wallet.d.ts +7 -32
- package/dist/x402/wallet.d.ts.map +1 -1
- package/dist/x402/wallet.js +0 -3
- package/dist/x402/wallet.js.map +1 -1
- package/dist/x402/wallets/account/wallet.d.ts +9 -30
- package/dist/x402/wallets/account/wallet.d.ts.map +1 -1
- package/dist/x402/wallets/account/wallet.js +30 -37
- package/dist/x402/wallets/account/wallet.js.map +1 -1
- package/dist/x402/wallets/index.d.ts +0 -1
- package/dist/x402/wallets/index.d.ts.map +1 -1
- package/dist/x402/wallets/index.js +0 -1
- package/dist/x402/wallets/index.js.map +1 -1
- package/dist/x402/wallets/smart-account/chain.d.ts +4 -0
- package/dist/x402/wallets/smart-account/chain.d.ts.map +1 -0
- package/dist/x402/wallets/smart-account/chain.js +12 -0
- package/dist/x402/wallets/smart-account/chain.js.map +1 -0
- package/dist/x402/wallets/smart-account/cosigned.d.ts +7 -33
- package/dist/x402/wallets/smart-account/cosigned.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/cosigned.js +28 -51
- package/dist/x402/wallets/smart-account/cosigned.js.map +1 -1
- package/dist/x402/wallets/smart-account/exact.d.ts +6 -20
- package/dist/x402/wallets/smart-account/exact.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/exact.js +33 -43
- package/dist/x402/wallets/smart-account/exact.js.map +1 -1
- package/dist/x402/wallets/smart-account/wallet.d.ts +6 -39
- package/dist/x402/wallets/smart-account/wallet.d.ts.map +1 -1
- package/dist/x402/wallets/smart-account/wallet.js +9 -36
- package/dist/x402/wallets/smart-account/wallet.js.map +1 -1
- package/package.json +4 -4
- package/dist/x402/http/adapter.d.ts +0 -38
- package/dist/x402/http/adapter.d.ts.map +0 -1
- package/dist/x402/http/adapter.js +0 -193
- package/dist/x402/http/adapter.js.map +0 -1
- package/dist/x402/http/v2-adapter.d.ts +0 -56
- package/dist/x402/http/v2-adapter.d.ts.map +0 -1
- package/dist/x402/http/v2-adapter.js +0 -94
- package/dist/x402/http/v2-adapter.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/mcp/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAClF,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,iCAAiC,EACtC,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/mcp/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAClF,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,KAAK,iCAAiC,EACtC,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACxB,MAAM,oCAAoC,CAAA;AAM3C,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,YAAY,CAAA;AAI7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,MAAO,SAAQ,SAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa;IAK9D;;;;;;;OAOG;IACG,QAAQ,CACZ,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,EACjC,YAAY,CAAC,EAAE,OAAO,oBAAoB,GAAG,OAAO,iCAAiC,EACrF,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,cAAc,GAAG,2BAA2B,CAAC;IAMxD;;;;;;OAMG;IACG,YAAY,CAAC,MAAM,EAAE,mBAAmB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAMhH;;OAEG;YACW,gBAAgB;YAuChB,aAAa;IA6B3B;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;CAY1B"}
|
|
@@ -92,28 +92,24 @@ export class Client extends McpClient {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const paymentContext = {
|
|
101
|
-
method,
|
|
102
|
-
params,
|
|
95
|
+
async decidePayment(method, params, wireRequirements) {
|
|
96
|
+
// MCP x402 is v1-only.
|
|
97
|
+
const request = {
|
|
98
|
+
protocol: "x402-v1",
|
|
99
|
+
data: { x402Version: 1, accepts: [...wireRequirements] },
|
|
103
100
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (!authorization) {
|
|
107
|
-
// Payment declined
|
|
101
|
+
const authorization = await this.treasurer.onPaymentRequired(request, { method, params });
|
|
102
|
+
if (!authorization)
|
|
108
103
|
return null;
|
|
104
|
+
if (authorization.payment.protocol !== "x402-v1") {
|
|
105
|
+
throw new Error(`MCP retry requires an x402-v1 authorization; got ${authorization.payment.protocol}`);
|
|
109
106
|
}
|
|
110
|
-
// Return modified params with payment (using spec-compliant field name)
|
|
111
107
|
const baseMeta = params._meta || {};
|
|
112
108
|
const paramsWithPayment = {
|
|
113
109
|
...params,
|
|
114
110
|
_meta: {
|
|
115
111
|
...baseMeta,
|
|
116
|
-
"x402/payment": authorization.payment,
|
|
112
|
+
"x402/payment": authorization.payment.data,
|
|
117
113
|
},
|
|
118
114
|
};
|
|
119
115
|
return { paramsWithPayment, authorization };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/mcp/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAE/E,OAAO,EACL,QAAQ,GAST,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/mcp/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAE/E,OAAO,EACL,QAAQ,GAST,MAAM,oCAAoC,CAAA;AAK3C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAK9C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,MAAO,SAAQ,SAAS;IAClB,SAAS,CAAe;IAEzC,YAAY,UAA0B,EAAE,OAAsB;QAC5D,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;QACrC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACpC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,QAAQ,CACZ,MAAiC,EACjC,YAAqF,EACrF,OAAwB;QAExB,OAAO,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CACvD,KAAK,CAAC,QAAQ,CAAC,CAA8B,EAAE,YAAY,EAAE,OAAO,CAAC,CACtE,CAAA;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAC,MAAqC,EAAE,OAAwB;QAChF,OAAO,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAC3D,K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AC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -22,8 +22,6 @@ export interface SimpleClientOptions {
|
|
|
22
22
|
sessionKeyPrivateKey: Hex;
|
|
23
23
|
/** Ampersend API URL (defaults to production) */
|
|
24
24
|
apiUrl?: string;
|
|
25
|
-
/** Chain ID (defaults to Base Sepolia 84532) */
|
|
26
|
-
chainId?: number;
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Create an MCP client with Ampersend payment support.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/mcp/client/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,IAAI,gBAAgB,EAAE,MAAM,2CAA2C,CAAA;AAClG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/mcp/client/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,aAAa,IAAI,gBAAgB,EAAE,MAAM,2CAA2C,CAAA;AAClG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAGxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAKpC;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,UAAU,EAAE,cAAc,CAAA;IAC1B,kCAAkC;IAClC,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,4BAA4B;IAC5B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,0CAA0C;IAC1C,oBAAoB,EAAE,GAAG,CAAA;IACzB,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAW7E;AAGD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -7,8 +7,6 @@ import { createAmpersendTreasurer } from "../../ampersend/treasurer.js";
|
|
|
7
7
|
import { Client } from "./client.js";
|
|
8
8
|
/** Default Ampersend API URL */
|
|
9
9
|
const DEFAULT_API_URL = "https://api.ampersend.ai";
|
|
10
|
-
/** Default chain ID (Base Sepolia) */
|
|
11
|
-
const DEFAULT_CHAIN_ID = 84532;
|
|
12
10
|
/**
|
|
13
11
|
* Create an MCP client with Ampersend payment support.
|
|
14
12
|
*
|
|
@@ -43,7 +41,6 @@ export function createAmpersendMcpClient(options) {
|
|
|
43
41
|
smartAccountAddress: options.smartAccountAddress,
|
|
44
42
|
sessionKeyPrivateKey: options.sessionKeyPrivateKey,
|
|
45
43
|
apiUrl: options.apiUrl ?? DEFAULT_API_URL,
|
|
46
|
-
chainId: options.chainId ?? DEFAULT_CHAIN_ID,
|
|
47
44
|
});
|
|
48
45
|
return new Client(options.clientInfo, {
|
|
49
46
|
mcpOptions: options.mcpOptions ?? { capabilities: { tools: {} } },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/mcp/client/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,gCAAgC;AAChC,MAAM,eAAe,GAAG,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/mcp/client/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,gCAAgC;AAChC,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAmBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAA4B;IACnE,MAAM,SAAS,GAAG,wBAAwB,CAAC;QACzC,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;QAChD,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;QAClD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,eAAe;KAC1C,CAAC,CAAA;IAEF,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE;QACpC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;QACjE,SAAS;KACV,CAAC,CAAA;AACJ,CAAC;AAED,4CAA4C;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -9,9 +9,6 @@ export declare class X402Middleware {
|
|
|
9
9
|
private readonly _authorizations;
|
|
10
10
|
constructor(options: X402MiddlewareOptions);
|
|
11
11
|
onMessage(request: JSONRPCRequest, response: JSONRPCMessage): Promise<JSONRPCRequest | void>;
|
|
12
|
-
/**
|
|
13
|
-
* Decides x402 payment request and return modified message if payment approved
|
|
14
|
-
*/
|
|
15
12
|
private decidePayment;
|
|
16
13
|
}
|
|
17
14
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/mcp/client/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/mcp/client/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAI7F,OAAO,KAAK,EAAgC,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAQ1F,MAAM,WAAW,qBAAqB;IACpC,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAA;CAClC;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAE1C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmC;gBAEvD,OAAO,EAAE,qBAAqB;IAIpC,SAAS,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;YA8CpF,aAAa;CA4B5B"}
|
|
@@ -31,7 +31,7 @@ export class X402Middleware {
|
|
|
31
31
|
if (request.params?._meta?.["x402/payment"]) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
const paymentResult = await this.decidePayment(request, x402Data.accepts);
|
|
34
|
+
const paymentResult = await this.decidePayment(request, x402Data.accepts ?? []);
|
|
35
35
|
if (!paymentResult) {
|
|
36
36
|
return; // Payment declined
|
|
37
37
|
}
|
|
@@ -42,23 +42,20 @@ export class X402Middleware {
|
|
|
42
42
|
await this._treasurer.onStatus("sending", authorization);
|
|
43
43
|
return messageWithPayment;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
async decidePayment(request, wireRequirements) {
|
|
46
|
+
// MCP x402 is v1-only.
|
|
47
|
+
const paymentRequest = {
|
|
48
|
+
protocol: "x402-v1",
|
|
49
|
+
data: { x402Version: 1, accepts: [...wireRequirements] },
|
|
50
|
+
};
|
|
50
51
|
const paymentContext = {
|
|
51
52
|
method: request.method,
|
|
52
53
|
params: request.params,
|
|
53
54
|
metadata: { requestId: request.id },
|
|
54
55
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!authorization) {
|
|
58
|
-
// Payment declined
|
|
56
|
+
const authorization = await this._treasurer.onPaymentRequired(paymentRequest, paymentContext);
|
|
57
|
+
if (!authorization)
|
|
59
58
|
return null;
|
|
60
|
-
}
|
|
61
|
-
// Build message with payment
|
|
62
59
|
const { messageWithPayment } = buildMessageWithPayment(request, authorization.payment, authorization.authorizationId);
|
|
63
60
|
return { messageWithPayment, authorization };
|
|
64
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/mcp/client/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,MAAM,oCAAoC,CAAA;
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/mcp/client/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,MAAM,oCAAoC,CAAA;AAK7F,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,eAAe,CAAA;AAOtB,MAAM,OAAO,cAAc;IACR,UAAU,CAAe;IAC1C,wDAAwD;IACvC,eAAe,GAAG,IAAI,GAAG,EAAyB,CAAA;IAEnE,YAAY,OAA8B;QACxC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAA;IACrC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAuB,EAAE,QAAwB;QAC/D,MAAM,QAAQ,GAAG,0BAA0B,CAAC,QAAQ,CAAC,CAAA;QACrD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAM;QACR,CAAC;QAED,IAAI,wBAAwB,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,MAAM,EAAE,SAAS,EAAE,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;YACjD,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,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;YACnB,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,gBAAgB,CAAC,EAAE;SACzD,CAAA;QAED,MAAM,cAAc,GAAG;YACrB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE;SACpC,CAAA;QAED,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA;QAE7F,IAAI,CAAC,aAAa;YAAE,OAAO,IAAI,CAAA;QAE/B,MAAM,EAAE,kBAAkB,EAAE,GAAG,uBAAuB,CACpD,OAAO,EACP,aAAa,CAAC,OAAO,EACrB,aAAa,CAAC,eAAe,CAC9B,CAAA;QAED,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,CAAA;IAC9C,CAAC;CACF"}
|
|
@@ -1,170 +1,166 @@
|
|
|
1
1
|
import { type JSONRPCMessage, type JSONRPCRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type PaymentPayloadV1 as V1PaymentPayload } from "@x402/core/schemas";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import type { PaymentAuthorization } from "../../x402/envelopes.ts";
|
|
4
5
|
import type { X402Response } from "./types.ts";
|
|
5
6
|
export declare const McpX402PaymentResponseSchema: z.ZodObject<{
|
|
6
7
|
"x402/payment-response": z.ZodObject<{
|
|
7
8
|
success: z.ZodBoolean;
|
|
8
|
-
errorReason: z.ZodOptional<z.ZodEnum<["insufficient_funds", "invalid_exact_evm_payload_authorization_valid_after", "invalid_exact_evm_payload_authorization_valid_before", "invalid_exact_evm_payload_authorization_value", "invalid_exact_evm_payload_signature", "invalid_exact_evm_payload_recipient_mismatch", "invalid_exact_svm_payload_transaction", "invalid_exact_svm_payload_transaction_amount_mismatch", "invalid_exact_svm_payload_transaction_create_ata_instruction", "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee", "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset", "invalid_exact_svm_payload_transaction_instructions", "invalid_exact_svm_payload_transaction_instructions_length", "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction", "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction", "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high", "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked", "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked", "invalid_exact_svm_payload_transaction_not_a_transfer_instruction", "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata", "invalid_exact_svm_payload_transaction_receiver_ata_not_found", "invalid_exact_svm_payload_transaction_sender_ata_not_found", "invalid_exact_svm_payload_transaction_simulation_failed", "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata", "invalid_network", "invalid_payload", "invalid_payment_requirements", "invalid_scheme", "invalid_payment", "payment_expired", "unsupported_scheme", "invalid_x402_version", "invalid_transaction_state", "invalid_x402_version", "settle_exact_svm_block_height_exceeded", "settle_exact_svm_transaction_confirmation_timed_out", "unsupported_scheme", "unexpected_settle_error", "unexpected_verify_error"]>>;
|
|
9
|
-
payer: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodString]>>;
|
|
10
9
|
transaction: z.ZodString;
|
|
11
|
-
network: z.
|
|
10
|
+
network: z.ZodString;
|
|
11
|
+
errorReason: z.ZodOptional<z.ZodString>;
|
|
12
|
+
payer: z.ZodOptional<z.ZodString>;
|
|
12
13
|
}, "strip", z.ZodTypeAny, {
|
|
13
|
-
|
|
14
|
+
network: string;
|
|
14
15
|
success: boolean;
|
|
15
|
-
|
|
16
|
+
transaction: string;
|
|
17
|
+
errorReason?: string | undefined;
|
|
16
18
|
payer?: string | undefined;
|
|
17
|
-
errorReason?: "invalid_exact_svm_payload_transaction" | "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
18
19
|
}, {
|
|
19
|
-
|
|
20
|
+
network: string;
|
|
20
21
|
success: boolean;
|
|
21
|
-
|
|
22
|
+
transaction: string;
|
|
23
|
+
errorReason?: string | undefined;
|
|
22
24
|
payer?: string | undefined;
|
|
23
|
-
errorReason?: "invalid_exact_svm_payload_transaction" | "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
24
25
|
}>;
|
|
25
26
|
}, "strip", z.ZodTypeAny, {
|
|
26
27
|
"x402/payment-response": {
|
|
27
|
-
|
|
28
|
+
network: string;
|
|
28
29
|
success: boolean;
|
|
29
|
-
|
|
30
|
+
transaction: string;
|
|
31
|
+
errorReason?: string | undefined;
|
|
30
32
|
payer?: string | undefined;
|
|
31
|
-
errorReason?: "invalid_exact_svm_payload_transaction" | "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
32
33
|
};
|
|
33
34
|
}, {
|
|
34
35
|
"x402/payment-response": {
|
|
35
|
-
|
|
36
|
+
network: string;
|
|
36
37
|
success: boolean;
|
|
37
|
-
|
|
38
|
+
transaction: string;
|
|
39
|
+
errorReason?: string | undefined;
|
|
38
40
|
payer?: string | undefined;
|
|
39
|
-
errorReason?: "invalid_exact_svm_payload_transaction" | "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
40
41
|
};
|
|
41
42
|
}>;
|
|
42
43
|
export type McpX402PaymentResponse = z.infer<typeof McpX402PaymentResponseSchema>;
|
|
44
|
+
/** 402 body embedded in the JSON-RPC `error.data`, optionally with a settle response. */
|
|
43
45
|
export declare const McpX402PaymentRequiredSchema: z.ZodObject<{
|
|
44
|
-
x402Version: z.
|
|
45
|
-
error: z.ZodOptional<z.
|
|
46
|
-
accepts: z.
|
|
47
|
-
scheme: z.
|
|
48
|
-
network: z.
|
|
49
|
-
maxAmountRequired: z.
|
|
46
|
+
x402Version: z.ZodLiteral<1>;
|
|
47
|
+
error: z.ZodOptional<z.ZodString>;
|
|
48
|
+
accepts: z.ZodArray<z.ZodObject<{
|
|
49
|
+
scheme: z.ZodString;
|
|
50
|
+
network: z.ZodString;
|
|
51
|
+
maxAmountRequired: z.ZodString;
|
|
50
52
|
resource: z.ZodString;
|
|
51
53
|
description: z.ZodString;
|
|
52
|
-
mimeType: z.ZodString
|
|
53
|
-
outputSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
54
|
-
payTo: z.
|
|
54
|
+
mimeType: z.ZodOptional<z.ZodString>;
|
|
55
|
+
outputSchema: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
56
|
+
payTo: z.ZodString;
|
|
55
57
|
maxTimeoutSeconds: z.ZodNumber;
|
|
56
|
-
asset: z.
|
|
57
|
-
extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.
|
|
58
|
+
asset: z.ZodString;
|
|
59
|
+
extra: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
58
60
|
}, "strip", z.ZodTypeAny, {
|
|
59
|
-
scheme: "exact";
|
|
60
61
|
description: string;
|
|
61
|
-
|
|
62
|
+
scheme: string;
|
|
63
|
+
network: string;
|
|
62
64
|
maxAmountRequired: string;
|
|
63
65
|
resource: string;
|
|
64
|
-
mimeType: string;
|
|
65
66
|
payTo: string;
|
|
66
67
|
maxTimeoutSeconds: number;
|
|
67
68
|
asset: string;
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
mimeType?: string | undefined;
|
|
70
|
+
outputSchema?: Record<string, unknown> | null | undefined;
|
|
71
|
+
extra?: Record<string, unknown> | null | undefined;
|
|
70
72
|
}, {
|
|
71
|
-
scheme: "exact";
|
|
72
73
|
description: string;
|
|
73
|
-
|
|
74
|
+
scheme: string;
|
|
75
|
+
network: string;
|
|
74
76
|
maxAmountRequired: string;
|
|
75
77
|
resource: string;
|
|
76
|
-
mimeType: string;
|
|
77
78
|
payTo: string;
|
|
78
79
|
maxTimeoutSeconds: number;
|
|
79
80
|
asset: string;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
mimeType?: string | undefined;
|
|
82
|
+
outputSchema?: Record<string, unknown> | null | undefined;
|
|
83
|
+
extra?: Record<string, unknown> | null | undefined;
|
|
84
|
+
}>, "many">;
|
|
84
85
|
} & {
|
|
85
86
|
"x402/payment-response": z.ZodOptional<z.ZodObject<{
|
|
86
87
|
success: z.ZodBoolean;
|
|
87
|
-
errorReason: z.ZodOptional<z.ZodEnum<["insufficient_funds", "invalid_exact_evm_payload_authorization_valid_after", "invalid_exact_evm_payload_authorization_valid_before", "invalid_exact_evm_payload_authorization_value", "invalid_exact_evm_payload_signature", "invalid_exact_evm_payload_recipient_mismatch", "invalid_exact_svm_payload_transaction", "invalid_exact_svm_payload_transaction_amount_mismatch", "invalid_exact_svm_payload_transaction_create_ata_instruction", "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee", "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset", "invalid_exact_svm_payload_transaction_instructions", "invalid_exact_svm_payload_transaction_instructions_length", "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction", "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction", "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high", "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked", "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked", "invalid_exact_svm_payload_transaction_not_a_transfer_instruction", "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata", "invalid_exact_svm_payload_transaction_receiver_ata_not_found", "invalid_exact_svm_payload_transaction_sender_ata_not_found", "invalid_exact_svm_payload_transaction_simulation_failed", "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata", "invalid_network", "invalid_payload", "invalid_payment_requirements", "invalid_scheme", "invalid_payment", "payment_expired", "unsupported_scheme", "invalid_x402_version", "invalid_transaction_state", "invalid_x402_version", "settle_exact_svm_block_height_exceeded", "settle_exact_svm_transaction_confirmation_timed_out", "unsupported_scheme", "unexpected_settle_error", "unexpected_verify_error"]>>;
|
|
88
|
-
payer: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodString]>>;
|
|
89
88
|
transaction: z.ZodString;
|
|
90
|
-
network: z.
|
|
89
|
+
network: z.ZodString;
|
|
90
|
+
errorReason: z.ZodOptional<z.ZodString>;
|
|
91
|
+
payer: z.ZodOptional<z.ZodString>;
|
|
91
92
|
}, "strip", z.ZodTypeAny, {
|
|
92
|
-
|
|
93
|
+
network: string;
|
|
93
94
|
success: boolean;
|
|
94
|
-
|
|
95
|
+
transaction: string;
|
|
96
|
+
errorReason?: string | undefined;
|
|
95
97
|
payer?: string | undefined;
|
|
96
|
-
errorReason?: "invalid_exact_svm_payload_transaction" | "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
97
98
|
}, {
|
|
98
|
-
|
|
99
|
+
network: string;
|
|
99
100
|
success: boolean;
|
|
100
|
-
|
|
101
|
+
transaction: string;
|
|
102
|
+
errorReason?: string | undefined;
|
|
101
103
|
payer?: string | undefined;
|
|
102
|
-
errorReason?: "invalid_exact_svm_payload_transaction" | "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
103
104
|
}>>;
|
|
104
105
|
}, "strip", z.ZodTypeAny, {
|
|
105
|
-
x402Version:
|
|
106
|
-
|
|
107
|
-
"x402/payment-response"?: {
|
|
108
|
-
transaction: string;
|
|
109
|
-
success: boolean;
|
|
110
|
-
network: "base-sepolia" | "avalanche-fuji" | "base" | "sei" | "sei-testnet" | "polygon" | "polygon-amoy" | "peaq" | "avalanche" | "iotex" | "solana-devnet" | "solana";
|
|
111
|
-
payer?: string | undefined;
|
|
112
|
-
errorReason?: "invalid_exact_svm_payload_transaction" | "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
113
|
-
} | undefined;
|
|
114
|
-
accepts?: {
|
|
115
|
-
scheme: "exact";
|
|
106
|
+
x402Version: 1;
|
|
107
|
+
accepts: {
|
|
116
108
|
description: string;
|
|
117
|
-
|
|
109
|
+
scheme: string;
|
|
110
|
+
network: string;
|
|
118
111
|
maxAmountRequired: string;
|
|
119
112
|
resource: string;
|
|
120
|
-
mimeType: string;
|
|
121
113
|
payTo: string;
|
|
122
114
|
maxTimeoutSeconds: number;
|
|
123
115
|
asset: string;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
x402Version: number;
|
|
130
|
-
error?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
116
|
+
mimeType?: string | undefined;
|
|
117
|
+
outputSchema?: Record<string, unknown> | null | undefined;
|
|
118
|
+
extra?: Record<string, unknown> | null | undefined;
|
|
119
|
+
}[];
|
|
120
|
+
error?: string | undefined;
|
|
131
121
|
"x402/payment-response"?: {
|
|
132
|
-
|
|
122
|
+
network: string;
|
|
133
123
|
success: boolean;
|
|
134
|
-
|
|
124
|
+
transaction: string;
|
|
125
|
+
errorReason?: string | undefined;
|
|
135
126
|
payer?: string | undefined;
|
|
136
|
-
errorReason?: "invalid_exact_svm_payload_transaction" | "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_cannot_derive_receiver_ata" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
|
|
137
127
|
} | undefined;
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
}, {
|
|
129
|
+
x402Version: 1;
|
|
130
|
+
accepts: {
|
|
140
131
|
description: string;
|
|
141
|
-
|
|
132
|
+
scheme: string;
|
|
133
|
+
network: string;
|
|
142
134
|
maxAmountRequired: string;
|
|
143
135
|
resource: string;
|
|
144
|
-
mimeType: string;
|
|
145
136
|
payTo: string;
|
|
146
137
|
maxTimeoutSeconds: number;
|
|
147
138
|
asset: string;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
139
|
+
mimeType?: string | undefined;
|
|
140
|
+
outputSchema?: Record<string, unknown> | null | undefined;
|
|
141
|
+
extra?: Record<string, unknown> | null | undefined;
|
|
142
|
+
}[];
|
|
143
|
+
error?: string | undefined;
|
|
144
|
+
"x402/payment-response"?: {
|
|
145
|
+
network: string;
|
|
146
|
+
success: boolean;
|
|
147
|
+
transaction: string;
|
|
148
|
+
errorReason?: string | undefined;
|
|
149
|
+
payer?: string | undefined;
|
|
150
|
+
} | undefined;
|
|
152
151
|
}>;
|
|
153
152
|
export type McpX402PaymentRequired = z.infer<typeof McpX402PaymentRequiredSchema>;
|
|
154
|
-
|
|
153
|
+
/** Embed a payment into a JSON-RPC request's `_meta`. MCP is v1-only; throws otherwise. */
|
|
154
|
+
export declare function buildMessageWithPayment(message: JSONRPCRequest, payment: PaymentAuthorization, paymentId: string): {
|
|
155
155
|
messageWithPayment: JSONRPCRequest;
|
|
156
156
|
};
|
|
157
157
|
export declare function paymentFromRequest(request: JSONRPCRequest): {
|
|
158
|
-
payment:
|
|
158
|
+
payment: V1PaymentPayload | null;
|
|
159
159
|
paymentId: string | null;
|
|
160
160
|
};
|
|
161
161
|
export declare function addMeta(request: JSONRPCRequest, k: string, v: unknown): JSONRPCRequest;
|
|
162
162
|
export declare function x402DataFromJSONRPCMessage(msg: JSONRPCMessage): McpX402PaymentResponse | McpX402PaymentRequired | null;
|
|
163
163
|
export declare function isMcpX402PaymentResponse(data: unknown): data is McpX402PaymentResponse;
|
|
164
164
|
export declare function isMcpX402PaymentRequired(data: unknown): data is McpX402PaymentRequired;
|
|
165
|
-
/**
|
|
166
|
-
* Type assertion for X402Response with runtime validation.
|
|
167
|
-
* Returns null if the data doesn't match the expected structure.
|
|
168
|
-
*/
|
|
169
165
|
export declare function asX402Response(obj: unknown): X402Response | null;
|
|
170
166
|
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/mcp/client/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/mcp/client/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,E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,CActF;AAED,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,cAAc,GAClB,sBAAsB,GAAG,sBAAsB,GAAG,IAAI,CAUxD;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,sBAAsB,CAGtF;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,sBAAsB,CAGtF;AAaD,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,GAAG,IAAI,CAEhE"}
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { isJSONRPCError, isJSONRPCResponse, } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PaymentRequiredV1Schema, } from "@x402/core/schemas";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
/** Local replica — `@x402/core` exports `SettleResponse` as a type only. */
|
|
5
|
+
const SettleResponseSchema = z.object({
|
|
6
|
+
success: z.boolean(),
|
|
7
|
+
transaction: z.string(),
|
|
8
|
+
network: z.string(),
|
|
9
|
+
errorReason: z.string().optional(),
|
|
10
|
+
payer: z.string().optional(),
|
|
11
|
+
});
|
|
4
12
|
export const McpX402PaymentResponseSchema = z.object({
|
|
5
13
|
"x402/payment-response": SettleResponseSchema,
|
|
6
14
|
});
|
|
7
|
-
|
|
15
|
+
/** 402 body embedded in the JSON-RPC `error.data`, optionally with a settle response. */
|
|
16
|
+
export const McpX402PaymentRequiredSchema = PaymentRequiredV1Schema.extend({
|
|
8
17
|
"x402/payment-response": SettleResponseSchema.optional(),
|
|
9
18
|
});
|
|
19
|
+
/** Embed a payment into a JSON-RPC request's `_meta`. MCP is v1-only; throws otherwise. */
|
|
10
20
|
export function buildMessageWithPayment(message, payment, paymentId) {
|
|
11
|
-
|
|
21
|
+
if (payment.protocol !== "x402-v1") {
|
|
22
|
+
throw new Error(`MCP meta requires an x402-v1 authorization; got ${payment.protocol}`);
|
|
23
|
+
}
|
|
24
|
+
const v1Payment = payment.data;
|
|
12
25
|
const base = message;
|
|
13
26
|
const baseParams = base.params || { _meta: {} };
|
|
14
27
|
const baseParamsMeta = baseParams._meta || {};
|
|
@@ -18,7 +31,7 @@ export function buildMessageWithPayment(message, payment, paymentId) {
|
|
|
18
31
|
...baseParams,
|
|
19
32
|
_meta: {
|
|
20
33
|
...baseParamsMeta,
|
|
21
|
-
"x402/payment":
|
|
34
|
+
"x402/payment": v1Payment,
|
|
22
35
|
"ampersend/paymentId": paymentId,
|
|
23
36
|
},
|
|
24
37
|
},
|
|
@@ -66,16 +79,9 @@ export function isMcpX402PaymentRequired(data) {
|
|
|
66
79
|
const result = McpX402PaymentRequiredSchema.safeParse(data);
|
|
67
80
|
return result.success;
|
|
68
81
|
}
|
|
69
|
-
// Type guards and validators
|
|
70
|
-
/**
|
|
71
|
-
* Type guard to check if a value is a valid PaymentRequirements array
|
|
72
|
-
*/
|
|
73
82
|
function isPaymentRequirementsArray(arr) {
|
|
74
83
|
return Array.isArray(arr) && arr.length > 0 && arr.every((req) => req && typeof req === "object" && "scheme" in req);
|
|
75
84
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Type guard to check if a value is a valid X402Response structure
|
|
78
|
-
*/
|
|
79
85
|
function isX402Response(obj) {
|
|
80
86
|
if (!obj || typeof obj !== "object")
|
|
81
87
|
return false;
|
|
@@ -84,10 +90,6 @@ function isX402Response(obj) {
|
|
|
84
90
|
const candidate = obj;
|
|
85
91
|
return typeof candidate.x402Version === "number" && isPaymentRequirementsArray(candidate.accepts);
|
|
86
92
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Type assertion for X402Response with runtime validation.
|
|
89
|
-
* Returns null if the data doesn't match the expected structure.
|
|
90
|
-
*/
|
|
91
93
|
export function asX402Response(obj) {
|
|
92
94
|
return isX402Response(obj) ? obj : null;
|
|
93
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/mcp/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