php
基于 PHP 实现的 MCP (Model Control Protocol) 服务器框架,通过注解优雅地定义 MCP 服务,支持 Tool、Prompt、Resource 三种处理器,支持Stdio、Sse 两种 transport。
claude mcp add --transport stdio he426100-php-mcp-server php bin/console mcp:test-server
How to use
This PHP MCP Server provides a framework to define MCP services using PHP annotations. It supports three core processors (Tool, Prompt, and Resource), and can communicate over either stdio or Server-Sent Events (SSE). To start a test server, run the command through PHP’s CLI interface provided by the project: php bin/console mcp:test-server. By default the server uses stdio, but you can switch to SSE by passing --transport sse. When running in SSE mode, the server exposes an SSE endpoint at /sse (for example, http://127.0.0.1:8000/sse). The annotations allow you to declare tools, prompts, and resources in your service classes, enabling structured and typed MCP interactions. You can customize tools, prompts, and resources by adding the appropriate annotations in your service classes, and expose them via a generated MCP API that clients can consume over SSE or stdio. Command-line options also include transport and port configuration, so you can tailor the server to your deployment needs.
How to install
Prerequisites:
- PHP >= 8.1
- Composer
- Swow extension (recommended > 1.5) or Swoole (>= 5.1) for better performance
- Docker (optional for containerized runs)
Installation steps:
-
Clone the repository git clone https://github.com/he426100/php-mcp-server cd php-mcp-server
-
Install PHP dependencies with Composer composer install
-
Optional: install the Swow extension (if not already installed) ./vendor/bin/swow-builder --install (Refer to Swow official docs for detailed installation: https://github.com/swow/swow)
-
Run the test server php bin/console mcp:test-server
-
(Optional) Run with SSE transport php bin/console mcp:test-server --transport sse
-
If you want to containerize, you can build a Docker image (see Docker support in README) docker build -t php-mcp-server . docker run --name=php-mcp-server -p 8000:8000 -itd php-mcp-server mcp:test-server --transport sse
Additional notes
Tips and notes:
- The server exposes two transport options: stdio (default) and SSE. Use --transport sse to enable Server-Sent Events.
- Logs are typically written to runtime/server_log.txt by default; you can override the log path by extending AbstractMcpServerCommand and setting a custom $logFilePath.
- Docker support is provided for containerized deployment; you can pass the mcp:test-server command inside the container.
- When using CPX (Composer Package Executor) to run the server directly, you can execute commands like: cpx he426100/php-mcp-server mcp:test-server, and with --transport=sse as needed.
- For advanced usage, you can customize service definitions via Tool, Prompt, and Resource annotations in your PHP classes. Ensure your PHP version and extensions are compatible with Swow/Swoole if you choose to use those runtimes.
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.
relay
An MCP client tool for Prism
elementor
Comprehensive Elementor MCP Server plugin.
mcp
Model Context Protocol for Hyperf
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.