Get the FREE Ultimate OpenClaw Setup Guide →

server

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

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-server php /absolute/path/to/your/mcp-server.php \
  --env MCP_LOG_LEVEL="debug (optional)"

How to use

This PHP MCP Server SDK lets you expose your PHP application's functionality as standardized MCP elements (Tools, Resources, Prompts) so AI assistants can interact with your backend via MCP. The server emphasizes a modern PHP 8.1+ architecture, attribute-based discovery, and multiple transports (such as stdio, HTTP/SSE, and streamable HTTP) for high-concurrency scenarios. To use it, you typically write your MCP elements (Tools, Resources, Prompts) using PHP attributes like #[McpTool], #[McpResource], and optionally #[Schema] for automatic JSON schema generation, then run a PHP script that builds the server, discovers those elements, and starts listening on a chosen transport (stdio for local client processes or HTTP for web clients).

Once running, you can connect an MCP client by configuring a client manifest (for example, an mcp.json file) that points to your local PHP server script. The client will be able to call registered tools and access resources and prompts, with the server handling JSON-RPC requests, validation, and schema generation. The SDK also supports batch requests, smart caching of discovered elements, and dependency injection for scalable, production-ready deployments.

How to install

Prerequisites

  • PHP 8.1 or newer
  • Composer (for PHP package management)

Install the MCP PHP server package

  1. Create a project directory and navigate into it
  2. Install via Composer:
composer require php-mcp/server

Optionally install framework or integration packages as needed

  • Laravel integration: php-mcp/laravel (for Laravel apps)

Usage preparation

  • Create your MCP elements with PHP attributes (Tools, Resources, Prompts)
  • Create a server script (e.g., mcp-server.php) that builds the server, discovers elements, and starts the transport

Run the server

php /path/to/mcp-server.php

Test client configuration

  • Create a client manifest (e.g., .cursor/mcp.json) that points to your PHP server script and defines the available MCP servers (names, endpoints, etc.)

Additional notes

Tips and considerations:

  • Ensure PHP 8.1+ and required extensions (json, mbstring, pcre) are enabled.
  • Use attribute-based discovery to register Tools, Resources, and Prompts automatically during startup.
  • Transport choices: stdio is convenient for local testing; HTTP/SSE or Streamable HTTP are better for web integrations and larger clients.
  • The server supports JSON-RPC batch requests, smart caching of discovered elements, and PSR-11 container support for dependency injection.
  • If you encounter class loading issues, verify Composer autoload is configured correctly and that your element namespaces match the discovery basePath.
  • Configure environment variables (e.g., MCP_LOG_LEVEL) to tailor logging and behavior in different environments.

Related MCP Servers

Sponsor this space

Reach thousands of developers