Repository navigation
Issue #41 : fix(tools): keep null branch in registered outputSchema - #46
Conversation
…ase PR. Keep pyproject.toml and uv.lock in sync, skip a bump while a version is still unpublished, and only hit the PyPI environment when an upload will actually run.
Bring the bump/publish workflows in line with develop (via main) so the PR can merge.
…ure/release-automation Automate version bumps and PyPI publishes from main
…ase/0.4.0 Release version bump to 0.4.0
|
The fix makes |
Verification of the proposed fix (
|
|
Rebasing onto develop so only the one fix commit remains. The fix itself is good. ~sent from claude-code |
|
Merged reverted, |
Output schemas describe real results, so Optional fields must still accept null. inspector_friendly_schema is now only applied to input forms. Reapplies the fix from #46 (reverted in #97) without the unrelated release workflow files, and adds regression tests: schema shape, nested models and arrays, in-process validation, and an end-to-end stdio check.
|
Verified the replacement request for #46, reverted by #97: the fix was reapplied in #106, merged on November 3. Rechecked current develop (a82a614) by building its wheel and installing it in a fresh environment. All 15 output/input schema regressions passed against the installed package. A real stdio tools/list → tools/call check confirmed that returned null values validate against the advertised outputSchema, input Inspector behavior is preserved, and both processes import the installed SDK. The replacement request is satisfied; no duplicate PR is needed. |
Summary
Registered output schemas lose the
nullbranch of Optional fields. A tool that returnsNonefor anX | Nonefield produces a result that a client validating against the advertisedoutputSchemarejects.Observed
A tool declares an output model with Optional fields (
str | None = None,int | None = None) and returnsNonefor them. A client that validatesstructuredContentagainst the advertisedoutputSchemafails the call with errors such as:Cause
In
nitrostack/core/app.py:inspector_friendly_schema(via_unwrap_nullable_schema) rewritesanyOf: [T, null]to plainT. Its docstring says this is so MCP Inspector can render form fields.tool_json_schemaapplies the same rewrite to the output schema, so the registeredoutputSchemano longer allows null.Repro
Run on main (0.4.0):
Pydantic emits
anyOf: [{type: string}, {type: null}]formaybe.tool_json_schemareturns:NitroTestingModule.call_toolreturns the null value without validating it against the schema, so the in-process harness does not catch this.Expected
The registered
outputSchemakeeps the null branch, because it describes what the tool returns. The Inspector rewrite is only needed for input forms.Workaround
Remove
output_schemafrom@tool.Proposal
inspector_friendly_schemato input schemas only.