Module: SchwabMCP::SchwabClientFactory
- Extended by:
- Loggable
- Defined in:
- lib/schwab_mcp/schwab_client_factory.rb
Class Method Summary
collapse
Methods included from Loggable
log_debug, log_error, log_fatal, log_info, log_warn, logger
Class Method Details
.cached_client ⇒ Object
33
34
35
|
# File 'lib/schwab_mcp/schwab_client_factory.rb', line 33
def self.cached_client
@client ||= create_client
end
|
.client_error_response ⇒ Object
37
38
39
40
41
42
|
# File 'lib/schwab_mcp/schwab_client_factory.rb', line 37
def self.client_error_response
MCP::Tool::Response.new([{
type: "text",
text: "**Error**: Failed to initialize Schwab client. Check your credentials."
}])
end
|
.create_client ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/schwab_mcp/schwab_client_factory.rb', line 9
def self.create_client
begin
log_debug("Initializing Schwab client")
client = SchwabRb::Auth.init_client_easy(
ENV['SCHWAB_API_KEY'],
ENV['SCHWAB_APP_SECRET'],
ENV['SCHWAB_CALLBACK_URI'],
ENV['SCHWAB_TOKEN_PATH']
)
unless client
log_error("Failed to initialize Schwab client - check credentials")
return nil
end
log_debug("Schwab client initialized successfully")
client
rescue => e
log_error("Error initializing Schwab client: #{e.message}")
log_debug("Backtrace: #{e.backtrace.first(3).join('\n')}")
nil
end
end
|