feat(mcp): selective tool registration via --tools / --exclude-tools#8
Merged
Conversation
semantic-release bumps pyproject.toml on tag but does not refresh uv.lock; bring it back in sync so subsequent `uv` runs do not leave a dirty working tree. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
177 MCP tools across 22 categories is a lot of surface area for an AI agent to reason about. Add a spec grammar that mixes category-level and per-tool granularity so users can dial the surface down to what the agent actually needs: chart -> all tools in chart chart(*) -> all tools in chart (explicit) chart(get_intraday_1hour) -> just that tool chart(t1,t2),quote(*) -> comma-separated mix * -> everything (default) New surface: - --tools / --exclude-tools CLI flags (env: AIOFMP_MCP_TOOLS / AIOFMP_MCP_EXCLUDE_TOOLS). When both set, the include set is the universe and exclude prunes from it. - --list-tools prints the inventory and exits; no API key required. Implementation: aiofmp/mcp_selection.py discovers the inventory by AST-scanning the *_tools.py modules (no imports → no global mcp side effects during validation). register_tools() now imports only the categories present in the effective selection, then calls mcp.remove_tool() for any tool outside that category's allow-set. Validation fails fast on unknown category / tool / malformed spec. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
177 MCP tools across 22 categories is a lot of surface area for an AI agent to reason about. This PR adds a small spec grammar that lets users restrict which tools the MCP server exposes, with both category-level and per-tool granularity.
--tools/--exclude-toolsCLI flags (env equivalents:AIOFMP_MCP_TOOLS/AIOFMP_MCP_EXCLUDE_TOOLS). When both are set,--toolsdefines the universe and--exclude-toolsprunes from it.--list-toolsprints the inventory and exits — noFMP_API_KEYrequired.chartorchart(*)— whole categorychart(get_intraday_1hour)— single toolchart(t1,t2),quote(*),search— mix freely*— every tool (default)Design
aiofmp/mcp_selection.pydiscovers the inventory by AST-scanning*_tools.pymodules. No imports during validation, so--list-toolsand CLI errors don't side-effect the globalmcpinstance.register_tools()imports only the categories present in the effective selection, then callsmcp.remove_tool()for tools outside each category's allow-set.click.UsageErrorso bad inputs fail fast with the valid category/tool list.Files
aiofmp/mcp_selection.py(new) — inventory + spec parser + selection computeaiofmp/mcp_server.py—register_tools()refactor, env-var resolutionaiofmp/cli.py— new flags +--list-toolsshort-circuittests/test_mcp_selection.py(new) — 34 tests for inventory, parser, selection compute, formattertests/test_cli_mcp_server.py(new) — 6 tests for CLI surface + validationtests/test_mcp_server.py— 6 new tests for env-var resolution +register_tools()mockingREADME.md— new "Selective Tool Registration" section + flags in CLI Reference + env vars in the tableCHANGELOG.md— backfilled from history (1.0.0 → 1.1.0 → 1.2.0) + Unreleased entryTest plan
pytest— 928 passed (40 new)ruff check— cleanruff format --check— cleanaiofmp-mcp-server --list-toolsprints inventory,--tools bogusexits non-zero with the valid category list🤖 Generated with Claude Code