Skip to content

[Capability] Map PHPDoc pseudo-types to the JSON Schema type of their base type - #643

Open
sarankumar1325 wants to merge 1 commit into
modelcontextprotocol:mainfrom
sarankumar1325:fix/phpdoc-pseudo-types
Open

sarankumar1325 wants to merge 1 commit into
modelcontextprotocol:mainfrom
sarankumar1325:fix/phpdoc-pseudo-types

Conversation

@sarankumar1325

Copy link
Copy Markdown

Fixes #641

PHPStan/Psalm pseudo-types and literal types in a tool's DocBlock fell through to the default => 'object' branch of the type mapping, so a tool taking e.g. @param non-empty-string $name advertised {"type": "object"} and rejected a valid string argument with -32602.

This change maps them to their base type, both for parameters and for keys of an array shape:

DocBlock type Before After
non-empty-string, numeric-string, class-string, lowercase-string, … object string
positive-int, non-negative-int, negative-int, … object integer
array-key object ["integer", "string"]
'asc'|'desc' / 1|2 / true object string / integer / boolean
non-empty-list<T>, non-empty-array<T> object array with items of T

Inside an array shape:

  • list<T>, non-empty-list<T> and array<int, T> keys become arrays. The comma of array<int, T> no longer splits the shape key in two, because parseObjectLikeArray() now tracks <> depth as well as {}.
  • array<string, T> keys become objects with additionalProperties.
  • mixed keys get the empty schema {}, so they accept any value.

The existing int<min, max> handling moved into the same helper.

Tests: added testMapsPhpStanAndPsalmPseudoTypesToTheirBaseType with a pseudoTypes fixture. It fails before this change and passes after. vendor/bin/phpunit --testsuite unit (2696 tests) passes, as do php-cs-fixer fix --dry-run and phpstan. I also added a CHANGELOG entry under 0.10.0.

I used an AI assistant to help write this change. I reviewed and tested it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-31T00:56:56.458125Z
We couldn’t complete this review. Comment @codex review to try again.
db1cab5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

PHPDoc pseudo-types (non-empty-string, positive-int, list<T> in shapes…) become {"type":"object"} and valid calls are rejected

1 participant