PackageTrack
Sign in Get early access

php-mcp/schema

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

1.0.2 619K downloads/mo #2800 most downloaded on Packagist php-mcp/schema

What this package is like to depend on

Last release 1 years ago

25 Jul 2025

Too new to tell

only 2 release windows

Nearly every release is documented

notes for 3 of 3 stable releases

Nothing withdrawn

no release was ever pulled

1 years old

3 releases · first in 2025

0 releases in the last 12 months

see the full history below

Release timeline

3 releases · Jun 2025 to Jul 2025
2026
Release Pre-release

Releases

latest 3
  1. 1.0.2 25 Jul 2025
    Release notes

    What's Changed

    • Normalize stdClass to array in Request::fromArray() for param type sa… by @judus in #4
    • Fix missing parameters in ClientCapabilities::fromArray() constructor call by @CodeWithKyrian in #5

    New Contributors

    • @judus made their first contribution in #4

    Full Changelog: 1.0.1...1.0.2

    Open source →
  2. 1.0.1 25 Jun 2025
    Release notes

    What's Changed

    • Fix Tool deserialization to preserve empty properties as stdClass by @CodeWithKyrian in #1

    Full Changelog: 1.0.0...1.0.1

    Open source →
  3. 1.0.0 19 Jun 2025
    Release notes

    🎉 Initial Stable Release

    I'm excited to announce the first stable release of php-mcp/schema, a comprehensive PHP implementation of Data Transfer Objects (DTOs) and Enums for the Model Context Protocol (MCP).

    📋 Overview

    This package provides type-safe PHP representations of the complete MCP specification, enabling robust server and client implementations with full schema compliance.

    MCP Schema Version Support: 2025-03-26 (Latest)

    🚀 Key Features

    Core DTOs and Schema Support

    • Complete MCP Schema Coverage: Full implementation of all MCP protocol types
    • Type Safety: Strongly-typed PHP classes with readonly properties for immutability
    • JSON Serialization: Built-in JsonSerializable support for seamless API communication
    • Validation: Comprehensive input validation with meaningful error messages

    Protocol Components

    🛠️ Tools & Resources

    • Tool - Tool definitions with JSON Schema validation
    • Resource - Static resource representations
    • ResourceTemplate - Dynamic resource templates with URI patterns
    • ToolAnnotations - Rich metadata for tool descriptions

    📝 Content Types

    • TextContent - Plain text content handling
    • ImageContent - Image content with MIME type support
    • AudioContent - Audio content representation
    • BlobResourceContents - Binary resource handling
    • EmbeddedResource - Embedded resource content

    🔄 Communication Layer

    • JSON-RPC 2.0: Complete implementation (Request, Response, Error, Notification)
    • Batch Operations: Support for batch requests and responses
    • Message Parsing: Robust JSON-RPC message parsing utilities

    📨 Request & Response Types

    • 15 Request Types: From InitializeRequest to CreateSamplingMessageRequest
    • 12 Result Types: Corresponding response objects for all operations
    • 9 Notification Types: Real-time event notifications

    🎯 Prompts & Capabilities

    • Prompt - Interactive prompt definitions
    • PromptArgument - Structured prompt parameters
    • ClientCapabilities & ServerCapabilities - Capability negotiation
    • ModelPreferences - LLM model preference specifications

    Developer Experience Features

    🏭 Factory Methods

    Every DTO includes convenient static factory methods:

    $tool = Tool::make('calculator', $schema, 'A calculator tool');
    $resource = Resource::make('/api/data', 'Dataset', 'Sample dataset');

    🔄 Array Conversion

    Seamless conversion between PHP objects and arrays:

    // To array (for JSON encoding)
    $toolArray = $tool->toArray();
    
    // From array (from JSON decoding)  
    $tool = Tool::fromArray($decodedData);

    ✅ Input Validation

    Comprehensive validation with descriptive error messages:

    • Required field validation
    • Type checking
    • Schema compliance verification
    • JSON Schema validation for tool inputs

    📦 Installation

    composer require php-mcp/schema

    Requirements:

    • PHP 8.1 or higher
    • No additional dependencies

    🎯 Use Cases

    • MCP Server Development: Build compliant MCP servers with type safety
    • MCP Client Development: Create robust clients with validated schemas
    • API Integration: Seamless JSON serialization for MCP communication
    • Testing: Mock MCP protocol interactions with real schema objects
    • Documentation: Self-documenting code with comprehensive type hints

    🔧 Architecture Highlights

    • Immutable Design: Readonly properties prevent accidental mutations
    • PSR Compliance: Follows PHP standards and best practices
    • Zero Dependencies: Lightweight with no external requirements
    • Full Coverage: Every MCP protocol type is represented

    📁 Package Structure

    src/
    ├── Content/          # Content type DTOs (Text, Image, Audio, etc.)
    ├── Enum/            # Protocol enums (LoggingLevel, Role)
    ├── JsonRpc/         # JSON-RPC protocol implementation
    ├── Notification/    # Notification message types
    ├── Request/         # Request message types  
    ├── Result/          # Response result types
    ├── Tool.php         # Core tool definitions
    ├── Resource.php     # Resource representations
    ├── Prompt.php       # Prompt definitions
    └── ...             # Additional core types
    

    🛣️ What's Next

    This stable release provides the foundation for the broader PHP MCP ecosystem:

    • php-mcp/server: SDK for MCP server implementation
    • php-mcp/client: SDK for MCP client implementation
    • php-mcp/laravel: Laravel integration package

    📖 Documentation

    🤝 Contributing

    Contributions are welcome! This package aims to maintain 100% compatibility with the official MCP specification.

    📄 License

    MIT License - see LICENSE file for details.

    Open source →

Every package, every release, already written down.

The archive is open and free. Watching your own project is what we are building next.

Browse the archive