Repository navigation
fix(cli): ignore case in --exclude-tools and --tools, reject unknown names - #617
Open
tanishqbaweja wants to merge 1 commit into
Open
tanishqbaweja wants to merge 1 commit into
tanishqbaweja wants to merge 1 commit into
Conversation
…names _apply_tool_filter() compares the names from --tools, --exclude-tools, WINDOWS_MCP_TOOLS, WINDOWS_MCP_EXCLUDE_TOOLS and [tools] exclude with the registered tool names exactly, and skips a name that matches none. So `serve --exclude-tools powershell` (or Powershell, or a typo such as PowerShel) starts with the PowerShell tool enabled and says nothing, and `serve --tools "screenshot,click"` starts with ControlStatus alone. The flags came with the tier system (65f7279), whose normalize_tool_names() matched names ignoring case and stopped startup on an unknown one; 5c12628 replaced it with this filter. Match names ignoring case, and raise that check's error for a name that matches no registered tool, so serve exits with code 1 and "Error: Unknown tools: PowerShel. Allowed: App, Click, ..." instead of starting. serve() passes a ClickException from _run_server() through without logging it as an unhandled exception, so the error prints like the other startup errors, without a traceback. Exact names, the reserved ControlStatus and --tools overriding the exclusions are unchanged.
This branch has not been deployed
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.
Problem
--exclude-toolsis how a deployment switches off tools it does not need, such as the README'swindows-mcp serve --exclude-tools "PowerShell,Registry"._apply_tool_filter()compares the names it gets with the registered tool names exactly, and skips a name that matches none without a word. That holds for--tools,--exclude-tools,WINDOWS_MCP_TOOLS,WINDOWS_MCP_EXCLUDE_TOOLSand[tools] excludein config.toml. So:--exclude-tools powershell(orPowershell, or a typo such asPowerShel) starts the server with the PowerShell tool enabled.--tools "screenshot,click"starts it withControlStatusalone, and--tools "Screenshot,Clik"without Click.The flags came with the tier system (65f7279), whose
normalize_tool_names()intiers.pymatched names ignoring case and stopped startup on an unknown name withUnknown tools: ... Allowed: .... 5c12628 replaced it the same day with the inline filter, which does neither.Reproduction
At 106b50c on Windows 11 (build 22631) with Python 3.14.9, fastmcp 4.1.3 and click 8.5.0. A script ran
windows-mcp servethrough click'sCliRunnerwith the real_build_mcp(), so the real tool registry, andFastMCP.runreplaced, so no server started; then it listed the registered tools. Onmainevery command starts the server and prints nothing:Fix
__main__.py:_apply_tool_filter()matches names ignoring case, and raises the old check's error, as aclick.ClickException, for a name that matches no registered tool. The reproduction then gives:The typo prints:
--ssl-certfilewithout--ssl-keyfile, an invalidip_allowlist).serve()passes aClickExceptionfrom_run_server()through without logging it as an unhandled exception, so the error prints on its own, not after a "Server exiting due to unhandled exception" traceback.ControlStatusis still always kept, and--toolsstill overrides the exclusions, which are then not checked since they are not used.Tests
New
tests/test_tool_filter.py, on a FastMCP with four tools:test_exclude_matches_tool_names_ignoring_case:PowerShell,powershellandPOWERSHELLeach remove PowerShell.test_tools_match_tool_names_ignoring_case:Screenshot,Clickandscreenshot,CLICKkeep the same tools.test_unknown_tool_name_is_an_error: an unknown exclusion, an unknown name in the tool list, and two unknown names. The error lists them and no tool is removed.test_unknown_tool_name_never_starts_server:servethroughCliRunner, withFastMCP.runreplaced, and the name in--exclude-tools, inWINDOWS_MCP_EXCLUDE_TOOLSor in[tools] exclude. Exit code 1, the output is the one error line, the server is not started and nothing logs "Server exiting".I ran each file on its own, in the same environment:
On
mainthe new file has 9 failures; only the 2 exact-case cases pass. The lowercase cases fail on the tool set (Extra items in the left set: 'PowerShell',assert {'ControlStatus'} == ...), the unknown names withDID NOT RAISE ClickException, and theservecases withassert 0 == 1on the exit code. On this branch all 11 pass. Without the pass-through inserve(), the 3servecases fail on the log check. The other files pass onmainand on this branch with the same counts:test_control_mcp_gate.py(15 passed, with itsControlStatusfilter test),test_cli_paired_flags.py(5),test_control_cli.py(25),test_cli_debug.py(10),test_cli_legacy_flags.py(11) andtest_config_stateless.py(9). I did not run the whole suite.ruff checkandruff format --checkare clean on both changed Python files.Not tested
A real MCP client: no server was started. To check it on a real machine, start
windows-mcp serve --exclude-tools powershellfrom a client and list its tools: onmainPowerShell is listed, with this change it is not.windows-mcp serve --exclude-tools PowerShelshould exit at once with the error above.