PHP MCP

v1.0.0Developer Toolsstable

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

phpmcpai-integration
Share:
28
Stars
0
Downloads
0
Weekly
0/5

What is PHP MCP?

PHP MCP is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to complete php implementation of the model context protocol (mcp) with server and client support, stdio and http transports, and framework integration

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

This server falls under the Developer Tools category on MCPgee, the world's largest MCP server directory with 33,000+ servers.

Features

  • A complete PHP implementation of the Model Context Protocol

Use Cases

Implement Model Context Protocol in PHP applications.
Build MCP servers and clients with STDIO and HTTP transports.
Integrate MCP with PHP frameworks for AI-powered tools.
dtyq

Maintainer

LicenseMIT
Languagephp
Versionv1.0.0
UpdatedApr 20, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx php

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

How to Set Up and Use PHP MCP

php-mcp is a complete PHP implementation of the Model Context Protocol that lets you build both MCP servers and MCP clients entirely in PHP, without a Node.js or Python runtime. It supports STDIO and HTTP (JSON-RPC) transports, provides annotation-based tool/resource/prompt registration via PHP attributes, and integrates with PHP dependency injection containers. PHP developers can use it to add MCP-compatible AI tool interfaces to existing Laravel, Symfony, or plain PHP applications without leaving the PHP ecosystem.

Prerequisites

  • PHP 7.4 or later (PHP 8.0+ recommended)
  • Composer for dependency management
  • Required PHP extensions: json, mbstring, openssl, pcntl, curl
  • An MCP client such as Claude Desktop or Cursor to connect to your server
1

Install the package via Composer

Add php-mcp to your PHP project using Composer. The package is published on Packagist under the name dtyq/php-mcp.

composer require dtyq/php-mcp
2

Verify required PHP extensions

Check that all required extensions are enabled in your php.ini. The pcntl extension is required for STDIO transport and is usually available on Linux/macOS but disabled on Windows.

php -m | grep -E 'json|mbstring|openssl|pcntl|curl'
3

Define a tool using the McpTool attribute

Annotate a PHP method with #[McpTool] to register it as a callable MCP tool. Parameters are validated against a JSON Schema derived from PHP type hints.

<?php
use Dtyq\PhpMcp\Attribute\McpTool;

class MyTools
{
    #[McpTool(description: 'Add two numbers together')]
    public function add(int $a, int $b): array
    {
        return ['result' => $a + $b];
    }
}
4

Bootstrap the MCP server

Create an Application instance, register your tool classes, and start the server in STDIO mode. The server will listen on stdin/stdout for MCP protocol messages.

<?php
use Dtyq\PhpMcp\Application;

$app = new Application($container, ['sdk_name' => 'my-php-mcp-server']);
$app->registerTool(new MyTools());
$app->runStdio();
5

Configure your MCP client to use the PHP server

Add a configuration entry for your PHP MCP server in your MCP client's config file, pointing to your PHP script with the php binary.

6

Test the connection

Restart your MCP client and ask the AI to list available tools. Your PHP-defined tools should appear by name with their descriptions.

PHP MCP Examples

Client configuration

Claude Desktop config to run a PHP MCP server script via the system PHP binary.

{
  "mcpServers": {
    "php-mcp": {
      "command": "php",
      "args": ["/absolute/path/to/your/server.php"]
    }
  }
}

Prompts to try

Example prompts once your PHP MCP server is running and connected.

- "What tools does the PHP server expose?"
- "Call the add tool with a=5 and b=7"
- "Use the PHP server to validate this JSON schema"
- "Fetch the list of resources available from the PHP MCP server"
- "Call the greet tool with name='World'"

Troubleshooting PHP MCP

pcntl extension not found on Windows

The pcntl extension is not available on Windows. Use HTTP transport mode instead of STDIO, or run the server inside WSL2 (Windows Subsystem for Linux) where pcntl is available.

composer require fails with version conflicts

Ensure your PHP version is 7.4 or later and that the platform constraint in composer.json matches your environment. Run composer diagnose to identify extension or version mismatches.

MCP client cannot communicate with the PHP server

Verify the absolute path to your server.php script is correct in the MCP config. Run php /absolute/path/to/server.php manually in a terminal to check for PHP parse errors before connecting an MCP client.

Frequently Asked Questions about PHP MCP

What is PHP MCP?

PHP MCP is a Model Context Protocol (MCP) server that complete php implementation of the model context protocol (mcp) with server and client support, stdio and http transports, and framework integration It connects AI assistants to external tools and data sources through a standardized interface.

How do I install PHP MCP?

Follow the installation instructions on the PHP MCP GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.

Which AI clients work with PHP MCP?

PHP MCP works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.

Is PHP MCP free to use?

Yes, PHP MCP is open source and available under the MIT license. You can use it freely in both personal and commercial projects.

Browse More Developer Tools MCP Servers

Explore all developer tools servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.

Quick Config Preview

{ "mcpServers": { "php": { "command": "npx", "args": ["-y", "php"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

Ready to use PHP MCP?

Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.

33,000+ ServersFree & Open SourceStep-by-Step Guides