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

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant