Repository navigation
fix(tools): accept explicit null for optional str arguments - #236
Conversation
search_knowledge(category), list_documents(category) and
add_from_url(title) were annotated `str = None`. The tool schema then
advertised "default": null on a string-only field, and the MCP SDK's
argument model rejected {"category": null} before the tool ran.
Annotate them Optional[str], like the other optional arguments.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review. 📝 WalkthroughWalkthroughThree tool parameters now use ChangesNullable tool arguments
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to Explicit null follows the documented optional-filter and automatic-title behavior. No actionable merge-blocking issue is established; the change is ready for normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @lyonzin, just checking this is still on your radar. It still merges cleanly: three annotations go from |
Patch release. Fixes the startup crash on every fresh install and every new data directory since v4.10.0 (#248, #252), makes state-file writes robust on Windows and stops reindex_documents from reporting a refused run as started (#249). Also ships #236 and the multi-arch Docker image from #242. - pyproject.toml: 4.11.0 -> 4.11.1 - mcp_server/__init__.py: __version__ -> 4.11.1 - npm/package.json: 4.11.0 -> 4.11.1 - CHANGELOG.md: Unreleased promoted to v4.11.1 with highlights and credits - .github/api-surface-baseline.json: regenerated with --snapshot. Additive only: 8 modules and 5 methods added since the 2026-08-10 snapshot, none removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
search_knowledge(category), list_documents(category) and
add_from_url(title) were annotated `str = None`. The tool schema then
advertised "default": null on a string-only field, and the MCP SDK's
argument model rejected {"category": null} before the tool ran.
Annotate them Optional[str], like the other optional arguments.
Patch release. Fixes the startup crash on every fresh install and every new data directory since v4.10.0 (#248, #252), makes state-file writes robust on Windows and stops reindex_documents from reporting a refused run as started (#249). Also ships #236 and the multi-arch Docker image from #242. - pyproject.toml: 4.11.0 -> 4.11.1 - mcp_server/__init__.py: __version__ -> 4.11.1 - npm/package.json: 4.11.0 -> 4.11.1 - CHANGELOG.md: Unreleased promoted to v4.11.1 with highlights and credits - .github/api-surface-baseline.json: regenerated with --snapshot. Additive only: 8 modules and 5 methods added since the 2026-08-10 snapshot, none removed.
…'s collision suffix and path validation search_knowledge and list_documents treat category="" like an omitted argument (MCP clients send empty strings for optional arguments, see #236), now documented and pinned by a test; add_from_url's saved name gains an 8/16-hex URL-hash suffix when the shorter name holds another file, so clients should use the returned filepath; its category becomes part of the path and must stay inside documents_dir (review on #276).
Summary
Three optional tool arguments are annotated
str = None:search_knowledge(category),list_documents(category)andadd_from_url(title). The tool schema advertises"default": nullon a field whose type is onlystring, so a client that sends that default back (some agent frameworks fill in every optional argument) gets a validation error, and the tool never runs:This PR annotates them
Optional[str] = None, the style the same functions already use forinclude_folders/exclude_folders. Callers that omit the argument see no change.No issue filed. It's a three-line fix, so I opened the PR directly.
Type of change
What changed
mcp_server/server.py:category: str = None→Optional[str] = Noneonsearch_knowledgeandlist_documents, and the same change fortitleonadd_from_url.tests/test_tool_null_defaults.py: lists the registered MCP tools and checks that every argument whose schema default isnullacceptsnullthrough the SDK's argument model. It fails onmaster(['search_knowledge.category', 'list_documents.category', 'add_from_url.title']) and passes here.CHANGELOG.md: added an entry under### Unreleased→ Fixed.Why
Checked on mcp 2.3.0, offline: 3 of the 5 null-default arguments reject
nullonmaster, and 0 do with this change. The other two were alreadyOptional[List[str]]. I also ranawait mcp.call_tool("list_documents", {"category": None}). Onmasterit raises the error above. With this change it returns the normal{"status": "success", "filter": "all", ...}response, the same as omittingcategory.7 Pillars Quality Gate
1. Security
eval,exec,subprocess shell=True,pickle.loadson untrusted input, or arbitrary deserialization2. Stability
xfail3. Memory leak
4. Versatility
Optional[str]works on 3.11 through 3.13 and is already imported inserver.py5. Scalability
Performance impact: N/A. Only type annotations changed in
server.py, and no runtime code path differs except thatnullis now accepted where it used to raise.6. Versioning
### UnreleasedinCHANGELOG.md(scripts/check_changelog.py→[OK] CHANGELOG updated under Unreleased (type: fix))scripts/check_api_surface.py --check→[OK] No breaking changes to public API surface.Parameter names are unchanged, andtest_backwards_compat.pypasses.7. Quality
ruff checkpasses on the changed filesruff format --checkpasses on the changed filesMigration / Breaking changes
N/A
Test plan
pytest tests/passed locally: 1251 passed, 14 skipped (macOS, Python 3.12, mcp 2.3.0,HF_HUB_OFFLINE=1)pre-commit run --all-files: I didn't run it. I ran the ruff, api-surface and changelog checks it covers on the changed files instead, and all were clean.mcp.call_tool("list_documents", {"category": None})errors onmasterand succeeds hereDocumentation
### UnreleasedinCHANGELOG.mdReviewer checklist
Found with mcp-doctor's
none_default_typecheck, then reproduced as above.By submitting this PR I confirm I read CONTRIBUTING.md and agree to the Code of Conduct.
🤖 Generated with Claude Code
Summary by CodeRabbit
nullfor optional category or title inputs in knowledge search, document listing, and URL-based document addition.