Skip to content

Fix MCP tool validation for nullable optional fields#1507

Merged
rapids-bot[bot] merged 1 commit intoNVIDIA:developfrom
AnuradhaKaruppiah:ak-workaround-schema-quirks
Jan 28, 2026
Merged

Fix MCP tool validation for nullable optional fields#1507
rapids-bot[bot] merged 1 commit intoNVIDIA:developfrom
AnuradhaKaruppiah:ak-workaround-schema-quirks

Conversation

@AnuradhaKaruppiah
Copy link
Contributor

@AnuradhaKaruppiah AnuradhaKaruppiah commented Jan 28, 2026

  • Make MCP client tool calls schema‑aware by dropping None values only when the tool’s input schema does not allow nulls.
  • Prevents validation failures from tools that advertise default: null on string fields (e.g., cursor, space) while preserving explicit‑null semantics when allowed.

Description

Closes

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • Bug Fixes
    • Improved input validation and compatibility with MCP servers by filtering invalid null fields during request processing.

✏️ Tip: You can customize this high-level summary in your review settings.

… optional fields with default: null don’t fail validation.

Signed-off-by: Anuradha Karuppiah <anuradhak@nvidia.com>
@AnuradhaKaruppiah AnuradhaKaruppiah self-assigned this Jan 28, 2026
@AnuradhaKaruppiah AnuradhaKaruppiah added the bug Something isn't working label Jan 28, 2026
@AnuradhaKaruppiah AnuradhaKaruppiah requested a review from a team as a code owner January 28, 2026 22:47
@AnuradhaKaruppiah AnuradhaKaruppiah added the non-breaking Non-breaking change label Jan 28, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

Walkthrough

Adds internal utility functions to filter invalid None values from Pydantic model inputs before validation. The utilities detect whether type annotations permit None and remove corresponding None-valued keys from input payloads. Changes are applied in two tool response handler functions without altering public APIs.

Changes

Cohort / File(s) Summary
Internal validation utilities
packages/nvidia_nat_mcp/src/nat/plugins/mcp/client/client_impl.py
Added _annotation_allows_none() to check if a type annotation allows None values. Added _drop_invalid_none_values() to filter keys with None values when the field annotation does not permit None. Applied filtering before Pydantic model_validate() calls in mcp_per_user_tool_function() and mcp_session_tool_function() tool response handlers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing MCP tool validation by handling nullable optional fields, which aligns with the core implementation of dropping invalid None values from Pydantic payloads.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AnuradhaKaruppiah
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 667e5d2 into NVIDIA:develop Jan 28, 2026
16 of 17 checks passed
@AnuradhaKaruppiah AnuradhaKaruppiah deleted the ak-workaround-schema-quirks branch March 13, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants