+20
-2
@@ -811,4 +811,2 @@ import { PaymentRequired, PaymentPayload, SettleResponse, PaymentRequirements, Network, Price, SchemeNetworkClient } from '@x402/core/types'; | ||
| }; | ||
| /** Extensions to include in 402 payment required responses (e.g., bazaar discovery) */ | ||
| extensions?: Record<string, unknown>; | ||
| /** Hooks for payment lifecycle events */ | ||
@@ -823,2 +821,22 @@ hooks?: { | ||
| }; | ||
| /** | ||
| * x402 extensions to include in the PaymentRequired response. | ||
| * Use this to attach Bazaar discovery metadata so facilitators can index the tool. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { declareDiscoveryExtension } from "@x402/extensions/bazaar"; | ||
| * | ||
| * resource: { url: "mcp://tool/get_weather" }, | ||
| * extensions: declareDiscoveryExtension({ | ||
| * toolName: "get_weather", | ||
| * description: "Get current weather for a city", | ||
| * inputSchema: { | ||
| * properties: { city: { type: "string" } }, | ||
| * required: ["city"], | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| extensions?: Record<string, unknown>; | ||
| } | ||
@@ -825,0 +843,0 @@ /** |
+24
-7
@@ -656,3 +656,3 @@ "use strict"; | ||
| return async (args, extra) => { | ||
| var _a, _b, _c, _d, _e; | ||
| var _a, _b, _c, _d, _e, _f, _g, _h; | ||
| const _meta = extra == null ? void 0 : extra._meta; | ||
@@ -678,4 +678,15 @@ const toolName = ((_b = (_a = config.resource) == null ? void 0 : _a.url) == null ? void 0 : _b.replace("mcp://tool/", "")) || "paid_tool"; | ||
| } | ||
| const resourceInfoForMatch = { | ||
| url: createToolResourceUrl(toolName, (_c = config.resource) == null ? void 0 : _c.url), | ||
| description: ((_d = config.resource) == null ? void 0 : _d.description) || `Tool: ${toolName}`, | ||
| mimeType: ((_e = config.resource) == null ? void 0 : _e.mimeType) || "application/json" | ||
| }; | ||
| const paymentRequiredForMatch = await resourceServer.createPaymentRequiredResponse( | ||
| config.accepts, | ||
| resourceInfoForMatch, | ||
| void 0, | ||
| config.extensions | ||
| ); | ||
| const paymentRequirements = resourceServer.findMatchingRequirements( | ||
| config.accepts, | ||
| paymentRequiredForMatch.accepts, | ||
| paymentPayload | ||
@@ -691,3 +702,8 @@ ); | ||
| } | ||
| const verifyResult = await resourceServer.verifyPayment(paymentPayload, paymentRequirements); | ||
| const extMap = config.extensions ?? {}; | ||
| const verifyResult = await resourceServer.verifyPayment( | ||
| paymentPayload, | ||
| paymentRequirements, | ||
| extMap | ||
| ); | ||
| if (!verifyResult.isValid) { | ||
@@ -707,3 +723,3 @@ return createPaymentRequiredResult( | ||
| }; | ||
| if ((_c = config.hooks) == null ? void 0 : _c.onBeforeExecution) { | ||
| if ((_f = config.hooks) == null ? void 0 : _f.onBeforeExecution) { | ||
| const hookResult = await config.hooks.onBeforeExecution(hookContext); | ||
@@ -724,3 +740,3 @@ if (hookResult === false) { | ||
| }; | ||
| if ((_d = config.hooks) == null ? void 0 : _d.onAfterExecution) { | ||
| if ((_g = config.hooks) == null ? void 0 : _g.onAfterExecution) { | ||
| await config.hooks.onAfterExecution(afterExecContext); | ||
@@ -734,5 +750,6 @@ } | ||
| paymentPayload, | ||
| paymentRequirements | ||
| paymentRequirements, | ||
| extMap | ||
| ); | ||
| if ((_e = config.hooks) == null ? void 0 : _e.onAfterSettlement) { | ||
| if ((_h = config.hooks) == null ? void 0 : _h.onAfterSettlement) { | ||
| const settlementContext = { | ||
@@ -739,0 +756,0 @@ ...hookContext, |
+20
-2
@@ -811,4 +811,2 @@ import { PaymentRequired, PaymentPayload, SettleResponse, PaymentRequirements, Network, Price, SchemeNetworkClient } from '@x402/core/types'; | ||
| }; | ||
| /** Extensions to include in 402 payment required responses (e.g., bazaar discovery) */ | ||
| extensions?: Record<string, unknown>; | ||
| /** Hooks for payment lifecycle events */ | ||
@@ -823,2 +821,22 @@ hooks?: { | ||
| }; | ||
| /** | ||
| * x402 extensions to include in the PaymentRequired response. | ||
| * Use this to attach Bazaar discovery metadata so facilitators can index the tool. | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { declareDiscoveryExtension } from "@x402/extensions/bazaar"; | ||
| * | ||
| * resource: { url: "mcp://tool/get_weather" }, | ||
| * extensions: declareDiscoveryExtension({ | ||
| * toolName: "get_weather", | ||
| * description: "Get current weather for a city", | ||
| * inputSchema: { | ||
| * properties: { city: { type: "string" } }, | ||
| * required: ["city"], | ||
| * }, | ||
| * }) | ||
| * ``` | ||
| */ | ||
| extensions?: Record<string, unknown>; | ||
| } | ||
@@ -825,0 +843,0 @@ /** |
+24
-7
@@ -613,3 +613,3 @@ // src/client/x402MCPClient.ts | ||
| return async (args, extra) => { | ||
| var _a, _b, _c, _d, _e; | ||
| var _a, _b, _c, _d, _e, _f, _g, _h; | ||
| const _meta = extra == null ? void 0 : extra._meta; | ||
@@ -635,4 +635,15 @@ const toolName = ((_b = (_a = config.resource) == null ? void 0 : _a.url) == null ? void 0 : _b.replace("mcp://tool/", "")) || "paid_tool"; | ||
| } | ||
| const resourceInfoForMatch = { | ||
| url: createToolResourceUrl(toolName, (_c = config.resource) == null ? void 0 : _c.url), | ||
| description: ((_d = config.resource) == null ? void 0 : _d.description) || `Tool: ${toolName}`, | ||
| mimeType: ((_e = config.resource) == null ? void 0 : _e.mimeType) || "application/json" | ||
| }; | ||
| const paymentRequiredForMatch = await resourceServer.createPaymentRequiredResponse( | ||
| config.accepts, | ||
| resourceInfoForMatch, | ||
| void 0, | ||
| config.extensions | ||
| ); | ||
| const paymentRequirements = resourceServer.findMatchingRequirements( | ||
| config.accepts, | ||
| paymentRequiredForMatch.accepts, | ||
| paymentPayload | ||
@@ -648,3 +659,8 @@ ); | ||
| } | ||
| const verifyResult = await resourceServer.verifyPayment(paymentPayload, paymentRequirements); | ||
| const extMap = config.extensions ?? {}; | ||
| const verifyResult = await resourceServer.verifyPayment( | ||
| paymentPayload, | ||
| paymentRequirements, | ||
| extMap | ||
| ); | ||
| if (!verifyResult.isValid) { | ||
@@ -664,3 +680,3 @@ return createPaymentRequiredResult( | ||
| }; | ||
| if ((_c = config.hooks) == null ? void 0 : _c.onBeforeExecution) { | ||
| if ((_f = config.hooks) == null ? void 0 : _f.onBeforeExecution) { | ||
| const hookResult = await config.hooks.onBeforeExecution(hookContext); | ||
@@ -681,3 +697,3 @@ if (hookResult === false) { | ||
| }; | ||
| if ((_d = config.hooks) == null ? void 0 : _d.onAfterExecution) { | ||
| if ((_g = config.hooks) == null ? void 0 : _g.onAfterExecution) { | ||
| await config.hooks.onAfterExecution(afterExecContext); | ||
@@ -691,5 +707,6 @@ } | ||
| paymentPayload, | ||
| paymentRequirements | ||
| paymentRequirements, | ||
| extMap | ||
| ); | ||
| if ((_e = config.hooks) == null ? void 0 : _e.onAfterSettlement) { | ||
| if ((_h = config.hooks) == null ? void 0 : _h.onAfterSettlement) { | ||
| const settlementContext = { | ||
@@ -696,0 +713,0 @@ ...hookContext, |
+3
-3
| { | ||
| "name": "@x402/mcp", | ||
| "version": "2.10.0", | ||
| "version": "2.11.0", | ||
| "main": "./dist/cjs/index.js", | ||
@@ -30,3 +30,3 @@ "module": "./dist/esm/index.js", | ||
| "vite": "^6.2.6", | ||
| "@x402/evm": "~2.10.0" | ||
| "@x402/evm": "~2.11.0" | ||
| }, | ||
@@ -36,3 +36,3 @@ "dependencies": { | ||
| "zod": "^3.24.2", | ||
| "@x402/core": "~2.10.0" | ||
| "@x402/core": "~2.11.0" | ||
| }, | ||
@@ -39,0 +39,0 @@ "exports": { |
+1
-1
@@ -1,2 +0,2 @@ | ||
| # @x402/mcp | ||
| # `@x402/mcp` • [](https://www.npmjs.com/package/@x402/mcp) | ||
@@ -3,0 +3,0 @@ MCP (Model Context Protocol) integration for the x402 payment protocol. This package enables paid tool calls in MCP servers and automatic payment handling in MCP clients. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
282721
1.95%2585
2.05%+ Added
- Removed
Updated