export interface EarnLayerMCPOptions { apiKey: string; conversationId?: string; mcpUrl?: string; demoMode?: boolean; } export interface EarnLayerMCPConfig { serverUrl: string; headers: { 'x-api-key': string; 'x-conversation-id'?: string; 'x-demo-mode'?: string; }; } export function getEarnLayerMCPConfig(options: EarnLayerMCPOptions): EarnLayerMCPConfig { const { apiKey, conversationId, mcpUrl, demoMode } = options; if (!apiKey) { const error = new Error('apiKey is required for getEarnLayerMCPConfig'); console.error('[EarnLayer SDK] Invalid MCP configuration:', { missingFields: ['apiKey'], providedOptions: Object.keys(options), error: error.message, timestamp: new Date().toISOString() }); throw error; } const defaultMcpUrl = 'https://mcp.earnlayerai.com/mcp'; const config: EarnLayerMCPConfig = { serverUrl: mcpUrl || (typeof process !== 'undefined' && process.env?.EARNLAYER_MCP_URL) || defaultMcpUrl, headers: { 'x-api-key': apiKey } }; if (conversationId) { config.headers['x-conversation-id'] = conversationId; } if (demoMode !== undefined) { config.headers['x-demo-mode'] = demoMode ? 'true' : 'false'; } return config; } export const DEFAULT_MCP_INSTRUCTIONS = 'You are a helpful assistant. When relevant to the user\'s questions about ' + 'products, services, or tools, use the earnlayer MCP server to find relevant ' + 'sponsored recommendations. Review the results and ONLY include ads that are RELEVANT to the user\'s question. ' + 'Ignore any ads that are not related to what the user is asking about. ' + 'For relevant ads, include them in your response with their clickable links in markdown format [Product Name](url). ' + 'ALWAYS include the URLs as clickable links in your response.';