Get the FREE Ultimate OpenClaw Setup Guide →

client

Core PHP implementation for the Model Context Protocol (MCP) Client

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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

Sponsor this space

Reach thousands of developers