Skip to content

[Server] Pass an explicit null to a nullable tool parameter with a default - #642

Open
bigdevlarry wants to merge 1 commit into
modelcontextprotocol:mainfrom
bigdevlarry:fix-nullable-tool-parameter-with-a-default-ignores-an-explicit-null-argument
Open

bigdevlarry wants to merge 1 commit into
modelcontextprotocol:mainfrom
bigdevlarry:fix-nullable-tool-parameter-with-a-default-ignores-an-explicit-null-argument

Conversation

@bigdevlarry

@bigdevlarry bigdevlarry commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

ReferenceHandler::prepareArguments() now passes an explicit null through to a nullable parameter. Before, isset() treated it as a missing argument, addressing issue #640

Motivation and Context

prepareArguments() tested isset($arguments[$paramName]), so an argument the client sent as null looked missing. A parameter such as ?string $category = 'books' received 'books' instead of null. The schema allows null and the client sent it, but the handler ran with a different value. The check now also accepts a key that is present with a null value when the parameter allows null.

How Has This Been Tested?

I added a unit test, testHandlePassesAnExplicitNullToANullableParameterWithADefault. It checks that an explicit null gives NULL and that an omitted argument still gives the default 'books'.

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Additional context

…fault

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bigdevlarry
bigdevlarry force-pushed the fix-nullable-tool-parameter-with-a-default-ignores-an-explicit-null-argument branch from 9001730 to adbbcfb Compare October 30, 2026 22:13
@chr-hertel
chr-hertel requested a balanced review from Copilot November 2, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change preserving explicit null arguments while retaining defaults for omitted parameters.

No open issues 🎉

What changed in this PR

Fixes issue #640 by preserving explicit null values for nullable tool parameters in ReferenceHandler, while retaining default values when arguments are omitted.

Changes:

  • Distinguishes an explicitly supplied null from a missing argument for nullable parameters.
  • Adds a regression test covering both explicit null and omitted arguments.
  • Documents the fix in the changelog.
File Description
tests/​Unit/​Capability/​Registry/​ReferenceHandlerTest.php Tests explicit null handling and preservation of defaults for omitted arguments.
src/​Capability/​Registry/​ReferenceHandler.php Accepts present argument keys with null values when the parameter allows null.
CHANGELOG.md Records the nullable tool parameter fix.

Review effort: Balanced

@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants