Skip to content

refactor(mcp_server): migrate to FastMCP v3 and add OpenBB Code Mode#7385

Draft
MagnusS0 wants to merge 5 commits intoOpenBB-finance:developfrom
MagnusS0:feature/mcp-v3-code-mode
Draft

refactor(mcp_server): migrate to FastMCP v3 and add OpenBB Code Mode#7385
MagnusS0 wants to merge 5 commits intoOpenBB-finance:developfrom
MagnusS0:feature/mcp-v3-code-mode

Conversation

@MagnusS0
Copy link
Copy Markdown
Contributor

@MagnusS0 MagnusS0 commented Mar 1, 2026

OpenBB MCP - FastMCP v3

This PR is an update of the OpenBB MCP.

I refactored the server to FastMCP v3 and adapted the upcoming Code Mode flow (still pre-GA), this makes the MCP much more usable.

In the first version of the OpenBB MCP i added the admin discovery tools to toggle tool visibility. With this change, we move to Code Mode-style interaction (search + execute), which also unlocks better tool chaining and practical access to categories that were previously skipped, especially POST-heavy areas (including technical/quant/econometrics workflows).

This also extendes the base FastMCP Code Mode behavior with OpenBB-specific filtering/search improvements and compact markdown output hints to reduce token usage.

What changed

  • Migrated MCP server integration to FastMCP v3 APIs.
  • Removed legacy admin discovery/toggle tool path:
    • available_categories
    • available_tools
    • activate_tools
    • deactivate_tools
  • Added OpenBB Code Mode integration:
    • search tool with category/subcategory/provider-aware filtering
    • execute for chained tool calls in sandboxed execution using python-monty
  • Added Code Mode config surface in settings/env:
    • enable flag
    • sandbox limits
    • search limits/output format
  • Unified duplicate handling via on_duplicate with legacy fallback compatibility.
  • Updated docs and tests to match new behavior.

Motivation / context

Code Mode is becoming a key MCP pattern (Cloudflare and Anthropic both published their versions):

I also opened a related FastMCP PR for markdown serializer/token improvements:

Draft note

This is intentionally a Draft PR because Code Mode support is not GA in upstream FastMCP yet, and this branch currently uses a git-pinned FastMCP revision to access that functionality.

How has this been tested?

Automated

  • uv run pytest openbb_platform/extensions/mcp_server/tests -q
  • Result: 109 passed, 4 skipped

Manual

  • Tested with my local openbb-pydantic-ai agent.
  • In my usage, this made the MCP flow more effective and reliable, especially for multi-step tool workflows.

Reviewer notes

Please focus review on:

  • openbb_mcp_server/utils/code_mode.py
  • openbb_mcp_server/app/app.py
  • openbb_mcp_server/utils/fastapi.py
  • openbb_mcp_server/models/settings.py

Checklist

  • Self-review completed.
  • Tests updated and passing for changed behavior.
  • Branch naming follows feature/*.
  • PR marked as Draft due pre-GA FastMCP dependency.

@deeleeramone deeleeramone added refactor Refactor code dependencies Work related to dependencies platform OpenBB Platform feature New feature labels Mar 1, 2026
deeleeramone and others added 4 commits March 3, 2026 08:52
…de, fix brief format

- Remove 270+ lines of dead code (summarize_categories, render_categories_as_markdown,
  OpenBBSearch/OpenBBListCategories classes, all OpenBB hint helpers)
- Consolidate duplicate tool builders into build_search_tool/build_list_categories_tool
  public methods; CodeMode factories become simple lambdas
- Add get_schema tool to standalone search mode giving it the same 4-step discovery
  flow as CodeMode: list_categories -> search -> get_schema -> call_tool
- Fix brief search output to use first line of description only (splitlines()[0])
  preventing multi-paragraph docstrings from bleeding into search results
- BM25 uses post-filter with uncapped top_k for stable indexing
- output_format exposed as public attribute
- Cache _make_list_categories_tool and _make_get_schema_tool instances
- max_results/ctx keyword-only in search inner fn (pylint R0917)
- Add test asserting BM25 index hash is stable across filter changes
…isable

- Expose render_results() as a public method on OpenBBBM25SearchTransform
  (wraps inherited _render_results) so build_search_tool closures avoid W0212;
  docstring explains the wrapper exists solely for pylint boundary reasons
- Add module-level pylint: disable=protected-access in test file — tests
  intentionally inspect private state (_bm25_hash, _max_results, etc.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Work related to dependencies feature New feature platform OpenBB Platform refactor Refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants