Get the FREE Ultimate OpenClaw Setup Guide →

php

A complete PHP implementation of the Model Context Protocol (MCP) with server and client support, STDIO and HTTP transports, and framework integration

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio dtyq-php-mcp php server.php \
  --env MCP_VERSION="1.0.0" \
  --env MCP_APP_NAME="my-server"

How to use

PHP MCP provides a complete PHP-based implementation of the Model Context Protocol with both server and client capabilities. The server supports multiple transport protocols, including STDIO for process-based communication and HTTP for JSON-RPC. It is designed to be framework-agnostic and works well with PSR-15/PSR-11 compatible containers, with optional Hyperf integration for seamless in-framework usage. Typical usage involves running a PHP script that initializes an McpServer instance, registers tools and resources, and then starts listening on the chosen transport (stdio or http).

On the client side, you can connect via STDIO or HTTP to call tools and interact with resources defined by the server. This enables you to expose math operations, data fetching, or any MCP-compliant tool/resource to other services or front-end clients. The README demonstrates both basic server setup and a client example, including how to register tools and how to call a tool and read its response.

How to install

Prerequisites:

  • PHP 7.4+ (8.0+ recommended)
  • Composer for dependency management

Installation steps:

  1. Install PHP MCP via Composer in your project: composer require dtyq/php-mcp

  2. If you plan to use the Hyperf integration, ensure Hyperf is configured in your project and follow the Hyperf integration guide mentioned in the repository docs.

  3. Create a simple server script (server.php) that initializes the MCP server, registers tools/resources, and starts a transport (e.g., stdio or http). Example skeleton (adjust to your container/bootstrapping):

<?php
require_once __DIR__ . '/vendor/autoload.php';

use Dtyq\PhpMcp\Server\McpServer;
use Dtyq\PhpMcp\Shared\Kernel\Application;

$container = /* your PSR-11 container */;
$app = new Application($container, ['sdk_name' => 'my-server']);
$server = new McpServer('my-server', '1.0.0', $app);

// Register tools/resources here
// $server->registerTool(...);

// Start using STDIO transport (or http, etc.)
$server->stdio();
  1. Run the server script with PHP: php server.php

Additional notes

Notes:

  • The server supports multiple transports: STDIO (process-based), HTTP (JSON-RPC), and a streamable HTTP variant (experimental).
  • Ensure required PHP extensions (json, mbstring, openssl, pcntl, curl) are enabled as listed in the README.
  • If you plan to expose tools/resources dynamically, you can utilize HttpTransportAuthenticatedEvent or the Annotation System to auto-register components.
  • When integrating with Hyperf, follow the provided Hyperf Integration Guide for minimal boilerplate and automatic wiring.
  • Use the composer.json PHP version compatibility as a guide to ensure compatibility with PHP 7.4 through 8.3.

Related MCP Servers

Sponsor this space

Reach thousands of developers