Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
969ff10
feat: Generate PHP DTOs from MCP schema version 2025-11-25
galatanovidiu Dec 10, 2025
d120ee5
docs: Update README with new generator features
galatanovidiu Dec 11, 2025
7a4a9a5
docs: Update architecture documentation with new components
galatanovidiu Dec 11, 2025
c750230
docs: Update configuration guide with new outputs and features
galatanovidiu Dec 11, 2025
0a31fe2
docs: Update design decisions with new type handling strategies
galatanovidiu Dec 11, 2025
8572f7f
feat: Add constants generator for protocol constants
galatanovidiu Dec 11, 2025
92e460a
feat: Add numeric enum generator for TypeScript enums
galatanovidiu Dec 11, 2025
5e470c1
feat: Add type alias wrapper generator
galatanovidiu Dec 11, 2025
0ec11f5
feat: Add intersection type wrapper generator
galatanovidiu Dec 11, 2025
3960af0
feat: Add schema map generator for JSON metadata
galatanovidiu Dec 11, 2025
d81b175
feat: Add skill file generator for Claude Code integration
galatanovidiu Dec 11, 2025
8aed907
feat: Add skill markdown helpers
galatanovidiu Dec 11, 2025
d85185f
feat: Export new generators from index
galatanovidiu Dec 11, 2025
525bab8
feat: Support numeric constants in type mapper
galatanovidiu Dec 11, 2025
d1f71eb
feat: Integrate new generators into main pipeline
galatanovidiu Dec 11, 2025
68b67db
feat: Enhance parser to extract numeric constants
galatanovidiu Dec 11, 2025
eaa5c0f
feat: Add skill types definitions
galatanovidiu Dec 11, 2025
b97adfc
feat: Update TsConstant type to support numeric values
galatanovidiu Dec 11, 2025
c597697
feat: Generate skill documentation files
galatanovidiu Dec 11, 2025
04094c4
feat: Generate skill JSON data files
galatanovidiu Dec 11, 2025
761eeb3
feat: Generate skill search scripts
galatanovidiu Dec 11, 2025
b5e870f
feat: Generate McpConstants PHP class
galatanovidiu Dec 11, 2025
17b66e8
feat: Generate EmptyResult wrapper class
galatanovidiu Dec 11, 2025
f3afd87
feat: Generate task result intersection type wrappers
galatanovidiu Dec 11, 2025
1e8eb64
fix: Extract properties from inline object types with JSDoc comments
galatanovidiu Dec 11, 2025
0d5302a
fix: Use asArrayOrNull for optional array properties in fromArray()
galatanovidiu Dec 11, 2025
0a9fc15
feat: Add runtime validation for ProgressToken (string|number) type
galatanovidiu Dec 11, 2025
53a777a
feat: Add runtime validation for index signature value types
galatanovidiu Dec 11, 2025
9397925
feat: Add runtime validation for 100-item limit on CompleteResultComp…
galatanovidiu Dec 11, 2025
866211f
feat: Use asArrayOrNull for optional array properties in intersection…
galatanovidiu Dec 11, 2025
1832495
feat: Fix property name handling in IntersectionTypeWrapperGenerator
galatanovidiu Dec 11, 2025
76ef307
fix(generator): deep-serialize union DTOs in toArray() to avoid {} in…
galatanovidiu Dec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 111 additions & 13 deletions generator/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ A TypeScript application that generates PHP 7.4 DTOs directly from the MCP TypeS
The generator fetches the official MCP TypeScript schema from GitHub, parses it using ts-morph AST analysis, and produces production-quality PHP code including:

