Skip to content

fix: normalize empty tool schema properties - #411

Open
Hanshuk wants to merge 4 commits into
modelcontextprotocol:mainfrom
Hanshuk:fix/tool-schema-properties-object
Open

fix: normalize empty tool schema properties#411
Hanshuk wants to merge 4 commits into
modelcontextprotocol:mainfrom
Hanshuk:fix/tool-schema-properties-object

Conversation

@Hanshuk

@Hanshuk Hanshuk commented Aug 10, 2026

Copy link
Copy Markdown

Summary

Fixes #405.

PHP serializes empty arrays as [], which causes an empty JSON Schema properties object to be serialized as an array instead of the required JSON object {}.

This can cause strict MCP clients to reject otherwise valid tool definitions.

Changes

  • Recursively normalize empty properties arrays to \stdClass.
  • Apply schema normalization during Tool::jsonSerialize() so directly constructed Tool instances are handled correctly despite readonly schema properties.
  • Apply the same normalization to both inputSchema and outputSchema.
  • Preserve legitimate JSON Schema arrays such as required and enum.
  • Retain the existing Tool::fromArray() normalization behavior.

Test coverage

Added regression coverage for:

  • Direct Tool construction with empty properties.
  • Tool::fromArray() with empty properties.
  • JSON decode → Tool construction → serialization.
  • Nested object schemas.
  • Existing non-empty properties.
  • Legitimate required and enum arrays.
  • outputSchema with empty properties.

Validation

  • git diff --check passes.
  • PHPUnit could not be executed locally because PHP/Composer are unavailable in the development environment.

The implementation is intentionally limited to the schema normalization and regression tests required for #405.

@Hanshuk
Hanshuk marked this pull request as draft August 10, 2026 19:38
@Hanshuk
Hanshuk marked this pull request as ready for review August 10, 2026 19:55
@chr-hertel

Copy link
Copy Markdown
Member

Hi @Hanshuk, thanks for this, but basically a duplicate of #407, right?
If you have some feedback for that PR to improve it, please share it there.

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.

Tool serializes empty inputSchema.properties as [] instead of {}

2 participants