Skip to content

fix(mcp): split nullable array type into anyOf branches for wider client compatibility - #8522

Open
ousamabenyounes wants to merge 1 commit into
api-platform:mainfrom
ousamabenyounes:fix/issue-8504
Open

fix(mcp): split nullable array type into anyOf branches for wider client compatibility#8522
ousamabenyounes wants to merge 1 commit into
api-platform:mainfrom
ousamabenyounes:fix/issue-8504

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

The MCP JSON Schema flattener now rewrites an array type (e.g. the ["string","null"] produced for nullable properties) into anyOf branches, each with a single type, while preserving sibling keywords. Several MCP clients read type as a single string and would otherwise reject the tool or drop the constraint. Base JsonSchema generation is untouched.

Test verification (RED → GREEN)

With the fix reverted, the new test fails (RED):

PHPUnit 12.5.35 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.14
Configuration: /app/phpunit.xml.dist

�[41;37mF�[0m                                                                   1 / 1 (100%)

Time: 00:00.003, Memory: 18.00 MB

There was 1 failure:

1) ApiPlatform\Mcp\Tests\JsonSchema\SchemaFactoryTest::testArrayTypeIsSplitIntoAnyOf
the array `type` must be removed
Failed asserting that an array does not have the key 'type'.

/app/src/Mcp/Tests/JsonSchema/SchemaFactoryTest.php:515

�[37;41mFAILURES!�[0m
�[37;41mTests: 1�[0m�[37;41m, Assertions: 1�[0m�[37;41m, Failures: 1�[0m�[37;41m.�[0m

With the fix applied, the test passes (GREEN):

GREEN attempt 1/2 (exit 0)
PHPUnit 12.5.35 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.14
Configuration: /app/phpunit.xml.dist

�[33;1mN�[0m                                                                   1 / 1 (100%)

Time: 00:00.002, Memory: 16.00 MB

�[30;43mOK, but there were issues!�[0m
�[30;43mTests: 1�[0m�[30;43m, Assertions: 3�[0m�[30;43m, PHPUnit Notices: 1�[0m�[30;43m.�[0m

Full local suite

Command: docker run --rm -u "$(id -u):$(id -g)" -e HOME=/tmp -v "$PWD":/app -w /app composer:2.8 vendor/bin/phpunit --bootstrap vendor/autoload.php src/Mcp/Tests

PHPUnit 12.5.35 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.14
Configuration: /app/phpunit.xml.dist

�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m�[33;1mN�[0m                      44 / 44 (100%)

Time: 00:00.035, Memory: 20.00 MB

�[30;43mOK, but there were issues!�[0m
�[30;43mTests: 44�[0m�[30;43m, Assertions: 112�[0m�[30;43m, PHPUnit Notices: 44�[0m�[30;43m.�[0m

Fix #8504

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.

[MCP] MCP Inspector warns about incompatible JSON Schemas / Change type hinting for nullable type

1 participant