PHPackages                             wordpress/php-mcp-schema - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wordpress/php-mcp-schema

ActiveLibrary

wordpress/php-mcp-schema
========================

PHP DTOs for the Model Context Protocol (MCP) specification

v0.1.0(2w ago)431↑480.6%GPL-2.0-or-laterPHPPHP &gt;=7.4CI passing

Since Mar 2Pushed 2w ago3 watchersCompare

[ Source](https://github.com/WordPress/php-mcp-schema)[ Packagist](https://packagist.org/packages/wordpress/php-mcp-schema)[ Docs](https://github.com/WordPress/php-mcp-schema)[ RSS](/packages/wordpress-php-mcp-schema/feed)WikiDiscussions trunk Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

PHP MCP Schema
==============

[](#php-mcp-schema)

A PHP representation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) schema types.

This package provides Data Transfer Objects (DTOs), Enums, and Unions that mirror the official MCP TypeScript schema. It is **not** an SDK, client, or server implementation; just the type definitions for building your own MCP-compatible applications in PHP.

Installation
------------

[](#installation)

```
composer require wordpress/php-mcp-schema
```

Requires PHP 7.4 or higher.

Usage
-----

[](#usage)

### Creating a Tool Definition

[](#creating-a-tool-definition)

```
use WP\McpSchema\Server\Tools\DTO\Tool;

$tool = Tool::fromArray([
    'name' => 'get_weather',
    'description' => 'Get current weather for a location',
    'inputSchema' => [
        'type' => 'object',
        'properties' => [
            'location' => ['type' => 'string', 'description' => 'City name'],
        ],
        'required' => ['location'],
    ],
]);
```

### Serialization (toArray)

[](#serialization-toarray)

Convert a DTO to a plain array for JSON encoding:

```
use WP\McpSchema\Server\Tools\DTO\Tool;

$tool = Tool::fromArray([
    'name' => 'get_weather',
    'description' => 'Get current weather for a location',
    'inputSchema' => ['type' => 'object', 'properties' => []],
]);

$array = $tool->toArray();
$json  = json_encode($array); // Ready to send over the wire
```

### Deserialization (fromArray)

[](#deserialization-fromarray)

Decode incoming JSON into a fully typed DTO:

```
use WP\McpSchema\Server\Tools\DTO\CallToolRequest;

$json = '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_weather","arguments":{"location":"Paris"}}}';
$data = json_decode($json, true);

$request   = CallToolRequest::fromArray($data);
$tool_name = $request->getTypedParams()->getName(); // "get_weather"
$arguments = $request->getTypedParams()->getArguments(); // ['location' => 'Paris']
```

### Factory / Union Types

[](#factory--union-types)

Use a factory to resolve polymorphic content blocks without knowing the concrete type up front:

```
use WP\McpSchema\Common\Protocol\Factory\ContentBlockFactory;
use WP\McpSchema\Common\Content\DTO\TextContent;

$block = ContentBlockFactory::fromArray(['type' => 'text', 'text' => 'Hello, world!']);

// $block implements ContentBlockInterface; cast when you need the concrete API
if ($block instanceof TextContent) {
    echo $block->getText(); // "Hello, world!"
}
```

### JSON-RPC Messages

[](#json-rpc-messages)

Construct a generic JSON-RPC request for any MCP method:

```
use WP\McpSchema\Common\JsonRpc\DTO\JSONRPCRequest;

$request = JSONRPCRequest::fromArray([
    'jsonrpc' => '2.0',
    'id'      => 1,
    'method'  => 'tools/list',
]);

$json = json_encode($request->toArray());
```

Available Types
---------------

[](#available-types)

### Server Types (`WP\McpSchema\Server\`)

[](#server-types-wpmcpschemaserver)

- **Tools** - `Tool`, `CallToolRequest`, `CallToolResult`, `ListToolsRequest`, `ListToolsResult`
- **Resources** - `Resource`, `ResourceTemplate`, `ReadResourceRequest`, `ReadResourceResult`
- **Prompts** - `Prompt`, `PromptMessage`, `GetPromptRequest`, `GetPromptResult`
- **Logging** - `LoggingMessageNotification`, `SetLevelRequest`

### Client Types (`WP\McpSchema\Client\`)

[](#client-types-wpmcpschemaclient)

- **Sampling** - `CreateMessageRequest`, `CreateMessageResult`, `SamplingMessage`
- **Elicitation** - `ElicitRequest`, `ElicitResult`
- **Roots** - `ListRootsRequest`, `ListRootsResult`, `Root`

### Common Types (`WP\McpSchema\Common\`)

[](#common-types-wpmcpschemacommon)

- **Protocol** - `InitializeRequest`, `InitializeResult`, `PingRequest`
- **Content** - `TextContent`, `ImageContent`, `AudioContent`
- **JSON-RPC** - `JSONRPCRequest`, `JSONRPCNotification`, `JSONRPCResultResponse`, `JSONRPCErrorResponse`

Generator
---------

[](#generator)

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.

See [generator/README.md](generator/README.md) for setup and usage instructions.

License
-------

[](#license)

GPL-2.0-or-later - see [LICENSE.md](LICENSE.md) for details.

Links
-----

[](#links)

- [Model Context Protocol Specification](https://spec.modelcontextprotocol.io/)
- [MCP GitHub Repository](https://github.com/modelcontextprotocol/modelcontextprotocol)

###  Health Score

37

—

LowBetter than 84% of packages

Maintenance96

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 98.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

20d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a60abe9a2c42fe5cf2117b88aac2eab186f0ea3c969f1f4a29d4a09d831153b8?d=identicon)[felixarntz](/maintainers/felixarntz)

---

Top Contributors

[![galatanovidiu](https://avatars.githubusercontent.com/u/2674748?v=4)](https://github.com/galatanovidiu "galatanovidiu (69 commits)")[![ovidiu-galatan](https://avatars.githubusercontent.com/u/191402693?v=4)](https://github.com/ovidiu-galatan "ovidiu-galatan (1 commits)")

---

Tags

phpschemamcpdtoModel Context Protocol

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wordpress-php-mcp-schema/health.svg)

```
[![Health](https://phpackages.com/badges/wordpress-php-mcp-schema/health.svg)](https://phpackages.com/packages/wordpress-php-mcp-schema)
```

###  Alternatives

[php-mcp/server

PHP SDK for building Model Context Protocol (MCP) servers - Create MCP tools, resources, and prompts

822230.3k20](/packages/php-mcp-server)[php-mcp/laravel

Laravel SDK for building Model Context Protocol (MCP) servers - Seamlessly integrate MCP tools, resources, and prompts into Laravel applications

47069.4k1](/packages/php-mcp-laravel)[yorcreative/laravel-argonaut-dto

Argonaut is a lightweight Data Transfer Object (DTO) package for Laravel that supports nested casting, recursive serialization, and validation out of the box. Ideal for service layers, APIs, and clean architecture workflows.

1042.4k1](/packages/yorcreative-laravel-argonaut-dto)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
