mppx 0.9.0 → 0.9.2

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 (61) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +7 -0
  3. package/dist/Errors.d.ts +10 -0
  4. package/dist/Errors.js +12 -0
  5. package/dist/Mcp.d.ts +9 -1
  6. package/dist/Mcp.js +18 -0
  7. package/dist/Method.d.ts +7 -0
  8. package/dist/cli/cli.d.ts +1 -0
  9. package/dist/cli/cli.js +135 -135
  10. package/dist/cli/internal.js +2 -2
  11. package/dist/cli/plugins/evm.js +2 -0
  12. package/dist/cli/plugins/index.d.ts +1 -0
  13. package/dist/cli/plugins/index.js +12 -12
  14. package/dist/cli/plugins/x402.d.ts +3 -0
  15. package/dist/cli/plugins/x402.js +61 -0
  16. package/dist/client/internal/protocols/Mcp.js +2 -1
  17. package/dist/mcp/client/McpClient.js +22 -10
  18. package/dist/mcp/server/Transport.d.ts +2 -2
  19. package/dist/mcp/server/Transport.js +11 -4
  20. package/dist/middlewares/internal/mppx.js +17 -3
  21. package/dist/server/Mppx.d.ts +6 -0
  22. package/dist/server/Mppx.js +75 -6
  23. package/dist/server/Transport.js +8 -15
  24. package/dist/stripe/Methods.d.ts +24 -0
  25. package/dist/stripe/Methods.js +3 -1
  26. package/dist/stripe/client/Charge.d.ts +24 -0
  27. package/dist/stripe/client/Methods.d.ts +24 -0
  28. package/dist/stripe/internal/constants.d.ts +4 -0
  29. package/dist/stripe/internal/constants.js +2 -0
  30. package/dist/stripe/internal/payment-intent.d.ts +16 -0
  31. package/dist/stripe/internal/payment-intent.js +13 -0
  32. package/dist/stripe/internal/types.d.ts +4 -0
  33. package/dist/stripe/server/Charge.d.ts +24 -0
  34. package/dist/stripe/server/Charge.js +31 -10
  35. package/dist/stripe/server/Methods.d.ts +6 -0
  36. package/dist/stripe/server/Methods.js +80 -8
  37. package/dist/stripe/server/internal/hosted-fee-payer.d.ts +10 -0
  38. package/dist/stripe/server/internal/hosted-fee-payer.js +54 -0
  39. package/dist/stripe/server/internal/html.gen.d.ts +1 -1
  40. package/dist/stripe/server/internal/html.gen.js +1 -1
  41. package/dist/stripe/server/internal/record-payment.d.ts +3 -1
  42. package/dist/stripe/server/internal/record-payment.js +33 -5
  43. package/dist/tempo/Tokens.d.ts +13 -0
  44. package/dist/tempo/Tokens.js +13 -0
  45. package/dist/tempo/client/Charge.d.ts +1 -1
  46. package/dist/tempo/client/Charge.js +17 -0
  47. package/dist/tempo/index.d.ts +1 -0
  48. package/dist/tempo/index.js +1 -0
  49. package/dist/tempo/internal/account.d.ts +1 -0
  50. package/dist/tempo/internal/fee-payer.d.ts +1 -1
  51. package/dist/tempo/internal/fee-payer.js +2 -12
  52. package/dist/tempo/internal/fee-token.d.ts +2 -0
  53. package/dist/tempo/internal/fee-token.js +7 -0
  54. package/dist/tempo/internal/remote-fee-payer.d.ts +2 -0
  55. package/dist/tempo/server/internal/html.gen.d.ts +1 -1
  56. package/dist/tempo/server/internal/html.gen.js +1 -1
  57. package/dist/tempo/session/client/SessionManager.js +1 -2
  58. package/dist/tempo/session/server/Session.js +5 -2
  59. package/dist/viem/Client.js +1 -0
  60. package/dist/x402/mcp.js +4 -3
  61. package/package.json +1 -1
