php-sdk
The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation.
claude mcp add --transport stdio modelcontextprotocol-php-sdk php /absolute/path/to/server.php
How to use
The PHP MCP SDK provides a framework-agnostic way to implement MCP servers and clients using PHP attributes and Symfony-style design patterns. It supports defining MCP capabilities as tools and resources using attributes, discovering them automatically, and exposing them over multiple transports such as STDIO and HTTP. The server builder makes it straightforward to register tools, resources, and session handling, while the included transports enable integration with CLI tools and web applications. Developers can also rely on the provided discovery and caching options to optimize startup and runtime performance.
With the SDK, you can: define MCP elements using attributes like McpTool and McpResource, build an MCP server via Server::builder(), and run it with a chosen transport (STDIO or HTTP). You can also register capabilities manually, manage sessions with various stores (in-memory, files, PSR-16 caches), and customize discovery behavior. The Quick Start demonstrates creating a simple class with tools and a resource, wiring a server script, and testing with an MCP Inspector. This makes it practical to prototype rapid MCP-enabled services in PHP and gradually adopt more framework-specific integrations as your project evolves.
How to install
Prerequisites:
- PHP 8.0 or higher
- Composer (dependency manager for PHP)
- Install the MCP PHP SDK via Composer:
composer require mcp/sdk
- Optionally install framework integrations or tooling you plan to use (examples):
- Symfony components or bundles if you plan to integrate within Symfony projects
- Any PSR-7/PSR-15 HTTP libraries if you plan to use the HTTP transport
- Create your MCP server script and define your elements, then run the server using PHP. See the Quick Start in the README for a minimal example. You may also add tests and CI as you refine the server behavior.
Additional notes
Tips and common considerations:
- The SDK is experimental and subject to API changes; pin versions and monitor the changelog or issues for stabilization progress.
- Discovery can be cached to improve startup time; consider enabling a PSR-16 cache for discovery results.
- If using the HTTP transport, ensure your PSR-7 compatible request/response factories are properly configured.
- For session management, you can switch between in-memory, file-based, or PSR-16 adapters. This is helpful for running multiple server instances or scaling out.
- When testing with the MCP Inspector, you can exercise tools and resources defined by your server to validate behavior before going to production.
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