Get the FREE Ultimate OpenClaw Setup Guide →

mcp

Create production-ready MCP servers in PHP with modern architecture, and flexible transport options.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio llm-agents-php-mcp-server node path/to/server.php \
  --env PHP_VERSION="8.3+" \
  --env COMPOSER_HOME="path/to/composer/cache (optional)"

How to use

This PHP MCP Server SDK provides the core components to build an MCP 2025 compliant server using PHP 8.3+. It includes support for multiple transports (STDIO, HTTP with SSE, and streamable HTTP), a robust registry for tools and resources, a protocol handler, and middleware support. With this SDK you can register custom tools and content handlers, define sessions and dispatch routes, and plug in middleware such as CORS or authentication. The Quick Start example demonstrates wiring the server together with a simple tool and running it over STDIO. You can adapt the same architecture to build a full MCP server that communicates over HTTP or a streamable transport by swapping the transport layer while reusing the protocol, registry, and dispatcher components.

How to install

Prerequisites:

  • PHP >= 8.3
  • Composer

Installation steps:

  1. Install PHP MCP Server package:
composer require llm/mcp-server
  1. If you plan to integrate with a framework, install the corresponding bridge (examples include Spiral Framework bridge):
composer require spiral/mcp-server
  1. (Optional) Install development tooling and autoloading if you want to run examples directly:
composer dump-autoload
  1. Create your server script (for STDIO) or configure your chosen transport, then start the server via PHP:
php path/to/your/server.php
  1. Verify the MCP protocol communication by sending MCP messages through STDIN/STDOUT or through your HTTP transport as configured.

Additional notes

Tips and notes:

  • Ensure PHP 8.3+ is used for full type safety features.
  • Enable required PHP extensions: json, mbstring, and pcre.
  • The SDK is designed to be transport-agnostic; you can swap STDIO for HTTP or Streamable HTTP by implementing or using the provided transport adapters.
  • When testing, you can start with a minimal tool registry and a simple tool to confirm the MCP flow (tool registration, dispatch, and response).
  • If using frameworks, prefer the dedicated bridge packages to leverage automatic discovery and validation.
  • For production, consider configuring a persistent session store and a resilient event loop integration (ReactPHP-based).

Related MCP Servers

Sponsor this space

Reach thousands of developers