Skip to main content
Glama
vsoneji
by vsoneji
client.ts1.86 kB
import { createSchwabAuth as SchwabAuthCreatorFromLibrary, AuthStrategy, type TokenData, type EnhancedTokenManager, type EnhancedTokenManagerOptions, } from '@sudowealth/schwab-api' import { type ValidatedEnv } from '../../types/env.js' import { LOGGER_CONTEXTS } from '../shared/constants.js' import { logger } from '../shared/log.js' // Create scoped logger for auth client const authLogger = logger.child(LOGGER_CONTEXTS.AUTH_CLIENT) /** * Creates a Schwab Auth client with enhanced features * * @param redirectUri OAuth callback URI * @param load Function to load tokens from storage * @param save Function to save tokens to storage * @returns Initialized Schwab auth client as EnhancedTokenManager */ export function initializeSchwabAuthClient( config: ValidatedEnv, redirectUri = config.SCHWAB_REDIRECT_URI, load?: () => Promise<TokenData | null>, save?: (tokenData: TokenData) => Promise<void>, ): EnhancedTokenManager { const clientId = config.SCHWAB_CLIENT_ID const clientSecret = config.SCHWAB_CLIENT_SECRET authLogger.debug('Using centralized environment for Schwab Auth client') authLogger.info('Initializing enhanced Schwab Auth client', { hasLoadFunction: !!load, hasSaveFunction: !!save, }) // Build options for EnhancedTokenManager with MCP-specific defaults const tokenManagerOptions: EnhancedTokenManagerOptions = { clientId, clientSecret, redirectUri, load, save, validateTokens: true, autoReconnect: true, debug: config.LOG_LEVEL === 'debug' || config.LOG_LEVEL === 'trace', traceOperations: config.LOG_LEVEL === 'trace', refreshThresholdMs: 5 * 60 * 1000, } // Configure auth with enhanced token manager const authConfig = { strategy: AuthStrategy.ENHANCED, oauthConfig: tokenManagerOptions, } const authClient = SchwabAuthCreatorFromLibrary(authConfig) return authClient }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vsoneji/schwab-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server