Skip to content

Add optional MCP server exposing the SDK as Model Context Protocol tools#1649

Open
DhruvaBansal00 wants to merge 2 commits into
jmfernandes:masterfrom
DhruvaBansal00:feature/mcp
Open

Add optional MCP server exposing the SDK as Model Context Protocol tools#1649
DhruvaBansal00 wants to merge 2 commits into
jmfernandes:masterfrom
DhruvaBansal00:feature/mcp

Conversation

@DhruvaBansal00

Copy link
Copy Markdown

Summary

Adds an opt-in robin_stocks_mcp package that exposes every public function of the robinhood, tda, and gemini submodules 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.

  • Pure addition. No existing public API changes. mcp[cli] lives behind a new [mcp] extra (pip install -e ".[mcp]") so existing users see no new required dependency.
  • 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.
  • Blocking SDK calls are offloaded to a thread pool so the MCP event loop stays responsive.
  • Every tool catches exceptions and returns structured {error, type, message} payloads instead of crashing the JSON-RPC transport.
  • Version bumped 3.4.0 → 3.5.0 per contributing.md (feature addition).
  • Docs in a separate commit from code per contributing.md rule 1.

Tool surface (sample)

Tool What it does
rh_get_quotes / rh_get_latest_price Stock quotes
rh_build_holdings Portfolio summary
rh_get_stock_historicals OHLC bars
rh_find_tradable_options Option chain search
rh_get_crypto_quote Crypto quote
rh_order_buy_market (write-guarded) Market buy
tda_get_accounts / tda_get_quote TDA account/quote
tda_get_price_history TDA price history
tda_place_order (write-guarded) TDA order
gem_get_pubticker Gemini public ticker
gem_check_available_balances Gemini balances
gem_order (write-guarded) Gemini order

Test plan

  • 84 offline tests under 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.
  • All tests run without broker credentials — every SDK call is mocked via unittest.mock, so no real orders are placed.
  • Run locally with pip install -e ".[mcp,dev]" && pytest tests/mcp -q → 84 passed.
  • Existing tests/test_{robinhood,gemini,tda}.py not run locally (require GitHub Secrets); maintainer's CI will verify.

Compliance with contributing.md

# Requirement Status
1 Grammar/docs changes in a separate commit from code ✅ Two commits; second is README-only
2 Update __init__.py to import new functions N/A — does not extend the SDK surface
3 Bump version in setup.py (YY for features) ✅ 3.4.0 → 3.5.0
4 Write tests covering new code ✅ 84 tests
5 Don't write tests that place real orders ✅ All SDK calls mocked

🤖 Generated with Claude Code

DhruvaBansal00 and others added 2 commits May 20, 2026 00:13
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>
@jhirschibar

Copy link
Copy Markdown

Not sure this package is actively maintained anymore. It could be worth looking for a new maintainer and then making a hard fork

@DhruvaBansal00

DhruvaBansal00 commented May 23, 2026

Copy link
Copy Markdown
Author

@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.

@jhirschibar

Copy link
Copy Markdown

@jhirschibar you're exactly right, and thanks for the nudge. jmfernandes/robin_stocks does appear to be unmaintained (this PR plus ~27 others have been sitting open), so 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants