Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/atxp-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atxp/client",
"version": "0.11.10",
"version": "0.11.12",
"description": "ATXP Client - MCP client with OAuth authentication and payment processing",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -33,8 +33,8 @@
"pack:dry": "npm pack --dry-run"
},
"dependencies": {
"@atxp/common": "0.11.10",
"@atxp/mpp": "0.11.10",
"@atxp/common": "0.11.11",
"@atxp/mpp": "0.11.11",
"@modelcontextprotocol/sdk": "^1.15.0",
"@x402/core": "^2.9.0",
"@x402/evm": "^2.9.0",
Expand Down
11 changes: 9 additions & 2 deletions packages/atxp-client/src/atxpAccountHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ describe('ATXPAccountHandler', () => {
});

describe('handlePaymentChallenge', () => {
it('delegates to account.authorize() and retries with payment header', async () => {
it('delegates to account.authorize() and retries with payment and lifecycle headers', async () => {
const authorize = vi.fn().mockResolvedValue({ protocol: 'atxp', credential: '{"token":"abc"}' });
const account = createMockAccount({ authorize });
const retryResponse = new Response('paid', { status: 200 });
const fetchFn = vi.fn().mockResolvedValue(retryResponse);
const config = createMockConfig({ account, fetchFn });

const response = make402Response({ chargeAmount: '0.01' });
const response = make402Response({
chargeAmount: '0.01',
paymentRequestId: 'pr_lifecycle_123',
});
const result = await handler.handlePaymentChallenge(
response,
{ url: 'https://example.com/api' },
Expand All @@ -77,6 +80,10 @@ describe('ATXPAccountHandler', () => {
}),
);
expect(fetchFn).toHaveBeenCalledTimes(1);
const retryInit = fetchFn.mock.calls[0][1] as RequestInit;
const retryHeaders = retryInit.headers as Headers;
expect(retryHeaders.get('X-ATXP-PAYMENT')).toBe('{"token":"abc"}');
expect(retryHeaders.get('X-ATXP-Payment-Request-Id')).toBe('pr_lifecycle_123');
expect(result).toBe(retryResponse);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/atxp-client/src/atxpAccountHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export class ATXPAccountHandler implements ProtocolHandler {

// Map the returned protocol to the correct HTTP header
const retryHeaders = buildPaymentHeaders(result, originalRequest.init?.headers);
const paymentRequestId = challengeData.paymentRequestId;
if (typeof paymentRequestId === 'string' && paymentRequestId) {
retryHeaders.set('X-ATXP-Payment-Request-Id', paymentRequestId);
}
const retryInit: RequestInit = { ...originalRequest.init, headers: retryHeaders };

return fetchFn(originalRequest.url, retryInit);
Expand Down
Loading