MCPSERV.CLUB
php-mcp

PHP MCP Server

MCP Server

Build AI‑enabled PHP servers with Model Context Protocol

Stale(60)
22stars
2views
Updated Jul 26, 2025

About

A robust PHP SDK that lets developers expose their applications as MCP Tools, Resources, and Prompts. It supports modern PHP features, multiple transports (stdio, http+sse, streamable HTTP), attribute‑based registration, and extensive testing for production use.

Capabilities

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

PHP MCP Server – A Declarative, High‑Performance MCP Framework

The PHP MCP Server solves a common pain point for developers building AI assistants: connecting PHP‑based business logic to an MCP‑compliant client without writing boilerplate RPC code. By leveraging PHP 8.1 attributes, the framework allows developers to describe tools, prompts, and resources directly on their service classes. The server then exposes these definitions over the MCP protocol, enabling language models such as Claude to invoke them with minimal configuration. This declarative approach reduces friction when integrating PHP services into a multi‑model ecosystem, making it easier to share reusable logic across assistants.

At its core, the server is a lightweight, event‑driven HTTP/STDIO listener that supports two transport modes: stdio for local, line‑by‑line communication and SSE (Server‑Sent Events) for streaming responses. It runs on either the Swow or Swoole extensions, giving developers flexibility to choose their preferred async runtime. The framework includes a full logging stack and Docker support, so teams can deploy the server in CI/CD pipelines or container orchestration platforms with minimal effort.

Key capabilities are exposed through three distinct annotations:

  • – Declares a callable that performs a specific action (e.g., calculations, data fetching). The annotation captures the tool’s name, description, and JSON‑schema‑style parameters, allowing the MCP client to validate arguments before execution.
  • – Defines a template that generates dynamic text based on supplied arguments. This is ideal for templated responses or context‑aware messages that the model can fill in.
  • – Exposes static or generated content via a URI, enabling the model to retrieve files (text, images, etc.) on demand.

Each annotation automatically generates the necessary MCP descriptors and request handlers. The framework also supports custom return types such as , , and , ensuring that binary or structured data is transmitted correctly without manual serialization.

In real‑world scenarios, the PHP MCP Server shines in environments where legacy PHP code needs to be surfaced to modern AI assistants. For example, a financial institution can expose calculation tools (interest rates, amortization schedules) as MCP services; a content management system can provide prompt templates for generating marketing copy; or an e‑commerce backend can serve product images and descriptions via resources. Because the server runs asynchronously on Swow/Swoole, it can handle high request volumes while maintaining low latency—a critical requirement for conversational agents.

Integrating the server into an AI workflow is straightforward: after deploying the PHP MCP Server, a client (e.g., Claude) can discover available tools and prompts through the MCP discovery protocol. The assistant then calls these services by name, passing arguments in JSON format. The server executes the PHP method and streams back the result via stdio or SSE, allowing the assistant to continue generating text while awaiting responses. This tight coupling between PHP logic and AI models enables rapid iteration, robust error handling, and secure data access—all without sacrificing the performance guarantees of native PHP runtimes.