@@ -0,0 +1,3 @@
1
+ /** Pays recognized x402 exact EVM challenges with the configured CLI account. */
2
+ export declare function x402(): import("./plugin.js").Plugin;
3
+ //# sourceMappingURL=x402.d.ts.map
@@ -0,0 +1,61 @@
1
+ import * as viemChains from 'viem/chains';
2
+ import { evm as evmMethods, assets as evmAssets } from '../../evm/client/index.js';
3
+ import * as Assets from '../../x402/Assets.js';
4
+ import * as x402_ChallengeBrand from '../../x402/internal/ChallengeBrand.js';
5
+ import { resolveAccount } from '../account.js';
6
+ import { createPlugin } from './plugin.js';
7
+ const knownAssets = [
8
+ ...Object.entries(evmAssets.base),
9
+ ...Object.entries(evmAssets.baseSepolia),
10
+ ...Object.entries(evmAssets.celo),
11
+ ...Object.entries(evmAssets.celoSepolia),
12
+ ];
13
+ /** Pays recognized x402 exact EVM challenges with the configured CLI account. */
14
+ export function x402() {
15
+ return createPlugin({
16
+ method: 'evm',
17
+ supports: isSupportedChallenge,
18
+ async setup({ challenge, options }) {
19
+ const request = challenge.request;
20
+ const chain = request.network ? resolveEvmChain(Assets.toChainId(request.network)) : undefined;
21
+ const known = request.network && request.asset
22
+ ? knownAssets.find(([, asset]) => Assets.matches(asset, request.asset, request.network))
23
+ : undefined;
24
+ const name = request.extra?.name;
25
+ const version = request.extra?.version;
26
+ const currency = request.asset && request.network && typeof name === 'string' && typeof version === 'string'
27
+ ? Assets.define({
28
+ address: request.asset,
29
+ decimals: known?.[1].decimals ?? 6,
30
+ network: request.network,
31
+ transfer: { name, type: 'eip3009', version },
32
+ })
33
+ : undefined;
34
+ const account = await resolveAccount(options.account);
35
+ return {
36
+ explorerUrl: chain?.blockExplorers?.default?.url,
37
+ methods: [...evmMethods({ account, ...(currency && { currencies: [currency] }) })],
38
+ tokenDecimals: known?.[1].decimals ?? 6,
39
+ tokenSymbol: known?.[0] ?? '',
40
+ };
41
+ },
42
+ });
43
+ }
44
+ /** Returns whether the CLI can create an x402 credential for this challenge. */
45
+ function isSupportedChallenge(challenge) {
46
+ if (!x402_ChallengeBrand.is(challenge))
47
+ return false;
48
+ const request = challenge.request;
49
+ const transfer = request.extra;
50
+ const transferMethod = transfer?.assetTransferMethod;
51
+ return (request.scheme === 'exact' &&
52
+ typeof request.asset === 'string' &&
53
+ typeof request.network === 'string' &&
54
+ typeof transfer?.name === 'string' &&
55
+ typeof transfer?.version === 'string' &&
56
+ (transferMethod === undefined || transferMethod === 'eip3009'));
57
+ }
58
+ function resolveEvmChain(chainId) {
59
+ return Object.values(viemChains).find((chain) => chain.id === chainId);
60
+ }
61
+ //# sourceMappingURL=x402.js.map
@@ -77,7 +77,8 @@ export function paymentRequiredData(message) {
77
77
  if (!message)
78
78
  return undefined;
79
79
  if ('error' in message) {
80
- if (message.error?.code !== Mcp.paymentRequiredCode)
80
+ if (message.error?.code !== Mcp.paymentRequiredCode &&
81
+ message.error?.code !== Mcp.paymentVerificationFailedCode)
81
82
  return undefined;
82
83
  return paymentRequiredDataFromValue(message.error.data);
83
84
  }
@@ -5,6 +5,7 @@ import * as AcceptPayment from '../../internal/AcceptPayment.js';
5
5
  import * as core_Mcp from '../../Mcp.js';
6
6
  import * as z from '../../zod.js';
7
7
  const MPPX_MCP_CLIENT_WRAPPER = Symbol.for('mppx.mcp.client.wrapper');
8
+ const maxPaymentAttempts = 3;
8
9
  /**
9
10
  * Adds automatic payment handling to an MCP SDK client.
10
11
  *
@@ -80,7 +81,8 @@ export function isPaymentRequiredError(error) {
80
81
  return false;
81
82
  if (!('code' in error) || !('message' in error))
82
83
  return false;
83
- if (error.code !== core_Mcp.paymentRequiredCode)
84
+ const code = error.code;
85
+ if (code !== core_Mcp.paymentRequiredCode && code !== core_Mcp.paymentVerificationFailedCode)
84
86
  return false;
85
87
  return isPaymentRequiredData(error.data);
86
88
  }
@@ -98,7 +100,7 @@ async function createCredential(challenge, config) {
98
100
  function createPaymentAwareCallTool(callTool, config) {
99
101
  const methods = config.methods.flat();
100
102
  const paymentPreferences = AcceptPayment.resolve(methods, config.paymentPreferences);
101
- const retryWithPayment = async (params, call, paymentRequired, cause) => {
103
+ const retryWithPayment = async (params, call, paymentRequired, cause, attemptsRemaining = maxPaymentAttempts) => {
102
104
  const challenges = paymentRequired.challenges;
103
105
  const candidates = AcceptPayment.selectChallengeCandidates(challenges, methods, paymentPreferences.entries);
104
106
  const orderedCandidates = config.orderChallenges
@@ -122,14 +124,24 @@ function createPaymentAwareCallTool(callTool, config) {
122
124
  methods,
123
125
  });
124
126
  const parsed = Credential.deserialize(credential);
125
- const retryResult = await callTool({
126
- ...params,
127
- _meta: {
128
- ...params._meta,
129
- [core_Mcp.credentialMetaKey]: parsed,
130
- },
131
- }, call.resultSchema, call.requestOptions);
132
- return withReceipt(retryResult);
127
+ try {
128
+ const retryResult = await callTool({
129
+ ...params,
130
+ _meta: {
131
+ ...params._meta,
132
+ [core_Mcp.credentialMetaKey]: parsed,
133
+ },
134
+ }, call.resultSchema, call.requestOptions);
135
+ const nextPaymentRequired = getPaymentRequiredMeta(retryResult);
136
+ if (nextPaymentRequired && attemptsRemaining > 1)
137
+ return retryWithPayment(params, call, nextPaymentRequired, retryResult, attemptsRemaining - 1);
138
+ return withReceipt(retryResult);
139
+ }
140
+ catch (error) {
141
+ if (!isPaymentRequiredError(error) || attemptsRemaining <= 1)
142
+ throw error;
143
+ return retryWithPayment(params, call, error.data, error, attemptsRemaining - 1);
144
+ }
133
145
  };
134
146
  return async (params, call) => {
135
147
  try {
@@ -1,5 +1,5 @@
1
1
  import type { CallToolResult, McpError } from '@modelcontextprotocol/sdk/types.js';
2
- import type * as Credential from '../../Credential.js';
2
+ import * as Credential from '../../Credential.js';
3
3
  import * as core_Mcp from '../../Mcp.js';
4
4
  import * as Transport from '../../server/Transport.js';
5
5
  /**
@@ -18,7 +18,7 @@ export type McpSdk = Transport.Transport<Extra, McpError, CallToolResult>;
18
18
  * MCP SDK transport for server-side payment handling with `@modelcontextprotocol/sdk`.
19
19
  *
20
20
  * - Reads credentials from `_meta["org.paymentauth/credential"]`
21
- * - Issues challenges as `McpError` with code `-32042` and challenge in `error.data`
21
+ * - Maps payment errors to their specification-defined JSON-RPC codes
22
22
  * - Attaches receipts via `_meta["org.paymentauth/receipt"]` on tool results
23
23
  *
24
24
  * @example
@@ -1,3 +1,4 @@
1
+ import * as Credential from '../../Credential.js';
1
2
  import * as core_Mcp from '../../Mcp.js';
2
3
  import * as Transport from '../../server/Transport.js';
3
4
  import * as McpCredential from '../internal/Credential.js';
@@ -5,7 +6,7 @@ import * as McpCredential from '../internal/Credential.js';
5
6
  * MCP SDK transport for server-side payment handling with `@modelcontextprotocol/sdk`.
6
7
  *
7
8
  * - Reads credentials from `_meta["org.paymentauth/credential"]`
8
- * - Issues challenges as `McpError` with code `-32042` and challenge in `error.data`
9
+ * - Maps payment errors to their specification-defined JSON-RPC codes
9
10
  * - Attaches receipts via `_meta["org.paymentauth/receipt"]` on tool results
10
11
  *
11
12
  * @example
@@ -41,7 +42,13 @@ export function mcpSdk() {
41
42
  };
42
43
  },
43
44
  getCredential(extra) {
44
- return McpCredential.parse(extra._meta?.[core_Mcp.credentialMetaKey])?.value ?? null;
45
+ const value = extra._meta?.[core_Mcp.credentialMetaKey];
46
+ if (value === undefined)
47
+ return null;
48
+ const parsed = McpCredential.parse(value);
49
+ if (!parsed)
50
+ throw new Credential.InvalidCredentialEncodingError();
51
+ return parsed.value;
45
52
  },
46
53
  async respondChallenge({ challenge, error }) {
47
54
  if (!McpErrorClass) {
@@ -55,8 +62,8 @@ export function mcpSdk() {
55
62
  throw err;
56
63
  }
57
64
  }
58
- return new McpErrorClass(core_Mcp.paymentRequiredCode, error?.message ?? 'Payment Required', {
59
- httpStatus: 402,
65
+ return new McpErrorClass(core_Mcp.errorCode(error), error?.message ?? 'Payment Required', {
66
+ httpStatus: error?.status ?? 402,
60
67
  challenges: [challenge],
61
68
  ...(error && { problem: error.toProblemDetails(challenge.id) }),
62
69
  });
@@ -21,9 +21,23 @@ export function wrap(mppx, wrapper) {
21
21
  };
22
22
  Object.assign(wrapWithMeta, methodFn);
23
23
  result[key] = wrapWithMeta;
24
- // Also set shorthand intent key if Mppx registered it (no collision)
25
- if (!reservedMppxKeys.has(mi.intent) && mppx[mi.intent])
26
- result[mi.intent] = wrapWithMeta;
24
+ // Also set shorthand intent key, using the core-composed handler on collisions.
25
+ if (!reservedMppxKeys.has(mi.intent) && mppx[mi.intent]) {
26
+ const intentFn = mppx[mi.intent];
27
+ if (intentFn === methodFn)
28
+ result[mi.intent] = wrapWithMeta;
29
+ else {
30
+ const wrapIntentWithMeta = (options) => {
31
+ const configured = intentFn(options);
32
+ const handler = wrapper(intentFn, options);
33
+ if (configured._internal)
34
+ handler._internal = configured._internal;
35
+ return handler;
36
+ };
37
+ Object.assign(wrapIntentWithMeta, intentFn);
38
+ result[mi.intent] = wrapIntentWithMeta;
39
+ }
40
+ }
27
41
  // Build nested handlers: wrapped.tempo.charge(...)
28
42
  if (!result[mi.name] || typeof result[mi.name] !== 'object')
29
43
  result[mi.name] = {};
@@ -99,7 +99,13 @@ export type PaymentSuccessContext<method extends Method.Method = Method.Method,
99
99
  input?: Transport.InputOf<transport> | undefined;
100
100
  method: ServerMethodDescriptor<method>;
101
101
  receipt: Receipt.Receipt;
102
+ /** Canonical request represented by the challenge. */
102
103
  request: z.output<method['schema']['request']>;
104
+ /**
105
+ * Resolved method input before request-schema output transforms. Absent during
106
+ * standalone credential verification when no route options are supplied.
107
+ */
108
+ requestInput?: z.input<method['schema']['request']> | undefined;
103
109
  }>;
104
110
  /** Options for standalone credential verification. */
105
111
  export type VerifyCredentialOptions = {
@@ -73,6 +73,7 @@ export function create(config) {
73
73
  input: ctx.input,
74
74
  receipt: ctx.receipt,
75
75
  request: ctx.request,
76
+ ...(ctx.requestInput !== undefined && { requestInput: ctx.requestInput }),
76
77
  });
77
78
  }
78
79
  }));
@@ -280,6 +281,7 @@ export function create(config) {
280
281
  parsedCredential,
281
282
  parsedRequest,
282
283
  request,
284
+ requestInput: shouldValidateRoute ? request : undefined,
283
285
  };
284
286
  }
285
287
  async function validateCredentialFn(input, options) {
@@ -293,7 +295,7 @@ export function create(config) {
293
295
  // broadcastCredential: single-call end-to-end validation and broadcast
294
296
  async function broadcastCredentialFn(input, options) {
295
297
  const prepared = await prepareStandaloneCredential(input, options, { emitFailures: true });
296
- const { method: mi, parsedCredential, parsedRequest, request, envelope } = prepared;
298
+ const { method: mi, parsedCredential, parsedRequest, request, requestInput, envelope, } = prepared;
297
299
  const emitStandalonePaymentFailed = async (parameters) => {
298
300
  await serverEvents.emit('payment.failed', createPaymentFailedContext({
299
301
  capturedRequest: options?.capturedRequest,
@@ -313,7 +315,7 @@ export function create(config) {
313
315
  receipt = await broadcast({ credential: parsedCredential, envelope, request });
314
316
  }
315
317
  catch (e) {
316
- const error = e instanceof Errors.PaymentError ? e : new Errors.VerificationFailedError();
318
+ const error = e instanceof Errors.PaymentError ? e : new Errors.InternalPaymentError();
317
319
  await emitStandalonePaymentFailed({
318
320
  challenge: prepared.credential.challenge,
319
321
  credential: parsedCredential,
@@ -331,6 +333,7 @@ export function create(config) {
331
333
  method: mi,
332
334
  receipt,
333
335
  request: parsedRequest,
336
+ ...(requestInput !== undefined && { requestInput }),
334
337
  }));
335
338
  return receipt;
336
339
  }
@@ -548,7 +551,11 @@ function createMethodFn(parameters) {
548
551
  // Credential was provided but malformed
549
552
  if (credentialError) {
550
553
  const reason = getSafeCredentialReason(credentialError);
551
- const error = new Errors.MalformedCredentialError(reason ? { reason } : {});
554
+ const error = credentialError instanceof Errors.PaymentError
555
+ ? credentialError
556
+ : reason
557
+ ? new Errors.MalformedCredentialError({ reason })
558
+ : new Errors.InternalPaymentError();
552
559
  await emitPaymentFailed({
553
560
  challenge,
554
561
  credential: null,
@@ -610,6 +617,7 @@ function createMethodFn(parameters) {
610
617
  method,
611
618
  receipt: authorized.receipt,
612
619
  request: parsedRequest,
620
+ requestInput: request,
613
621
  }));
614
622
  return success(authorized.receipt, {
615
623
  managementResponse: authorized.response,
@@ -619,7 +627,7 @@ function createMethodFn(parameters) {
619
627
  catch (e) {
620
628
  if (!(e instanceof Errors.PaymentError))
621
629
  console.error('mppx: internal authorization error', e);
622
- const error = e instanceof Errors.PaymentError ? e : new Errors.VerificationFailedError();
630
+ const error = e instanceof Errors.PaymentError ? e : new Errors.InternalPaymentError();
623
631
  await emitPaymentFailed({
624
632
  challenge,
625
633
  credential: null,
@@ -792,7 +800,7 @@ function createMethodFn(parameters) {
792
800
  catch (e) {
793
801
  if (!(e instanceof Errors.PaymentError))
794
802
  console.error('mppx: internal verification error', e);
795
- const error = e instanceof Errors.PaymentError ? e : new Errors.VerificationFailedError();
803
+ const error = e instanceof Errors.PaymentError ? e : new Errors.InternalPaymentError();
796
804
  await emitPaymentFailed({
797
805
  challenge,
798
806
  credential: parsedCredential,
@@ -832,6 +840,7 @@ function createMethodFn(parameters) {
832
840
  method,
833
841
  receipt: receiptData,
834
842
  request: parsedRequest,
843
+ requestInput: request,
835
844
  }));
836
845
  return success(receiptData, {
837
846
  challengeId: credential.challenge.id,
@@ -991,6 +1000,9 @@ function createPaymentSuccessContext(parameters) {
991
1000
  method: snapshotMethod(parameters.method),
992
1001
  receipt: snapshotValue(parameters.receipt),
993
1002
  request: snapshotValue(parameters.request),
1003
+ ...(parameters.requestInput !== undefined && {
1004
+ requestInput: snapshotValue(parameters.requestInput),
1005
+ }),
994
1006
  });
995
1007
  }
996
1008
  function snapshotMethod(method) {
@@ -1035,8 +1047,65 @@ function snapshotValue(value) {
1035
1047
  return freezeSnapshot(structuredClone(value));
1036
1048
  }
1037
1049
  catch {
1038
- return freezeSnapshot(value);
1050
+ return freezeSnapshot(cloneSnapshotFallback(value));
1051
+ }
1052
+ }
1053
+ /**
1054
+ * Copies object containers when `structuredClone` rejects callable values.
1055
+ * Functions remain callable references, while their containing request data is
1056
+ * detached so snapshot freezing and nested writes cannot affect hook-owned
1057
+ * objects.
1058
+ */
1059
+ function cloneSnapshotFallback(value, seen = new WeakMap()) {
1060
+ if (!value || typeof value !== 'object')
1061
+ return value;
1062
+ const existing = seen.get(value);
1063
+ if (existing)
1064
+ return existing;
1065
+ if (value instanceof Date)
1066
+ return new Date(value);
1067
+ if (value instanceof RegExp)
1068
+ return new RegExp(value.source, value.flags);
1069
+ if (value instanceof URL)
1070
+ return new URL(value);
1071
+ if (value instanceof Headers)
1072
+ return new Headers(value);
1073
+ if (value instanceof ArrayBuffer)
1074
+ return value.slice(0);
1075
+ if (ArrayBuffer.isView(value)) {
1076
+ const buffer = new Uint8Array(value.buffer, value.byteOffset, value.byteLength).slice().buffer;
1077
+ if (value instanceof DataView)
1078
+ return new DataView(buffer);
1079
+ const Constructor = value.constructor;
1080
+ return new Constructor(buffer);
1081
+ }
1082
+ if (value instanceof Map) {
1083
+ const snapshot = new Map();
1084
+ seen.set(value, snapshot);
1085
+ for (const [key, entry] of value)
1086
+ snapshot.set(cloneSnapshotFallback(key, seen), cloneSnapshotFallback(entry, seen));
1087
+ return snapshot;
1088
+ }
1089
+ if (value instanceof Set) {
1090
+ const snapshot = new Set();
1091
+ seen.set(value, snapshot);
1092
+ for (const entry of value)
1093
+ snapshot.add(cloneSnapshotFallback(entry, seen));
1094
+ return snapshot;
1095
+ }
1096
+ const snapshot = Array.isArray(value) ? [] : Object.create(Object.getPrototypeOf(value));
1097
+ seen.set(value, snapshot);
1098
+ for (const key of Reflect.ownKeys(value)) {
1099
+ if (Array.isArray(value) && key === 'length')
1100
+ continue;
1101
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
1102
+ if (!descriptor)
1103
+ continue;
1104
+ if ('value' in descriptor)
1105
+ descriptor.value = cloneSnapshotFallback(descriptor.value, seen);
1106
+ Object.defineProperty(snapshot, key, descriptor);
1039
1107
  }
1108
+ return snapshot;
1040
1109
  }
1041
1110
  function snapshotInputProperty(input) {
1042
1111
  if (input === undefined)
@@ -1,8 +1,8 @@
1
1
  import * as Challenge from '../Challenge.js';
2
2
  import * as Constants from '../Constants.js';
3
3
  import * as Credential from '../Credential.js';
4
- import * as Errors from '../Errors.js';
5
4
  import * as core_Mcp from '../Mcp.js';
5
+ import * as McpCredential from '../mcp/internal/Credential.js';
6
6
  import * as Receipt from '../Receipt.js';
7
7
  import * as Html from './internal/html/config.js';
8
8
  import { serviceWorker } from './internal/html/serviceWorker.gen.js';
@@ -147,17 +147,20 @@ export function mcp() {
147
147
  },
148
148
  getCredential(request) {
149
149
  const meta = request.params?._meta;
150
- const credential = meta?.[core_Mcp.credentialMetaKey];
151
- if (!credential)
150
+ const value = meta?.[core_Mcp.credentialMetaKey];
151
+ if (value === undefined)
152
152
  return null;
153
- return credential;
153
+ const parsed = McpCredential.parse(value);
154
+ if (!parsed)
155
+ throw new Credential.InvalidCredentialEncodingError();
156
+ return parsed.value;
154
157
  },
155
158
  respondChallenge({ challenge, input, error }) {
156
159
  return {
157
160
  jsonrpc: '2.0',
158
161
  id: input.id,
159
162
  error: {
160
- code: mcpErrorCode(error),
163
+ code: core_Mcp.errorCode(error),
161
164
  message: error?.message ?? 'Payment Required',
162
165
  data: {
163
166
  httpStatus: error?.status ?? 402,
@@ -187,16 +190,6 @@ export function mcp() {
187
190
  },
188
191
  });
189
192
  }
190
- /** @internal */
191
- function mcpErrorCode(error) {
192
- if (!error)
193
- return core_Mcp.paymentRequiredCode;
194
- if (error instanceof Errors.MalformedCredentialError)
195
- return -32602;
196
- if (error instanceof Errors.PaymentRequiredError)
197
- return core_Mcp.paymentRequiredCode;
198
- return core_Mcp.paymentVerificationFailedCode;
199
- }
200
193
  export function safeUrl(url) {
201
194
  try {
202
195
  if (url instanceof URL)
@@ -22,6 +22,18 @@ export declare const charge: {
22
22
  externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
23
23
  metadata: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
24
24
  networkId: z.ZodMiniString<string>;
25
+ paymentIntentOptions: z.ZodMiniOptional<z.ZodMiniObject<{
26
+ customer: z.ZodMiniOptional<z.ZodMiniString<string>>;
27
+ hooks: z.ZodMiniOptional<z.ZodMiniObject<{
28
+ inputs: z.ZodMiniObject<{
29
+ tax: z.ZodMiniObject<{
30
+ calculation: z.ZodMiniString<string>;
31
+ }, z.core.$strip>;
32
+ }, z.core.$strip>;
33
+ }, z.core.$strip>>;
34
+ metadata: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
35
+ receipt_email: z.ZodMiniOptional<z.ZodMiniString<string>>;
36
+ }, z.core.$strip>>;
25
37
  paymentMethodTypes: z.ZodMiniArray<z.ZodMiniString<string>>;
26
38
  recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
27
39
  }, z.core.$strip>, z.ZodMiniTransform<{
@@ -43,6 +55,18 @@ export declare const charge: {
43
55
  externalId?: string | undefined;
44
56
  metadata?: Record<string, string> | undefined;
45
57
  networkId: string;
58
+ paymentIntentOptions?: {
59
+ customer?: string | undefined;
60
+ hooks?: {
61
+ inputs: {
62
+ tax: {
63
+ calculation: string;
64
+ };
65
+ };
66
+ } | undefined;
67
+ metadata?: Record<string, string> | undefined;
68
+ receipt_email?: string | undefined;
69
+ } | undefined;
46
70
  paymentMethodTypes: string[];
47
71
  recipient?: string | undefined;
48
72
  }>>;
@@ -1,6 +1,7 @@
1
1
  import { parseUnits } from 'viem';
2
2
  import * as Method from '../Method.js';
3
3
  import * as z from '../zod.js';
4
+ import * as PaymentIntent from './internal/payment-intent.js';
4
5
  /**
5
6
  * Stripe charge intent for one-time payments via Shared Payment Tokens (SPTs).
6
7
  *
@@ -24,9 +25,10 @@ export const charge = Method.from({
24
25
  externalId: z.optional(z.string()),
25
26
  metadata: z.optional(z.record(z.string(), z.string())),
26
27
  networkId: z.string(),
28
+ paymentIntentOptions: z.optional(PaymentIntent.Schema),
27
29
  paymentMethodTypes: z.array(z.string()).check(z.minLength(1)),
28
30
  recipient: z.optional(z.string()),
29
- }), z.transform(({ amount, decimals, metadata, networkId, paymentMethodTypes, ...rest }) => ({
31
+ }), z.transform(({ amount, decimals, metadata, networkId, paymentIntentOptions: _, paymentMethodTypes, ...rest }) => ({
30
32
  ...rest,
31
33
  amount: parseUnits(amount, decimals).toString(),
32
34
  methodDetails: {
@@ -55,6 +55,18 @@ export declare function charge(parameters: charge.Parameters): Method.Client<{
55
55
  externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
56
56
  metadata: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
57
57
  networkId: z.ZodMiniString<string>;
58
+ paymentIntentOptions: z.ZodMiniOptional<z.ZodMiniObject<{
59
+ customer: z.ZodMiniOptional<z.ZodMiniString<string>>;
60
+ hooks: z.ZodMiniOptional<z.ZodMiniObject<{
61
+ inputs: z.ZodMiniObject<{
62
+ tax: z.ZodMiniObject<{
63
+ calculation: z.ZodMiniString<string>;
64
+ }, z.core.$strip>;
65
+ }, z.core.$strip>;
66
+ }, z.core.$strip>>;
67
+ metadata: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
68
+ receipt_email: z.ZodMiniOptional<z.ZodMiniString<string>>;
69
+ }, z.core.$strip>>;
58
70
  paymentMethodTypes: z.ZodMiniArray<z.ZodMiniString<string>>;
59
71
  recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
60
72
  }, z.core.$strip>, z.ZodMiniTransform<{
@@ -76,6 +88,18 @@ export declare function charge(parameters: charge.Parameters): Method.Client<{
76
88
  externalId?: string | undefined;
77
89
  metadata?: Record<string, string> | undefined;
78
90
  networkId: string;
91
+ paymentIntentOptions?: {
92
+ customer?: string | undefined;
93
+ hooks?: {
94
+ inputs: {
95
+ tax: {
96
+ calculation: string;
97
+ };
98
+ };
99
+ } | undefined;
100
+ metadata?: Record<string, string> | undefined;
101
+ receipt_email?: string | undefined;
102
+ } | undefined;
79
103
  paymentMethodTypes: string[];
80
104
  recipient?: string | undefined;
81
105
  }>>;
@@ -42,6 +42,18 @@ export declare function stripe(parameters: stripe.Parameters): readonly [import(
42
42
  externalId: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
43
43
  metadata: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniRecord<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniString<string>>>;
44
44
  networkId: import("zod/mini").ZodMiniString<string>;
45
+ paymentIntentOptions: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniObject<{
46
+ customer: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
47
+ hooks: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniObject<{
48
+ inputs: import("zod/mini").ZodMiniObject<{
49
+ tax: import("zod/mini").ZodMiniObject<{
50
+ calculation: import("zod/mini").ZodMiniString<string>;
51
+ }, import("zod/v4/core").$strip>;
52
+ }, import("zod/v4/core").$strip>;
53
+ }, import("zod/v4/core").$strip>>;
54
+ metadata: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniRecord<import("zod/mini").ZodMiniString<string>, import("zod/mini").ZodMiniString<string>>>;
55
+ receipt_email: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
56
+ }, import("zod/v4/core").$strip>>;
45
57
  paymentMethodTypes: import("zod/mini").ZodMiniArray<import("zod/mini").ZodMiniString<string>>;
46
58
  recipient: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
47
59
  }, import("zod/v4/core").$strip>, import("zod/mini").ZodMiniTransform<{
@@ -63,6 +75,18 @@ export declare function stripe(parameters: stripe.Parameters): readonly [import(
63
75
  externalId?: string | undefined;
64
76
  metadata?: Record<string, string> | undefined;
65
77
  networkId: string;
78
+ paymentIntentOptions?: {
79
+ customer?: string | undefined;
80
+ hooks?: {
81
+ inputs: {
82
+ tax: {
83
+ calculation: string;
84
+ };
85
+ };
86
+ } | undefined;
87
+ metadata?: Record<string, string> | undefined;
88
+ receipt_email?: string | undefined;
89
+ } | undefined;
66
90
  paymentMethodTypes: string[];
67
91
  recipient?: string | undefined;
68
92
  }>>;
@@ -5,4 +5,8 @@
5
5
  * Bump this when upgrading to a newer Stripe API version.
6
6
  */
7
7
  export declare const stripePreviewVersion = "2026-07-29.preview";
8
+ /** Metadata identifying a Stripe PaymentIntent as a machine payment. */
9
+ export declare const machinePaymentMetadata: {
10
+ readonly machine_payment: 'true';
11
+ };
8
12
  //# sourceMappingURL=constants.d.ts.map
@@ -5,4 +5,6 @@
5
5
  * Bump this when upgrading to a newer Stripe API version.
6
6
  */
7
7
  export const stripePreviewVersion = '2026-07-29.preview';
8
+ /** Metadata identifying a Stripe PaymentIntent as a machine payment. */
9
+ export const machinePaymentMetadata = { machine_payment: 'true' };
8
10
  //# sourceMappingURL=constants.js.map
@@ -0,0 +1,16 @@
1
+ import * as z from '../../zod.js';
2
+ /** Stripe PaymentIntent options accepted only by server-side method input. */
3
+ export declare const Schema: z.ZodMiniObject<{
4
+ customer: z.ZodMiniOptional<z.ZodMiniString<string>>;
5
+ hooks: z.ZodMiniOptional<z.ZodMiniObject<{
6
+ inputs: z.ZodMiniObject<{
7
+ tax: z.ZodMiniObject<{
8
+ calculation: z.ZodMiniString<string>;
9
+ }, z.core.$strip>;
10
+ }, z.core.$strip>;
11
+ }, z.core.$strip>>;
12
+ metadata: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
13
+ receipt_email: z.ZodMiniOptional<z.ZodMiniString<string>>;
14
+ }, z.core.$strip>;
15
+ export type Options = z.infer<typeof Schema>;
16
+ //# sourceMappingURL=payment-intent.d.ts.map
@@ -0,0 +1,13 @@
1
+ import * as z from '../../zod.js';
2
+ /** Stripe PaymentIntent options accepted only by server-side method input. */
3
+ export const Schema = z.object({
4
+ customer: z.optional(z.string().check(z.minLength(1))),
5
+ hooks: z.optional(z.object({
6
+ inputs: z.object({
7
+ tax: z.object({ calculation: z.string().check(z.minLength(1)) }),
8
+ }),
9
+ })),
10
+ metadata: z.optional(z.record(z.string(), z.string())),
11
+ receipt_email: z.optional(z.string().check(z.minLength(1))),
12
+ });
13
+ //# sourceMappingURL=payment-intent.js.map
@@ -6,6 +6,10 @@ import * as StripeJsTypes from '../../stripe/server/internal/html/types.js';
6
6
  * Uses loose signatures so any Stripe SDK version is assignable.
7
7
  */
8
8
  export type StripeClient = {
9
+ /** Stripe-node request transport used for hosted fee-payer requests. */
10
+ _requestSender?: {
11
+ _request(...args: any[]): void;
12
+ } | undefined;
9
13
  paymentIntents: {
10
14
  create(...args: any[]): Promise<{
11
15
  id: string;