php
A complete PHP implementation of the Model Context Protocol (MCP) with server and client support, STDIO and HTTP transports, and framework integration
claude mcp add --transport stdio dtyq-php-mcp php server.php \ --env MCP_VERSION="1.0.0" \ --env MCP_APP_NAME="my-server"
How to use
PHP MCP provides a complete PHP-based implementation of the Model Context Protocol with both server and client capabilities. The server supports multiple transport protocols, including STDIO for process-based communication and HTTP for JSON-RPC. It is designed to be framework-agnostic and works well with PSR-15/PSR-11 compatible containers, with optional Hyperf integration for seamless in-framework usage. Typical usage involves running a PHP script that initializes an McpServer instance, registers tools and resources, and then starts listening on the chosen transport (stdio or http).
On the client side, you can connect via STDIO or HTTP to call tools and interact with resources defined by the server. This enables you to expose math operations, data fetching, or any MCP-compliant tool/resource to other services or front-end clients. The README demonstrates both basic server setup and a client example, including how to register tools and how to call a tool and read its response.
How to install
Prerequisites:
- PHP 7.4+ (8.0+ recommended)
- Composer for dependency management
Installation steps:
-
Install PHP MCP via Composer in your project: composer require dtyq/php-mcp
-
If you plan to use the Hyperf integration, ensure Hyperf is configured in your project and follow the Hyperf integration guide mentioned in the repository docs.
-
Create a simple server script (server.php) that initializes the MCP server, registers tools/resources, and starts a transport (e.g., stdio or http). Example skeleton (adjust to your container/bootstrapping):
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Dtyq\PhpMcp\Server\McpServer;
use Dtyq\PhpMcp\Shared\Kernel\Application;
$container = /* your PSR-11 container */;
$app = new Application($container, ['sdk_name' => 'my-server']);
$server = new McpServer('my-server', '1.0.0', $app);
// Register tools/resources here
// $server->registerTool(...);
// Start using STDIO transport (or http, etc.)
$server->stdio();
- Run the server script with PHP: php server.php
Additional notes
Notes:
- The server supports multiple transports: STDIO (process-based), HTTP (JSON-RPC), and a streamable HTTP variant (experimental).
- Ensure required PHP extensions (json, mbstring, openssl, pcntl, curl) are enabled as listed in the README.
- If you plan to expose tools/resources dynamically, you can utilize HttpTransportAuthenticatedEvent or the Annotation System to auto-register components.
- When integrating with Hyperf, follow the provided Hyperf Integration Guide for minimal boilerplate and automatic wiring.
- Use the composer.json PHP version compatibility as a guide to ensure compatibility with PHP 7.4 through 8.3.
Related MCP Servers
drift
Codebase intelligence for AI. Detects patterns & conventions + remembers decisions across sessions. MCP server for any IDE. Offline CLI.
laravel
A Laravel package for implementing secure Model Context Protocol servers using Streamable HTTP and SSE transport, providing real-time communication and a scalable tool system for enterprise environments.
php
基于 PHP 实现的 MCP (Model Control Protocol) 服务器框架,通过注解优雅地定义 MCP 服务,支持 Tool、Prompt、Resource 三种处理器,支持Stdio、Sse 两种 transport。
mcp-profiler-bundle
The Symfony MCP Profiler Bundle mimics the WebProfiler Bundle. It bridges the gap between Profiler data and your favorite MCP-enabled AI-powered IDE.
elementor
Comprehensive Elementor MCP Server plugin.
mcp
Model Context Protocol for Hyperf