Repository navigation
fix(tools): let optional MCP tool arguments accept null - #261
Merged
Zongwei9888 merged 1 commit intoOct 21, 2026
Merged
Conversation
read_file, search_code and read_document_segments declared optional
arguments as `int = None` / `str = None` / `List[str] = None`. FastMCP
advertises those as {"type": "integer", "default": null}, so a client
that sends the advertised default back explicitly gets a validation error
before the tool runs. Annotate the five arguments as `T | None`.
Collaborator
|
Merged into main on 2026-10-21 as 7d5c251 ("Merge PR #261: let optional MCP tool arguments accept null"). Thank you for a precise first contribution. We confirmed the bug: our own argument validator rejected A small nit we may tidy later: the module docstring in |
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.
Description
Three tools in the bundled MCP servers declare optional arguments as
T = NonewithoutNonein the type. FastMCP then advertises them as, for example,{"type": "integer", "default": null}: the default is null, but the type doesn't allow null. A client that sends the advertised default back explicitly is rejected before the tool runs. For example,read_filewith{"file_path": "a.py", "start_line": null}fails with:This PR annotates those arguments as
T | None. Behavior for callers that leave the arguments out doesn't change.Related Issues
None found. I searched issues and PRs for
null,Optional,nullableanddefault None.Changes Made
tools/code_implementation_server.py:read_file(start_line,end_line) andsearch_code(search_directory)tools/document_segmentation_server.py:read_document_segments(keywords,max_total_chars)tests/test_bundled_mcp_optional_args.py. For both servers, it lists the tools through the realFastMCPinstance and checks that every argument whose schema default isnullalso acceptsnull. It checks both the advertised schema and pydantic argument validation. It doesn't call any tools and doesn't start a backend.Checklist
Additional Notes
mainfor all 5 arguments and passes with this change.scripts/ci/requirements.lock:main: 9 failed, 2774 passed, 14 skippedmainand on this branch. They cover the workbench and verification test runners (the systempython3here has no pytest, plus npm runs), theci-scopegit action, and the bash large-output spill test. None of them touch these servers.ruff0.15.21 (the pre-commit pin) check and format both pass on the changed files.setup.py), soT | Noneworks on every supported version. Other modules intools/already use it.