- Explore MCP Servers
- php-mcp
Php Mcp
What is Php Mcp
php-mcp is a complete PHP implementation of the Model Context Protocol (MCP), offering both server and client functionalities with support for various transport protocols.
Use cases
Use cases for php-mcp include building APIs, implementing server-client communication in distributed systems, and developing applications that require mathematical calculations or other services based on the MCP.
How to use
To use php-mcp, install it via Composer with ‘composer require dtyq/php-mcp’. For integration with the Hyperf framework, simply add a route in your application to handle MCP requests.
Key features
Key features include support for the latest MCP protocol specification, a complete implementation with tools and resources, multiple transport options (STDIO, HTTP), compatibility with PSR-compliant frameworks, and comprehensive documentation in both English and Chinese.
Where to use
php-mcp can be used in web applications, microservices, and any PHP-based projects that require communication using the Model Context Protocol.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Php Mcp
php-mcp is a complete PHP implementation of the Model Context Protocol (MCP), offering both server and client functionalities with support for various transport protocols.
Use cases
Use cases for php-mcp include building APIs, implementing server-client communication in distributed systems, and developing applications that require mathematical calculations or other services based on the MCP.
How to use
To use php-mcp, install it via Composer with ‘composer require dtyq/php-mcp’. For integration with the Hyperf framework, simply add a route in your application to handle MCP requests.
Key features
Key features include support for the latest MCP protocol specification, a complete implementation with tools and resources, multiple transport options (STDIO, HTTP), compatibility with PSR-compliant frameworks, and comprehensive documentation in both English and Chinese.
Where to use
php-mcp can be used in web applications, microservices, and any PHP-based projects that require communication using the Model Context Protocol.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
PHP MCP
A complete PHP implementation of the Model Context Protocol (MCP), providing both server and client functionality with support for multiple transport protocols.
✨ 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
Installation
composer require dtyq/php-mcp
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)->handler();
});
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
Basic Server Example
<?php
require_once 'vendor/autoload.php';
use Dtyq\PhpMcp\Server\McpServer;
use Dtyq\PhpMcp\Shared\Kernel\Application;
// Create server with simple container
$container = /* your PSR-11 container */;
$app = new Application($container, ['sdk_name' => 'my-server']);
$server = new McpServer('my-server', '1.0.0', $app);
// Add a tool
$server->registerTool(
new \Dtyq\PhpMcp\Types\Tools\Tool('echo', [
'type' => 'object',
'properties' => ['message' => ['type' => 'string']],
'required' => ['message']
], 'Echo a message'),
function(array $args): array {
return ['response' => $args['message']];
}
);
// Start server
$server->stdio(); // or $server->http($request)
Basic Client Example
<?php
use Dtyq\PhpMcp\Client\McpClient;
$client = new McpClient('my-client', '1.0.0', $app);
$session = $client->connect('stdio', ['command' => 'php server.php']);
$session->initialize();
// Call a tool
$result = $session->callTool('echo', ['message' => 'Hello, MCP!']);
echo $result->getContent()[0]->getText();
📖 Documentation
- 📚 Complete Documentation - All guides and references
- 📖 Project Overview - Architecture, features, and use cases
- 🚀 Quick Start Guide - 5-minute tutorial
- 🔧 Server Guides - Build MCP servers
- 📡 Client Guides - Create MCP clients
Working Examples
Check the /examples directory:
stdio-server-test.php- Complete STDIO serverhttp-server-test.php- HTTP server with toolsstdio-client-test.php- STDIO client examplehttp-client-test.php- HTTP client example
🌟 Transport Protocols
| Protocol | Status | Description |
|---|---|---|
| STDIO | ✅ | Process communication |
| HTTP | ✅ | JSON-RPC over HTTP |
| Streamable HTTP | 🚧 | HTTP + Server-Sent Events |
🛠️ Requirements
- PHP: 7.4+ (8.0+ recommended)
- Extensions: json, mbstring, openssl, pcntl, curl
- Composer: For dependency management
🤝 Contributing
We welcome contributions! Please see our issues page for areas where you can help.
git clone https://github.com/dtyq/php-mcp.git
cd php-mcp
composer install
composer test
📄 License
MIT License - see LICENSE file for details.
🙏 Acknowledgments
- Model Context Protocol for the specification
- Anthropic for creating MCP
- The PHP community for excellent tooling and support
⭐ Star this repository if you find it useful!
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.










