PHPackages                             llm/mcp-server - 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. llm/mcp-server

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

llm/mcp-server
==============

PHP SDK for building MCP servers

1.0.2(7mo ago)431.1k1[1 issues](https://github.com/llm-agents-php/mcp-server/issues)MITPHPPHP &gt;=8.3CI passing

Since Sep 6Pushed 7mo agoCompare

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

READMEChangelog (3)Dependencies (19)Versions (5)Used By (0)

PHP MCP Server SDK
==================

[](#php-mcp-server-sdk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0468e5e2fd7a08f2bbde7510aac6ae77370e31fd3c3af2d9d1470fe8a41b6aa8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6c6d2f6d63702d7365727665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/llm/mcp-server)[![Total Downloads](https://camo.githubusercontent.com/d2098a9565200dc663901b2ea219441e08b6959f0ffa761d4a14e938d7de311a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6c6d2f6d63702d7365727665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/llm/mcp-server)[![License](https://camo.githubusercontent.com/19d524a04281b2990917e6abec80c8661d9836fb4cfb6434f06cd1103443a50a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6c6d2f6d63702d7365727665722e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/7fc6bd1aa28f1d68bca95a1da3a6910458af4b4ba991884ad220f5205c68762d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6c6d2f6d63702d7365727665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/llm/mcp-server)

A comprehensive PHP SDK for building [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction)servers. Create production-ready MCP servers in PHP with modern architecture, flexible transport options, and comprehensive feature support.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
    - [Framework Integration](#framework-integration)
- [Quick Start](#quick-start)
- [Core Concepts](#core-concepts)
- [Transport Options](#transport-options)
    - [STDIO Transport](#stdio-transport-recommended-for-cli)
    - [HTTP Transport with SSE](#http-transport-with-sse)
    - [Streamable HTTP Transport](#streamable-http-transport)
- [Working with Tools](#working-with-tools)
    - [Basic Tool Registration](#basic-tool-registration)
    - [Advanced Tool with Multiple Content Types](#advanced-tool-with-multiple-content-types)
    - [Error Handling in Tools](#error-handling-in-tools)
- [Working with Resources](#working-with-resources)
- [Working with Prompts](#working-with-prompts)
- [HTTP Middleware](#http-middleware)
    - [Built-in Middleware](#built-in-middleware)
        - [CORS Middleware](#cors-middleware)
        - [Authentication Middleware](#authentication-middleware)
    - [Custom Middleware](#custom-middleware)
- [Advanced Configuration](#advanced-configuration)
    - [Complete Server Setup](#complete-server-setup)
    - [Event Store for Resumability](#event-store-for-resumability)
- [Common Patterns](#common-patterns)
    - [Handler Factory Pattern](#handler-factory-pattern)
    - [Decorator Pattern for Handlers](#decorator-pattern-for-handlers)
    - [Class-Based Tool Handlers with Schema Mapping](#class-based-tool-handlers-with-schema-mapping)
- [Ecosystem &amp; Extensions](#ecosystem--extensions)
- [Contributing](#contributing)
- [License](#license)
- [Acknowledgments](#acknowledgments)

> This SDK implements the **MCP 2025-03-26** specification with full backward compatibility support.

Features
--------

[](#features)

- **Complete MCP Implementation**: Full support for tools, resources, prompts, and logging
- **Multiple Transport Options**: STDIO, HTTP with SSE, and streamable HTTP transports
- **Session Management**: Built-in session handling with configurable storage backends
- **Event-Driven Architecture**: ReactPHP-powered asynchronous operations
- **Middleware Support**: PSR-15 compatible HTTP middleware system
- **Type Safety**: Full PHP 8.3+ type declarations and comprehensive error handling
- **Extensible Design**: Pluggable components with clear interfaces
- **Production Ready**: Comprehensive logging, error handling, and testing support

### What's NOT Included

[](#whats-not-included)

This SDK focuses on core MCP functionality and intentionally **does not include**:

- **Resource Discovery**: Automatic scanning and registration of resources from filesystem or annotations
- **Schema Generation**: Automatic generation of JSON schemas from PHP code or docblocks
- **Request Validation**: Built-in validation of incoming requests against defined schemas
- **Framework Integration**: Direct integration with web frameworks (Laravel, Symfony, etc.)

**Why?** These features are better implemented as separate packages or framework-specific bridges that can:

- Provide opinionated conventions for specific use cases
- Integrate deeply with framework ecosystems
- Offer different approaches to schema management
- Maintain focused, single-responsibility packages

Requirements
------------

[](#requirements)

- **PHP** &gt;= 8.3 (required for advanced type features and performance)
- **Extensions**: `json`, `mbstring`, `pcre` (typically bundled with PHP)

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

[](#installation)

```
composer require llm/mcp-server
```

### Framework Integration

[](#framework-integration)

For enhanced developer experience with automatic discovery and validation:

**Spiral Framework**: Use the [spiral/mcp-server](https://github.com/spiral-packages/mcp-server) bridge

```
composer require spiral/mcp-server
```

**Other Frameworks**: Framework-specific bridges are planned. Contributions welcome!

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

[](#quick-start)

Here's a minimal working example that demonstrates core functionality:

```
