server
Core PHP implementation for the Model Context Protocol (MCP) server
claude mcp add --transport stdio php-mcp-server php /absolute/path/to/your/mcp-server.php \ --env MCP_LOG_LEVEL="debug (optional)"
How to use
This PHP MCP Server SDK lets you expose your PHP application's functionality as standardized MCP elements (Tools, Resources, Prompts) so AI assistants can interact with your backend via MCP. The server emphasizes a modern PHP 8.1+ architecture, attribute-based discovery, and multiple transports (such as stdio, HTTP/SSE, and streamable HTTP) for high-concurrency scenarios. To use it, you typically write your MCP elements (Tools, Resources, Prompts) using PHP attributes like #[McpTool], #[McpResource], and optionally #[Schema] for automatic JSON schema generation, then run a PHP script that builds the server, discovers those elements, and starts listening on a chosen transport (stdio for local client processes or HTTP for web clients).
Once running, you can connect an MCP client by configuring a client manifest (for example, an mcp.json file) that points to your local PHP server script. The client will be able to call registered tools and access resources and prompts, with the server handling JSON-RPC requests, validation, and schema generation. The SDK also supports batch requests, smart caching of discovered elements, and dependency injection for scalable, production-ready deployments.
How to install
Prerequisites
- PHP 8.1 or newer
- Composer (for PHP package management)
Install the MCP PHP server package
- Create a project directory and navigate into it
- Install via Composer:
composer require php-mcp/server
Optionally install framework or integration packages as needed
- Laravel integration: php-mcp/laravel (for Laravel apps)
Usage preparation
- Create your MCP elements with PHP attributes (Tools, Resources, Prompts)
- Create a server script (e.g., mcp-server.php) that builds the server, discovers elements, and starts the transport
Run the server
php /path/to/mcp-server.php
Test client configuration
- Create a client manifest (e.g., .cursor/mcp.json) that points to your PHP server script and defines the available MCP servers (names, endpoints, etc.)
Additional notes
Tips and considerations:
- Ensure PHP 8.1+ and required extensions (json, mbstring, pcre) are enabled.
- Use attribute-based discovery to register Tools, Resources, and Prompts automatically during startup.
- Transport choices: stdio is convenient for local testing; HTTP/SSE or Streamable HTTP are better for web integrations and larger clients.
- The server supports JSON-RPC batch requests, smart caching of discovered elements, and PSR-11 container support for dependency injection.
- If you encounter class loading issues, verify Composer autoload is configured correctly and that your element namespaces match the discovery basePath.
- Configure environment variables (e.g., MCP_LOG_LEVEL) to tailor logging and behavior in different environments.
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