PHPackages                             dtyq/php-mcp - 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. [API Development](/categories/api)
4. /
5. dtyq/php-mcp

ActiveLibrary[API Development](/categories/api)

dtyq/php-mcp
============

PHP implementation of MCP server and client

0.1.9(5mo ago)289.9k↓18.5%8[1 issues](https://github.com/dtyq/php-mcp/issues)1MITPHPPHP &gt;=7.4CI passing

Since Jun 3Pushed 2mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (13)Versions (15)Used By (1)

PHP MCP
=======

[](#php-mcp)

A complete PHP implementation of the **Model Context Protocol (MCP)**, providing both server and client functionality with support for multiple transport protocols.

[![CI](https://github.com/dtyq/php-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/dtyq/php-mcp/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/4d34cdeb03fcdfdcfc999a265fb73a6fe2b88af74fdec946a7d75c2fff86c2e6/68747470733a2f2f636f6465636f762e696f2f67682f647479712f7068702d6d63702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/dtyq/php-mcp)[![PHP Version](https://camo.githubusercontent.com/d2162e42f65bf34b1f45719a56ff4761acc57dc2a822c61c157b95875c5cdb2a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e34253230253743253230382e30253230253743253230382e31253230253743253230382e32253230253743253230382e332d626c7565)](composer.json)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Latest Version](https://camo.githubusercontent.com/44d818c929d249fbdd586179ece1f5ce2fd103fd6f9b794c54d3e79e3f28ffbc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f647479712f7068702d6d6370)](https://github.com/dtyq/php-mcp/releases)

> **Language**: [English](./README.md) | [简体中文](./README_CN.md)

✨ Key Features
--------------

[](#-key-features)

- 🚀 **Latest MCP Protocol** - Supports MCP 2025-03-26 specification
- 🔧 **Complete Implementation** - Tools, resources, and prompts support
- 🔌 **Multiple Transports** - STDIO ✅, HTTP ✅, Streamable HTTP 🚧
- 🌐 **Framework Compatible** - Works with any PSR-compliant framework, built-in Hyperf integration
- 📚 **Well Documented** - Comprehensive guides in English and Chinese

🚀 Quick Start
-------------

[](#-quick-start)

### Installation

[](#installation)

```
composer require dtyq/php-mcp
```

### Hyperf Framework Quick Integration

[](#hyperf-framework-quick-integration)

If you're using Hyperf framework, integration is extremely simple:

```
// Just one line of code!
Router::addRoute(['POST', 'GET', 'DELETE'], '/mcp', function () {
    return \Hyperf\Context\ApplicationContext::getContainer()->get(HyperfMcpServer::class)->handle('default');
});
```

**Annotation-Based Registration**:

```
class CalculatorService
{
    #[McpTool(description: 'Mathematical calculations')]
    public function calculate(string $operation, int $a, int $b): array
    {
        return ['result' => match($operation) {
            'add' => $a + $b,
            'multiply' => $a * $b,
            default => 0
        }];
    }

    #[McpResource(description: 'System information')]
    public function systemInfo(): TextResourceContents
    {
        return new TextResourceContents('mcp://system/info',
            json_encode(['php' => PHP_VERSION]), 'application/json');
    }
}
```

**Advanced Options**:

- 🔐 **AuthenticatorInterface** - Custom authentication
- 📊 **HttpTransportAuthenticatedEvent** - Dynamic tool/resource registration
- 📝 **Annotation System** - Auto-register tools, resources and prompts

👉 [View Complete Hyperf Integration Guide](./docs/en/server/hyperf-integration.md)

### Basic Server Example

[](#basic-server-example)

```
