|
1 | 1 | # PHP MCP Schema |
| 2 | + |
| 3 | +A PHP representation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) schema types. |
| 4 | + |
| 5 | +This package provides Data Transfer Objects (DTOs), Enums, and Unions that mirror the official MCP TypeScript schema. |
| 6 | +It is **not** an SDK, client, or server implementation; |
| 7 | +just the type definitions for building your own MCP-compatible applications in PHP. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +composer require wordpress/php-mcp-schema |
| 13 | +``` |
| 14 | + |
| 15 | +Requires PHP 7.4 or higher. |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +```php |
| 20 | +use WP\McpSchema\Server\Tools\Tool; |
| 21 | +use WP\McpSchema\Server\Tools\CallToolRequest; |
| 22 | +use WP\McpSchema\Common\Content\TextContent; |
| 23 | + |
| 24 | +// Create a tool definition |
| 25 | +$tool = Tool::fromArray([ |
| 26 | + 'name' => 'get_weather', |
| 27 | + 'description' => 'Get current weather for a location', |
| 28 | + 'inputSchema' => [ |
| 29 | + 'type' => 'object', |
| 30 | + 'properties' => [ |
| 31 | + 'location' => ['type' => 'string', 'description' => 'City name'], |
| 32 | + ], |
| 33 | + 'required' => ['location'], |
| 34 | + ], |
| 35 | +]); |
| 36 | +``` |
| 37 | + |
| 38 | +## Available Types |
| 39 | + |
| 40 | +### Server Types (`WP\McpSchema\Server\`) |
| 41 | + |
| 42 | +- **Tools** - `Tool`, `CallToolRequest`, `CallToolResult`, `ListToolsRequest`, `ListToolsResult` |
| 43 | +- **Resources** - `Resource`, `ResourceTemplate`, `ReadResourceRequest`, `ReadResourceResult` |
| 44 | +- **Prompts** - `Prompt`, `PromptMessage`, `GetPromptRequest`, `GetPromptResult` |
| 45 | +- **Logging** - `LoggingMessageNotification`, `SetLevelRequest` |
| 46 | + |
| 47 | +### Client Types (`WP\McpSchema\Client\`) |
| 48 | + |
| 49 | +- **Sampling** - `CreateMessageRequest`, `CreateMessageResult`, `SamplingMessage` |
| 50 | +- **Elicitation** - `ElicitRequest`, `ElicitResult` |
| 51 | +- **Roots** - `ListRootsRequest`, `ListRootsResult`, `Root` |
| 52 | + |
| 53 | +### Common Types (`WP\McpSchema\Common\`) |
| 54 | + |
| 55 | +- **Protocol** - `InitializeRequest`, `InitializeResult`, `PingRequest` |
| 56 | +- **Content** - `TextContent`, `ImageContent`, `AudioContent` |
| 57 | +- **JSON-RPC** - `JSONRPCRequest`, `JSONRPCNotification`, `JSONRPCResultResponse`, `JSONRPCErrorResponse` |
| 58 | + |
| 59 | +## Generator |
| 60 | + |
| 61 | +The PHP code in `src/` is auto-generated from the official MCP TypeScript schema. The generator is located in the `generator/` directory and is not included in the Composer package. |
| 62 | + |
| 63 | +See [generator/README.md](generator/README.md) for setup and usage instructions. |
| 64 | + |
| 65 | +## License |
| 66 | + |
| 67 | +MIT License - see [LICENSE](LICENSE) for details. |
| 68 | + |
| 69 | +## Links |
| 70 | + |
| 71 | +- [Model Context Protocol Specification](https://spec.modelcontextprotocol.io/) |
| 72 | +- [MCP GitHub Repository](https://github.com/modelcontextprotocol/modelcontextprotocol) |
0 commit comments