mcp-php
A PHP Server Framework for Model Context Protocol (MCP)
claude mcp add --transport stdio james2037-mcp-php-server php examples/stdio_server.php \ --env MCP_LOG_LEVEL="info" \ --env PHP_DISPLAY_ERRORS="1"
How to use
This MCP server is a PHP implementation of the Model Context Protocol (MCP). It provides a framework for exposing Tools (functions the LLM can call) and Resources (data the LLM can fetch) to a large language model. The SDK supports both STDIO and HTTP transports, allowing you to run a local CLI server for development or expose an HTTP endpoint that can be served by a PHP-enabled web server. You’ll define tools and resources using PHP attributes, register them with a Server instance, and run the server via the chosen transport. Tools are Invokable functions that receive parameters from the LLM and return content, while Resources are read-only data or content that can be requested by the LLM.
With the STDIO example, you get a minimal server that defines an EchoTool (returns a message) and a GreetingResource (provides a greeting). The HTTP example demonstrates how to expose the same capabilities over HTTP using PSR-7/PSR-17 implementations. The server handles JSON-RPC parsing and formatting, so you can query tools and resources with standard MCP requests and receive structured responses.
To interact with the server, send JSON-RPC requests over STDIN/STDOUT for the STDIO transport, or issue HTTP requests to the HTTP transport endpoint. The README includes concrete code examples showing how to define a tool, how to expose a resource, and how to wire those into the server and a transport.
How to install
Prerequisites:
- PHP 8.1 or higher
- Composer for dependency management
Installation steps:
- Install the MCP PHP server package via Composer:
composer require james2037/mcp-php-server
-
(Optional) Create your own server file or use the provided examples to define Tools and Resources. The repository includes an STDIO example (examples/stdio_server.php) and an HTTP example (examples/http_server.php).
-
Run the STDIO server for development:
php examples/stdio_server.php
- Run the HTTP server (assuming you have a web server configured or use PHP's built-in server):
php -S localhost:8000 examples/http_server.php
- Send MCP requests to the running server using the appropriate transport (STDIO or HTTP).
Prerequisites typically include having PHP properly set up (CLI and, for HTTP, a web server like Apache/Nginx with PHP-FPM or PHP's built-in server) and Composer configured on your system.
Additional notes
Tips and caveats:
- The SDK uses PHP 8.1+ attributes to declare Tools and Resources. Ensure your PHP version supports attributes.
- For HTTP transport, the examples rely on PSR-7 and PSR-17 implementations (e.g., nyholm/psr7). These are typically pulled in by composer when you include the HTTP example code.
- When running STDIO servers, the server listens on standard input/output; ensure the environment allows interactive I/O.
- You can customize environment variables (e.g., enabling verbose logging) by passing an env block in the mcp_config entry. Use env vars to control logging levels, feature toggles, or endpoints.
- If you want to deploy via Docker, you can wrap the PHP server in a container and expose the appropriate port; however, the repository documentation focuses on native PHP execution.
- Check for PHP extensions required by your PHP web server (if using HTTP) and ensure file permissions allow reading of autoload files and resources.
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