refactor(mcp_server): migrate to FastMCP v3 and add OpenBB Code Mode#7385
Draft
MagnusS0 wants to merge 5 commits intoOpenBB-finance:developfrom
Draft
refactor(mcp_server): migrate to FastMCP v3 and add OpenBB Code Mode#7385MagnusS0 wants to merge 5 commits intoOpenBB-finance:developfrom
MagnusS0 wants to merge 5 commits intoOpenBB-finance:developfrom
Conversation
…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.)
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
available_categoriesavailable_toolsactivate_toolsdeactivate_toolssearchtool with category/subcategory/provider-aware filteringexecutefor chained tool calls in sandboxed execution using python-montyon_duplicatewith legacy fallback compatibility.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 -q109 passed, 4 skippedManual
openbb-pydantic-aiagent.Reviewer notes
Please focus review on:
openbb_mcp_server/utils/code_mode.pyopenbb_mcp_server/app/app.pyopenbb_mcp_server/utils/fastapi.pyopenbb_mcp_server/models/settings.pyChecklist
feature/*.