Skip to content

Commit 875deb7

Browse files
badjerclaude
andcommitted
feat: auto-register X402 + MPP protocol handlers by default
protocolHandlers now defaults to [X402ProtocolHandler, MPPProtocolHandler] instead of empty array. Developers no longer need to manually configure protocol support — all protocols work out of the box. ATXP-MCP doesn't need a handler — it's the native MCP payment flow that runs as the fallback when no protocol handler matches. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b88d870 commit 875deb7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/atxp-client/src/atxpFetcher.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ import {
2222
} from '@atxp/common';
2323
import type { PaymentMaker, ProspectivePayment, ClientConfig, PaymentFailureContext } from './types.js';
2424
import type { ProtocolHandler, ProtocolConfig } from './protocolHandler.js';
25+
import { X402ProtocolHandler } from './x402ProtocolHandler.js';
26+
import { MPPProtocolHandler } from './mppProtocolHandler.js';
27+
28+
/** Default protocol handlers — all supported protocols enabled out of the box.
29+
* TODO: Extract ATXP-MCP into an ATXPProtocolHandler so all three protocols use
30+
* the same ProtocolHandler interface. Currently ATXP-MCP is special-cased in
31+
* handlePaymentRequestError and runs as the fallback when no handler matches. */
32+
const DEFAULT_PROTOCOL_HANDLERS: ProtocolHandler[] = [
33+
new X402ProtocolHandler(),
34+
new MPPProtocolHandler(),
35+
];
2536
import { InsufficientFundsError, ATXPPaymentError } from './errors.js';
2637
import { getIsReactNative, createReactNativeSafeFetch, Destination } from '@atxp/common';
2738
import { McpError } from '@modelcontextprotocol/sdk/types.js';
@@ -110,7 +121,7 @@ export class ATXPFetcher {
110121
onPayment = async () => {},
111122
onPaymentFailure,
112123
onPaymentAttemptFailed,
113-
protocolHandlers = [],
124+
protocolHandlers,
114125
protocolFlag
115126
} = config;
116127
// Use React Native safe fetch if in React Native environment
@@ -132,7 +143,7 @@ export class ATXPFetcher {
132143
this.onPayment = onPayment;
133144
this.onPaymentFailure = onPaymentFailure || this.defaultPaymentFailureHandler;
134145
this.onPaymentAttemptFailed = onPaymentAttemptFailed;
135-
this.protocolHandlers = protocolHandlers;
146+
this.protocolHandlers = protocolHandlers ?? DEFAULT_PROTOCOL_HANDLERS;
136147
this.protocolFlag = protocolFlag;
137148
}
138149

0 commit comments

Comments
 (0)