The @atxp/client package is used to create MCP clients with OAuth authentication and payment processing via ATXP.
This package depends on types and utilities from @atxp/common. All shared types like Account, ClientArgs, AuthorizationData, PaymentData, and error types are documented in the common package.
The OAuth database to use for storing tokens; either a SQLiteOAuthDatabase or RedisOAuthDatabase. If not provided, the tokens will be stored in memory.
Returns an object that can be used to call tools on the MCP server, handling authorization and payment.
CallbacksThe ATXP client provides a callback system to handle authorization and payment events throughout the application lifecycle:
Authorization flow
The authorization callbacks handle the OAuth flow:
onAuthorize - Called when a user successfully completes OAuth authorization
onAuthorizeFailure - Called when authorization fails or is denied
Use onAuthorize to store user session data, update UI state, or initialize user-specific resources. Use onAuthorizeFailure to show appropriate error messages and provide retry options.
Payment flow
The payment callbacks handle the payment processing flow:
onPayment - Called when a payment is successfully processed
onPaymentFailure - Called when a payment fails or is rejected
Callback functions should not throw unhandled exceptions as they may interrupt the payment flow. Always wrap callback logic in try-catch blocks when necessary.
Example usage
Without callbacks
With callbacks
An example showing how to use the ATXP client without callbacks, passing in only the required arguments.
Copy
Ask AI
import { atxpClient } from '@atxp/sdk'import { Account } from '@atxp/common'const client = await atxpClient({ mcpServer: 'https://browse.mcp.atxp.ai/', account: new Account(atxpConnectionString),})
ReturnReturns a Promise<ToolResult> typed object that contains the result of the tool call.Example usage
Copy
Ask AI
import { atxpClient } from '@atxp/sdk'import { Account } from '@atxp/common'// Read the ATXP connection string from the environment variables// Your connection string should look like https://accounts.atxp.ai?connection_token=<random_string>// and can be found in your ATXP account dashboard at https://accounts.atxp.ai/const atxpConnectionString = process.env.ATXP_CONNECTION_STRINGconst client = await atxpClient({ mcpServer: 'https://browse.mcp.atxp.ai/', account: new Account(atxpConnectionString),})const prompt = "What are the top 3 articles by points on https://news.ycombinator.com?";const result = await client.callTool({ name: 'browse_run_task', arguments: { instructions: prompt }});
The ATXP connection string in the format: https://accounts.atxp.ai?connection_token=<token>. This connection string identifies the ATXP account that will be used by the client to pay for MCP server tool calls. You can find your connection string in your ATXP account dashboard at https://accounts.atxp.ai/.
Creates a Base account object that can be used to create a Base client. The baseRPCUrl is the Base RPC URL and the sourceSecretKey is the source secret key for the Base account. You can find your source secret key in your Base account dashboard at https://base.org/.Arguments