Add optional MCP server exposing the SDK as Model Context Protocol tools#1649
Add optional MCP server exposing the SDK as Model Context Protocol tools#1649DhruvaBansal00 wants to merge 2 commits into
Conversation
Introduces a new `robin_stocks_mcp` package that wraps every public function of the robinhood, tda, and gemini submodules as MCP tools (188 total), making the SDK usable from any MCP client (Claude Code, Claude Desktop, Cursor, Continue, etc.). Design choices: - Opt-in: `mcp[cli]` lives under a new `[mcp]` extra (`pip install -e ".[mcp]"`); existing users are unaffected. - Reuses the SDK's own credential persistence as the default path. New CLI subcommands `robin-stocks-mcp login` and `robin-stocks-mcp tda-setup` wrap the first-time interactive setup; subsequent runs reuse the pickle/encrypted store without prompting. - Read-only by default. Order placement, cancellation, transfers, watchlist mutations, CSV exports, and document downloads return a structured ReadOnlyError until ROBIN_STOCKS_MCP_READ_ONLY=false is set. - Blocking SDK calls are offloaded to a thread pool so the MCP event loop stays responsive. - Every tool catches exceptions and returns structured error payloads instead of crashing the transport. Includes 84 offline tests covering runtime helpers, env-var parsing, the auth bootstrap, tool registration, dispatch via mocks, the write guard, the CLI subcommands, and an end-to-end subprocess test that boots the server over STDIO and completes the MCP handshake. No order-placement tests hit real broker APIs. Bumps version to 3.5.0 per contributing.md (feature addition). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a new "MCP Server" section to the existing README covering install, first-time setup, running, Claude Code / Claude Desktop integration, the tool surface, architecture, testing, and safety notes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Not sure this package is actively maintained anymore. It could be worth looking for a new maintainer and then making a hard fork |
|
@jhirschibar I've taken your suggestion and stood up a community-maintained hard fork: https://github.com/DhruvaBansal00/robin_stocks_v2 It's a complete copy of the repo (full commit history + tags), and this MCP server is already merged there: https://github.com/DhruvaBansal00/robin_stocks_v2/tree/main/robin_stocks_mcp — along with 11 other open PRs from here, all with added test coverage (92% overall, 100% on the MCP layer). If you'd like a maintained build with this change, or want to help maintain it, that's where it's happening. Would love the help. |
Sweet dude! I'll try to pitch in where I can, thanks for stepping up! |
Summary
Adds an opt-in
robin_stocks_mcppackage that exposes every public function of therobinhood,tda, andgeminisubmodules as Model Context Protocol tools — 188 in total. This makes the SDK directly usable from any MCP client (Claude Code, Claude Desktop, Cursor, Continue, custom agents) without users having to write any glue code.mcp[cli]lives behind a new[mcp]extra (pip install -e ".[mcp]") so existing users see no new required dependency.robin-stocks-mcp loginandrobin-stocks-mcp tda-setupwrap the first-time interactive setup; subsequent runs reuse the pickle / encrypted store without prompting.ReadOnlyErroruntilROBIN_STOCKS_MCP_READ_ONLY=false.{error, type, message}payloads instead of crashing the JSON-RPC transport.Tool surface (sample)
rh_get_quotes/rh_get_latest_pricerh_build_holdingsrh_get_stock_historicalsrh_find_tradable_optionsrh_get_crypto_quoterh_order_buy_market(write-guarded)tda_get_accounts/tda_get_quotetda_get_price_historytda_place_order(write-guarded)gem_get_pubtickergem_check_available_balancesgem_order(write-guarded)Test plan
tests/mcp/cover the runtime helpers, env-var parsing, auth bootstrap (pickle reuse + env fallback), tool registration, dispatch via mocks, write-guard enforcement, error capture, the CLI subcommands, and an end-to-end subprocess test that boots the server over STDIO and completes the MCP handshake.unittest.mock, so no real orders are placed.pip install -e ".[mcp,dev]" && pytest tests/mcp -q→ 84 passed.tests/test_{robinhood,gemini,tda}.pynot run locally (require GitHub Secrets); maintainer's CI will verify.Compliance with contributing.md
__init__.pyto import new functionssetup.py(YY for features)🤖 Generated with Claude Code