MCPSERV.CLUB
php-mcp

PHP MCP Client

MCP Server

A PHP library to connect, manage, and interact with MCP servers

Stale(55)
41stars
1views
Updated 14 days ago

About

The PHP MCP Client library enables PHP applications to establish stateful connections with Model Context Protocol (MCP) servers over stdio or HTTP+SSE transports. It offers both synchronous and asynchronous APIs for discovering tools, resources, prompts, and executing requests.

Capabilities

Resources
Access data sources
Tools
Execute functions
Prompts
Pre-built templates
Sampling
AI model interactions

PHP MCP Client

The PHP MCP Client bridges PHP applications with servers that implement the Model Context Protocol (MCP), enabling developers to harness external data sources, APIs, and tools directly within their PHP code. By abstracting the intricacies of MCP communication—handshakes, transport negotiation, and request orchestration—the library allows developers to focus on business logic rather than protocol plumbing.

At its core, the client follows MCP’s client‑per‑server model: a single instance maintains a stateful connection to one configured MCP server. This design aligns with the protocol’s specification, ensuring that each PHP host can reliably manage a dedicated session without interference. The connection lifecycle is explicit: (or its async counterpart) performs the handshake, while cleanly tears down the session. This clarity simplifies error handling and resource cleanup in production environments.

The library offers a dual API surface. For straightforward integrations, the synchronous façade exposes blocking methods such as and , making it trivial to query available capabilities or invoke a tool. For high‑performance or concurrent workloads, the Promise‑based asynchronous API (e.g., , ) leverages ReactPHP to provide non‑blocking I/O, enabling developers to orchestrate multiple MCP requests in parallel without blocking the event loop.

Transport flexibility is another standout feature. Whether the server runs as a local process (communicating via ) or is exposed over HTTP with Server‑Sent Events, the client handles both seamlessly. This versatility means the same PHP code can interact with a local CLI tool, a cloud‑hosted API wrapper, or any MCP‑compliant service regardless of deployment topology.

Beyond basic tool invocation, the client supports full resource and prompt interactions. Developers can list resources (), read data (), retrieve prompts (), and even manage dynamic sampling configurations. Coupled with PSR‑compliant integrations— for logging, for optional caching of server definitions, and for event‑driven handling of Server‑Sent Events—the library fits naturally into modern PHP ecosystems.

In practice, the PHP MCP Client shines in scenarios where PHP applications need to delegate complex or stateful operations to external systems. For example, a Laravel application can call an MCP server that interfaces with a codebase or database, enabling AI assistants to fetch code snippets or query data without exposing sensitive infrastructure. Similarly, a Symfony service can offload natural‑language‑driven web browsing to an MCP server that wraps a browser automation tool. By providing a robust, standards‑compliant bridge between PHP and MCP servers, the library empowers developers to integrate AI capabilities into their workflows with minimal friction.