Skip to content

Treat explicit null defaults as nullable in MCP schema translation#1665

Merged
rapids-bot[bot] merged 2 commits intoNVIDIA:release/1.5from
AnuradhaKaruppiah:ak-mcp-workaround
Feb 26, 2026
Merged

Treat explicit null defaults as nullable in MCP schema translation#1665
rapids-bot[bot] merged 2 commits intoNVIDIA:release/1.5from
AnuradhaKaruppiah:ak-mcp-workaround

Conversation

@AnuradhaKaruppiah
Copy link
Contributor

@AnuradhaKaruppiah AnuradhaKaruppiah commented Feb 26, 2026

Description

Adds a temporary MCP schema-translation workaround so fields with an explicit default: null are treated as nullable, even when the schema type does not explicitly include null.

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

    • Schema processing now treats optional fields that explicitly default to null as nullable, so validators accept both the original type and null as valid values.
  • Tests

    • New tests confirm optional fields with explicit null defaults validate correctly for null and for values of the declared type.

Signed-off-by: Anuradha Karuppiah <anuradhak@nvidia.com>
@AnuradhaKaruppiah AnuradhaKaruppiah self-assigned this Feb 26, 2026
@AnuradhaKaruppiah AnuradhaKaruppiah requested a review from a team as a code owner February 26, 2026 05:05
@AnuradhaKaruppiah AnuradhaKaruppiah added bug Something isn't working non-breaking Non-breaking change labels Feb 26, 2026
@copy-pr-bot
Copy link

copy-pr-bot bot commented Feb 26, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa66f98 and 1bc3274.

📒 Files selected for processing (1)
  • packages/nvidia_nat_mcp/tests/client/test_mcp_schema.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nvidia_nat_mcp/tests/client/test_mcp_schema.py

Walkthrough

Detects fields that explicitly default to None and, for optional fields, widens their inferred type to include nullability so the model annotation permits None; adds a test verifying this behavior.

Changes

Cohort / File(s) Summary
Type Handling Enhancement
packages/nvidia_nat_mcp/src/nat/plugins/mcp/utils.py
Adds has_explicit_null_default and updates optional-field handling to OR the inferred field_type with None when the field's default is explicitly None but the type lacks nullability.
Test Addition
packages/nvidia_nat_mcp/tests/client/test_mcp_schema.py
Adds test_optional_field_with_explicit_null_default_becomes_nullable to assert that a field with default=None becomes annotated to accept both the declared type and None, and validates both None and valid values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 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 clearly describes the main change: treating explicit null defaults as nullable in MCP schema translation. It uses imperative mood and is concise at 66 characters.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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 unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@AnuradhaKaruppiah
Copy link
Contributor Author

/ok to test fa66f98

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/nvidia_nat_mcp/tests/client/test_mcp_schema.py (1)

884-890: Consider adding a test case for omitted field defaulting to None.

The test validates explicit None and string values, but doesn't verify that omitting the field entirely uses the None default. This would make the test more complete.

🧪 Suggested additional assertion
     # Test string value validates
     m2 = _model.model_validate({"cursor": "abc123"})
     assert m2.cursor == "abc123"
+
+    # Test omitted field defaults to None
+    m3 = _model.model_validate({})
+    assert m3.cursor is None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nvidia_nat_mcp/tests/client/test_mcp_schema.py` around lines 884 -
890, Add a test that verifies omitting the "cursor" field results in the default
None value: call _model.model_validate with an empty dict (or without "cursor"),
assign to e.g. m3, and assert m3.cursor is None so the schema defaults missing
cursor to None; update the test near the existing m1/m2 assertions in
test_mcp_schema.py to include this omitted-field check referencing _model and
model_validate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/nvidia_nat_mcp/tests/client/test_mcp_schema.py`:
- Around line 884-890: Add a test that verifies omitting the "cursor" field
results in the default None value: call _model.model_validate with an empty dict
(or without "cursor"), assign to e.g. m3, and assert m3.cursor is None so the
schema defaults missing cursor to None; update the test near the existing m1/m2
assertions in test_mcp_schema.py to include this omitted-field check referencing
_model and model_validate.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3892d75 and fa66f98.

📒 Files selected for processing (2)
  • packages/nvidia_nat_mcp/src/nat/plugins/mcp/utils.py
  • packages/nvidia_nat_mcp/tests/client/test_mcp_schema.py

Signed-off-by: Anuradha Karuppiah <anuradhak@nvidia.com>
@AnuradhaKaruppiah
Copy link
Contributor Author

/ok to test 1bc3274

@AnuradhaKaruppiah
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit 4dcf567 into NVIDIA:release/1.5 Feb 26, 2026
17 checks passed
Charlie-Yi-2002 pushed a commit to Charlie-Yi-2002/NeMo-Agent-Toolkit that referenced this pull request Mar 5, 2026
…VIDIA#1665)

Adds a temporary MCP schema-translation workaround so fields with an explicit default: null are treated as nullable, even when the schema type does not explicitly include null.

## By Submitting this PR I confirm:
- I am familiar with the [Contributing Guidelines](https://github.com/NVIDIA/NeMo-Agent-Toolkit/blob/develop/docs/source/resources/contributing/index.md).
- 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**
  * Schema processing now treats optional fields that explicitly default to null as nullable, so validators accept both the original type and null as valid values.

* **Tests**
  * New tests confirm optional fields with explicit null defaults validate correctly for null and for values of the declared type.

Authors:
  - Anuradha Karuppiah (https://github.com/AnuradhaKaruppiah)

Approvers:
  - Will Killian (https://github.com/willkill07)

URL: NVIDIA#1665
@AnuradhaKaruppiah AnuradhaKaruppiah deleted the ak-mcp-workaround 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