feat: add rh Connect facade and tool coverage

This commit is contained in:
2026-09-01 13:40:40 -05:00
parent 4318b6aefe
commit eb3077ae2a
6 changed files with 358 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
package rh
import (
"context"
"fmt"
"s1d3sw1ped/robinhood-agentic-mcp/accounts"
"s1d3sw1ped/robinhood-agentic-mcp/auth"
"s1d3sw1ped/robinhood-agentic-mcp/client"
"s1d3sw1ped/robinhood-agentic-mcp/crypto"
"s1d3sw1ped/robinhood-agentic-mcp/equity"
"s1d3sw1ped/robinhood-agentic-mcp/market"
"s1d3sw1ped/robinhood-agentic-mcp/options"
"s1d3sw1ped/robinhood-agentic-mcp/scanner"
"s1d3sw1ped/robinhood-agentic-mcp/watchlists"
)
// Connect reads tokens and returns a wired API. Session connect is preferred;
// JSON-RPC tools/call is used when the session cannot be opened. Missing tokens fail closed.
func Connect(ctx context.Context, cfg Config) (*API, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
cfg = cfg.WithDefaults()
if cfg.TokenFile == "" {
return nil, fmt.Errorf("connect: missing TokenFile")
}
tok, err := auth.ReadTokens(cfg.TokenFile)
if err != nil {
return nil, fmt.Errorf("connect: %w", err)
}
if tok.AccessToken == "" {
return nil, fmt.Errorf("connect: missing access token")
}
c, err := client.ConnectSession(ctx, cfg.URL, auth.ClientToken(tok), cfg.Name, cfg.Version)
if err != nil {
c = &client.Client{
URL: cfg.URL,
Token: tok.AccessToken,
Name: cfg.Name,
Version: cfg.Version,
}
}
return &API{
Client: c,
Accounts: accounts.New(c),
Equity: equity.New(c),
Options: options.New(c),
Crypto: crypto.New(c),
Watchlists: watchlists.New(c),
Market: market.New(c),
Scanner: scanner.New(c),
}, nil
}