- **DTOs** - Data Transfer Objects with `fromArray()`/`toArray()` methods
- **Enums** - Class-based enums (PHP 7.4 compatible)
- **Enums** - Class-based enums (PHP 7.4 compatible) from both string literal unions and TypeScript enums
- **Constants** - Protocol constants class with error codes and version strings
- **Union Interfaces** - Marker interfaces for polymorphic types
- **Factories** - Discriminator-based instantiation for unions
- **Type Alias Wrappers** - Concrete classes for type aliases referenced in unions
- **Intersection Type Wrappers** - Concrete classes for intersection types (A & B)
- **Builders** - Optional fluent builder pattern classes
- **Contracts** - Marker interfaces for type hierarchies
- **Skill Files** - Claude Code reference documentation and search tools

## Quick Start

Expand Down Expand Up @@ -78,20 +82,114 @@ The generator produces PHP files organized by MCP domain:
```
src/
├── Common/
│ ├── Protocol/ # Core protocol types
│ ├── JsonRpc/ # JSON-RPC message types
│ └── Content/ # Content block types
│ ├── AbstractDataTransferObject.php
│ ├── AbstractEnum.php
│ ├── McpConstants.php # Protocol constants & error codes
│ ├── Traits/
│ ├── Contracts/ # Marker interfaces
│ ├── Protocol/ # Core protocol types
│ ├── JsonRpc/ # JSON-RPC message types
│ ├── Content/ # Content block types
│ └── Tasks/ # Shared task types
├── Server/
│ ├── Tools/ # Tool definitions
│ ├── Resources/ # Resource management
│ ├── Prompts/ # Prompt templates
│ └── Logging/ # Logging types
│ ├── Tools/ # Tool definitions
│ ├── Resources/ # Resource management
│ ├── Prompts/ # Prompt templates
│ ├── Logging/ # Logging types
│ ├── Lifecycle/ # Server lifecycle
│ └── Core/ # Server core types
├── Client/
│ ├── Sampling/ # LLM sampling
│ ├── Elicitation/ # User input elicitation
│ ├── Roots/ # Root directory management
│ └── Tasks/ # Background tasks
└── Contracts/ # Shared interfaces
│ ├── Sampling/ # LLM sampling
│ ├── Elicitation/ # User input elicitation
│ ├── Roots/ # Root directory management
│ ├── Tasks/ # Background tasks
│ └── Lifecycle/ # Client lifecycle
└── Contracts/ # Shared interfaces
```

Additionally, skill files are generated for Claude Code integration:

```
skill/
├── SKILL.md # Entry point
├── reference/ # Markdown documentation
│ ├── overview.md
│ ├── common.md
│ ├── server.md
│ ├── client.md
│ ├── rpc-methods.md
│ └── factories.md
├── data/ # JSON data files
│ ├── schema-index.json
│ ├── schema-common.json
│ ├── schema-server.json
│ └── schema-client.json
└── scripts/ # Search utilities
├── search-types.sh
├── get-type.sh
└── find-rpc.sh
```

## Key Features

### Version Tracking

The generator tracks schema history and annotates generated code with `@since` tags:

```php
/**
* @since 2024-11-05
*/
class CallToolRequest extends Request
{
/**
* @since 2025-03-26
*/
protected ?array $arguments;
}
```

### Type Alias Wrappers

Type aliases like `type EmptyResult = Result` get wrapper classes when referenced in unions:

```php
class EmptyResult extends Result implements ServerResultInterface, ClientResultInterface
{
// Inherits everything from Result
}
```

### Intersection Type Wrappers

Intersection types like `type GetTaskResult = Result & Task` become concrete classes:

```php
class GetTaskResult extends Result implements ClientResultInterface
{
// Properties from Task are merged in
protected string $taskId;
protected string $status;
// ...
}
```

### Protocol Constants

Exported constants from the schema become a PHP constants class:

```php
class McpConstants
{
public const LATEST_PROTOCOL_VERSION = '2025-11-25';
public const JSONRPC_VERSION = '2.0';
public const PARSE_ERROR = -32700;
public const INVALID_REQUEST = -32600;
// ...

public static function isValidErrorCode(int $code): bool { ... }
public static function getErrorCodeName(int $code): ?string { ... }
}
```

## Documentation
Expand Down
Loading