← 输入框|github.com|刷新
Skip to content

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

Merged
chr-hertel merged 2 commits into
modelcontextprotocol:mainfrom
bigdevlarry:fix-nullable-tool-parameter-with-a-default-ignores-an-explicit-null-argument
Nov 3, 2026
Merged

chr-hertel merged 2 commits 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

Fixes #640

…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

@chr-hertel chr-hertel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @bigdevlarry!

@chr-hertel
chr-hertel merged commit 18595ae into modelcontextprotocol:main Nov 3, 2026
28 checks passed
chr-hertel added a commit to BrocksiNet/php-sdk that referenced this pull request Nov 4, 2026
…et/php-sdk into pr-618-end-a-listen-stream-that-can

* 'fix/listen-empty-filter' of https://github.com/BrocksiNet/php-sdk: (25 commits)
  [Server] Pass an explicit null to a nullable tool parameter with a default (modelcontextprotocol#642)
  [Capability] Check tool names against the spec's 128-character limit and character set (modelcontextprotocol#639)
  [Tests] Stop php -S servers together with their forked workers (modelcontextprotocol#658)
  chore(deps): bump astral-sh/setup-uv from 10.3.2 to 10.3.3 (modelcontextprotocol#659)
  [Server] Accept plain http on `*.localhost` and `127.0.0.0/8` hosts in OAuth URLs (modelcontextprotocol#620)
  [Capability] Map PHPDoc pseudo-types to the JSON Schema type of their base type (modelcontextprotocol#643)
  Raise minimum versions of `phpdocumentor/reflection-docblock` and `psr/container` (modelcontextprotocol#657)
  [Server] Use compact JSON in result formatters (modelcontextprotocol#647)
  [Server] Filter list completions in one pass (modelcontextprotocol#649)
  [Server] Fix result lists being sent as JSON objects (modelcontextprotocol#656)
  Avoid repeated array merges in prompt formatting (modelcontextprotocol#650)
  [Docs] Add AGENTS.md (modelcontextprotocol#634)
  Avoid repeated array merges in resource formatting (modelcontextprotocol#651)
  [Server] Fix `"0"` prefix offering all completions (modelcontextprotocol#655)
  Filter enum completions in one pass (modelcontextprotocol#652)
  Paginate registry references before mapping (modelcontextprotocol#653)
  Extract JWT scopes in one pass (modelcontextprotocol#654)
  [Server] Fix `Session::save()` wiping a session that the store failed to read (modelcontextprotocol#637)
  [Server] Answer a DELETE of an unknown or ended session with 404 (modelcontextprotocol#638)
  [Server] Add `Psr6SessionStore` and `Psr6NotificationBus` (modelcontextprotocol#635)
  ...
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.

A nullable tool parameter with a default ignores an explicit null argument

3 participants