@agentauth/mcp
Version:
Universal payment-enabled MCP gateway for AI agents with native x402 protocol support.
138 lines • 4.65 kB
TypeScript
import type { WalletService } from '../wallet/walletService.js';
/**
* AgentPay v0.0.2 HTTP Headers
*/
export declare const AGENTPAY_HEADERS: {
readonly AUTHORIZATION: "x-agentpay-authorization";
readonly FROM: "x-agentpay-from";
readonly AMOUNT: "x-agentpay-amount";
readonly TOKEN: "x-agentpay-token";
readonly CHAIN: "x-agentpay-chain";
readonly CHAIN_ID: "x-agentpay-chain-id";
readonly RECIPIENT: "x-agentpay-recipient";
readonly DESCRIPTION: "x-agentpay-description";
readonly RECEIPT: "x-agentpay-receipt";
readonly ERROR: "x-agentpay-error";
};
/**
* Payment Required Response (HTTP 402 equivalent)
*/
export interface PaymentRequiredResponse {
error: 'payment_required';
code?: 402;
message: string;
amount: string;
currency: string;
description?: string;
headers?: Record<string, string>;
transaction?: TransactionTemplate;
}
/**
* Transaction Template for signing
*/
export interface TransactionTemplate {
to: string;
data: string;
value: string;
chainId: number;
gasLimit: string;
x402Requirement?: any;
}
/**
* Payment Protocol Interface - defines what any payment protocol must implement
*/
export interface PaymentProtocol {
/**
* Check if a response requires payment
*/
isPaymentRequired(response: any): boolean;
/**
* Extract payment details from response
*/
extractPaymentDetails(response: any): PaymentRequiredResponse | null;
/**
* Sign a payment transaction
*/
signPaymentTransaction(template: TransactionTemplate, walletService: WalletService): Promise<{
signedTx: string;
from: string;
}>;
/**
* Create payment authorization headers
*/
createAuthorizationHeaders(signedTx: string, from: string, walletService?: WalletService, requirement?: any): Promise<Record<string, string>> | Record<string, string>;
/**
* Format payment details for user display (UX layer)
* Now async to support real-time gas estimation during preview
*/
formatForUser(paymentDetails: PaymentRequiredResponse, walletBalances?: {
usdc: string;
eth: string;
}, walletService?: any): Promise<string>;
/**
* Format instructions for agent (UX layer)
*/
formatForAgent(paymentDetails: PaymentRequiredResponse, originalParams?: any): string;
/**
* Fix potentially truncated transaction data (protocol-specific handling)
*/
fixTruncatedTransactionData(template: TransactionTemplate): TransactionTemplate;
/**
* Validate transaction template structure and content
*/
validateTransactionTemplate(template: TransactionTemplate): {
valid: boolean;
errors: string[];
};
}
/**
* AgentPay v0.0.2 Protocol Implementation
*/
export declare class AgentPayV002Protocol implements PaymentProtocol {
/**
* Lightweight detection of AgentPay payment requirements
* Excludes x402 responses to maintain protocol priority
*/
isPaymentRequired(response: any): boolean;
/**
* Extract payment details from a payment required response
*/
extractPaymentDetails(response: any): PaymentRequiredResponse | null;
/**
* Sign a payment transaction using the wallet service
*/
signPaymentTransaction(template: TransactionTemplate, walletService: WalletService): Promise<{
signedTx: string;
from: string;
}>;
/**
* Create authorization headers for the payment
*/
createAuthorizationHeaders(signedTx: string, from: string): Record<string, string>;
/**
* Format payment details for user display with real-time gas estimation
* This is the UX layer - focused on clarity and transparency
*/
formatForUser(paymentDetails: PaymentRequiredResponse, walletBalances?: {
usdc: string;
eth: string;
}, walletService?: any): Promise<string>;
/**
* Format instructions for the agent
* This is the UX layer - focused on clear agent instructions
*/
formatForAgent(paymentDetails: PaymentRequiredResponse, originalParams?: any): string;
/**
* Attempt to fix LLM-truncated transaction data by restoring leading zeros
* Only fixes when we can safely detect truncated amount field
*/
fixTruncatedTransactionData(template: TransactionTemplate): TransactionTemplate;
/**
* Validate that a transaction template is safe to sign
*/
validateTransactionTemplate(template: TransactionTemplate): {
valid: boolean;
errors: string[];
};
}
//# sourceMappingURL=agentpay-v002.d.ts.map