client
Core PHP implementation for the Model Context Protocol (MCP) Client
claude mcp add --transport stdio php-mcp-client npx -y @modelcontextprotocol/server-filesystem /path/to/root \ --env DEBUG="mcp*"
How to use
PHP MCP Client is a library for consuming MCP-enabled servers from a PHP application. It manages a stateful connection to a single MCP server (per Client instance) and provides both synchronous (blocking) and asynchronous (Promise-based) APIs to discover server capabilities (tools, resources, prompts) and to execute requests like calling a tool or reading a resource. The client supports multiple transports, including stdio (via a server process) and HTTP (via server-sent events), and it relies on ReactPHP for non-blocking I/O. Use it when your PHP app needs to interact with external MCP servers in a structured way while preserving the MCP lifecycle (initialize, use capabilities, disconnect).
To get started, configure a Client with a ServerConfig that points to your MCP server, choose a transport (stdio for local server processes or http for remote servers), and then initialize the connection. After initialization, you can list available tools, resources, and prompts, and execute tool calls or read resources. The library also exposes asynchronous variants like listToolsAsync() and callToolAsync() for integration with async PHP applications. Optional components such as a PSR-3 logger, a PSR-16 cache for server definitions, and an event dispatcher can be wired in to fit your application's architecture.
How to install
Prerequisites:
- PHP 8.1 or newer
- Composer installed
Install the PHP MCP Client package via Composer:
composer require php-mcp/client
The package pulls in necessary ReactPHP components (event-loop, promise, stream, child-process, http) automatically. Depending on your environment and transport choice, ensure you have the ability to run server processes (for stdio) or network access to MCP servers (for HTTP/SSE).
After installation, you can start using the Client in your PHP project by autoloading Composer's autoloader and constructing a ServerConfig for your MCP server. See the Quick Start example in the README for concrete usage patterns.
Additional notes
Tips and caveats:
- Always call initialize() or initializeAsync() before attempting any MCP operations, and disconnect() when finished.
- For stdio transport, the MCP server must be executable and accessible from your environment. For HTTP transport, ensure the server URL is reachable.
- If you enable logging, provide a PSR-3 logger to help diagnose transport or protocol issues.
- The client is designed to manage a single server per instance; create separate Client instances for multiple MCP servers.
- If you rely on server definitions or capabilities caching, consider enabling the PSR-16 SimpleCache integration to speed up startup.
- When debugging, the DEBUG environment variable can be used to enable verbose MCP logs if supported by the server implementation.
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