[Server] Always emit items for array tool parameter schemas#378
Open
valeriudev wants to merge 1 commit into
Open
[Server] Always emit items for array tool parameter schemas#378valeriudev wants to merge 1 commit into
items for array tool parameter schemas#378valeriudev wants to merge 1 commit into
Conversation
Array tool parameters without an inferable element type generated `{"type":"array"}` with no `items`, which strict MCP clients (VS Code / Copilot) reject. Always emit `items` (`{}` when the element type is unknown) and recover the element type for nullable typed arrays such as `string[]|null`.
Fixes modelcontextprotocol#151
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
VS Code / Copilot and other strict MCP clients reject tools whose input schema declares an
arrayparameter without anitemskeyword:Any handler with an untyped
arrayparameter (e.g.array $params = [], as in the report) generated{"type": "array"}with noitems, so the tool was unusable in those clients.Root cause
SchemaGeneratoronly setitemswhen it could infer an element type:array,array<string, mixed>maps,mixed) and untyped variadics emittedtype: arraywith noitemsat all.string[]|null) lost its element type entirely, because the|nullsuffix wasn't stripped before theT[]inference ran — so it too fell back to noitems.Fix
src/Capability/Discovery/SchemaGenerator.php, two parts:ensureArrayItems()runs after all schema merges (and on the variadic path). When the schema is array-typed and still has noitems, it defaults to the empty schema —items: {}(a\stdClass, so it serializes to{}and not[]), which matches any element. Running post-merge means a#[Schema]attribute that reshapes a parameter (e.g. toobject) is respected and the invariant is only enforced on what is genuinely still an array.inferArrayItemsType()strips a top-level nullable union (string[]|null,null|int[]) before inference, so nullable typed arrays recover their element type. Inner unions likearray<int|string>are left untouched (the strip is anchored to the start/end only); array nullability is still handled separately viaallows_null.No public API symbol changes — this corrects derived schema output to be spec-compliant, so it is a bugfix, not a
[BC Break].Verification
testRecoversItemsTypeForNullableTypedArraysandtestUntypedVariadicStillDeclaresItems; tightened the existing array-case assertions; new fixturesnullableTypedArrays/untypedVariadic.make tests(unit + inspector),make phpstan,make cs,composer validate --strict, andmake docsall green.HttpComplexToolSchemaTestsnapshot now shows the nullablestring[]|nullattendee-emails parameter correctly carryingitems: {type: string}.Note for merge
A parallel branch of mine also opens a
0.6.1CHANGELOG section. If it lands first, I'll rebase and move this bullet under the existing0.6.1heading rather than re-adding it.Fixes #151