Add TypeScript generator for MCP PHP DTOs #1
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.
What
This PR establishes a complete PHP Composer package (
wordpress/php-mcp-schema) with a TypeScript-based code generator that creates PHP 7.4 DTOs from the official Model Context Protocol TypeScript schema.Package Structure:
src/- Auto-generated PHP DTOs (distributed via Packagist)generator/- TypeScript generator (excluded from distribution via.gitattributes)Generator Pipeline:
Generated Artifacts:
fromArray(),toArray()(auto-hydration/serialization)extends@categoryJSDoc tagsWhy
TypeScript AST over JSON Schema: The generator parses TypeScript directly using ts-morph because:
extendsrelationships (JSON Schema flattens intoallOf)@categoryJSDoc tags for domain classificationPHP 7.4 Compatibility: Ensures broad adoption across PHP ecosystems, using class-based enums instead of native PHP 8.1 enums, PHPDoc annotations instead of union types.
Generator Approach: Keeps PHP code synchronized with the evolving MCP specification. The generator supports multiple schema versions (2024-11-05 through 2025-11-25) and tracks version history for changelog annotations.
True Inheritance: PHP DTOs mirror TypeScript inheritance chains (
InitializeRequest extends JSONRPCRequest extends Request) instead of flattening, enablinginstanceofchecks and eliminating code duplication.Key Files
generator/src/index.tsgenerator/src/generators/dto.tsgenerator/src/generators/type-mapper.tsgenerator/src/generators/domain-classifier.ts@category→ namespace mappinggenerator/src/extractors/synthetic-dto.tsgenerator/src/cli/index.tsUsage
Test Plan
npm run buildin generator/ - compiles without errorsnpx mcp-php-generator generate -c config/2025-11-25.json- generates PHP filescomposer analyse- PHPStan level 8 passes