PHPackages                             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. [Utility &amp; Helpers](/categories/utility)
4. /
5. php-mcp/schema

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

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

PHP Data Transfer Objects (DTOs) and Enums for the Model Context Protocol (MCP) schema.

1.0.2(9mo ago)18221.6k—2.1%64MITPHPPHP &gt;=8.1

Since Jun 19Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/php-mcp/schema)[ Packagist](https://packagist.org/packages/php-mcp/schema)[ RSS](/packages/php-mcp-schema/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (4)

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

[](#php-mcp-schema)

[![Latest Version on Packagist](https://camo.githubusercontent.com/191327f35ec1c61cb82ab8c849817d97c74c1aaa5974a7a2e7bc2cd2390be702/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d6d63702f736368656d612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/php-mcp/schema)[![Total Downloads](https://camo.githubusercontent.com/8dc4a8b774227880e6df75b3bb591d6b1ea65932a63339ffa075ba2b86c3c40c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068702d6d63702f736368656d612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/php-mcp/schema)[![License](https://camo.githubusercontent.com/5a7e35eed76bad57ea6d4565fd992e32dcdeecb772d976177a9a6057d1e15861/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068702d6d63702f736368656d612e7376673f7374796c653d666c61742d737175617265)](LICENSE)

**Type-safe PHP DTOs for the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) specification.**

This package provides comprehensive Data Transfer Objects and Enums that ensure full compliance with the official MCP schema, enabling robust server and client implementations with complete type safety.

> 🎯 **MCP Schema Version:** [2025-03-26](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-03-26/schema.ts) (Latest)

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

[](#installation)

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

**Requirements:** PHP 8.1+ • No dependencies

Quick Start
-----------

[](#quick-start)

```
use PhpMcp\Schema\Tool;
use PhpMcp\Schema\Resource;
use PhpMcp\Schema\Request\CallToolRequest;

// Create a tool definition
$tool = Tool::make(
    name: 'calculator',
    inputSchema: [
        'type' => 'object',
        'properties' => [
            'operation' => ['type' => 'string'],
            'a' => ['type' => 'number'],
            'b' => ['type' => 'number']
        ],
        'required' => ['operation', 'a', 'b']
    ],
    description: 'Performs basic arithmetic operations'
);

// Serialize to JSON
$json = json_encode($tool);

// Deserialize from array
$tool = Tool::fromArray($decodedData);
```

Core Features
-------------

[](#core-features)

### 🏗️ **Complete Schema Coverage**

[](#️-complete-schema-coverage)

Every MCP protocol type is represented with full validation and type safety.

### 🔒 **Immutable Design**

[](#-immutable-design)

All DTOs use readonly properties to prevent accidental mutations.

### 🚀 **Developer Experience**

[](#-developer-experience)

- **Factory Methods:** Convenient `make()` methods for fluent object creation
- **Array Conversion:** Seamless `toArray()` and `fromArray()` methods
- **JSON Ready:** Built-in `JsonSerializable` interface support
- **Validation:** Comprehensive input validation with clear error messages

### 📦 **Schema Components**

[](#-schema-components)

ComponentDescription**Tools**Tool definitions with JSON Schema validation**Resources**Static and template-based resource representations**Prompts**Interactive prompt definitions with arguments**Content**Text, image, audio, and blob content types**JSON-RPC**Complete JSON-RPC 2.0 protocol implementation**Requests/Results**All 15 request types and corresponding responses**Notifications**Real-time event notification messages**Capabilities**Client and server capability declarationsUsage Patterns
--------------

[](#usage-patterns)

### Creating Protocol Messages

[](#creating-protocol-messages)

```
// Initialize request
$request = InitializeRequest::make(
    protocolVersion: '2025-03-26',
    capabilities: ClientCapabilities::make(),
    clientInfo: Implementation::make('MyClient', '1.0.0')
);

// Call tool request
$callRequest = CallToolRequest::make(
    name: 'calculator',
    arguments: ['operation' => 'add', 'a' => 5, 'b' => 3]
);
```

### Working with Resources

[](#working-with-resources)

```
// Static resource
$resource = Resource::make(
    uri: '/data/users.json',
    name: 'User Database',
    description: 'Complete user registry'
);

// Resource template
$template = ResourceTemplate::make(
    uriTemplate: '/users/{id}',
    name: 'User Profile',
    description: 'Individual user data'
);
```

### Content Handling

[](#content-handling)

```
// Text content
$text = TextContent::make('Hello, world!');

// Image content
$image = ImageContent::make(
    data: base64_encode($imageData),
    mimeType: 'image/png'
);
```

Package Structure
-----------------

[](#package-structure)

```
src/
├── Content/         # Content types (Text, Image, Audio, Blob, etc.)
├── Enum/           # Protocol enums (LoggingLevel, Role)
├── JsonRpc/        # JSON-RPC 2.0 implementation
├── Notification/   # Event notification types
├── Request/        # Protocol request messages
├── Result/         # Protocol response messages
├── Tool.php        # Tool definitions
├── Resource.php    # Resource representations
├── Prompt.php      # Prompt definitions
└── ...            # Core protocol types

```

Why Use This Package?
---------------------

[](#why-use-this-package)

- ✅ **100% MCP Compliance** - Matches official specification exactly
- ✅ **Type Safety** - Catch errors at development time, not runtime
- ✅ **Zero Dependencies** - Lightweight and self-contained
- ✅ **Production Ready** - Immutable, validated, and thoroughly tested
- ✅ **Future Proof** - Updated with latest MCP specification versions

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

---

**Part of the [PHP MCP](https://github.com/php-mcp) ecosystem** • Build type-safe MCP applications with confidence

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance55

Moderate activity, may be stable

Popularity46

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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

Every ~18 days

Total

3

Last Release

297d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/146c2eb02350558d165083e0018f5377f15f0e71493439c93ee60e7c7ac97fc1?d=identicon)[CodeWithKyrian](/maintainers/CodeWithKyrian)

---

Top Contributors

[![CodeWithKyrian](https://avatars.githubusercontent.com/u/48791154?v=4)](https://github.com/CodeWithKyrian "CodeWithKyrian (7 commits)")[![judus](https://avatars.githubusercontent.com/u/1478654?v=4)](https://github.com/judus "judus (2 commits)")

### Embed Badge

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

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

###  Alternatives

[barryvdh/reflection-docblock

1.3k118.6M40](/packages/barryvdh-reflection-docblock)[outlandish/oowp

A plugin for WordPress that makes post types easier to manage

415.4k](/packages/outlandish-oowp)[moell/rss

moell/rss is a package that follows the RSS 2.0 standard

111.8k1](/packages/moell-rss)

PHPackages © 2026

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