php -sdk
PHP implementation of the Model Context Protocol (MCP), enabling seamless integration between LLM applications and external data sources and tools. ✨ Features 🚀 Complete MCP Protocol Support - Full implementation of the MCP specification 🔧 Type-Safe - Leverages PHP 8.1+ type system with enums, union types, and strict typing ⚡ Async First
claude mcp add --transport stdio dalehurley-php-mcp-sdk php path/to/server.php
How to use
The PHP MCP SDK provides a PHP implementation of the Model Context Protocol, enabling PHP applications to expose MCP tools and orchestrate MP-based interactions with LLMs and external data sources. It leverages PHP 8.1+ features, Amphp for asynchronous I/O, and supports multiple transports such as STDIO, HTTP streaming, and WebSocket. Use it to build real-world MCP servers that offer a suite of tools (for example: hello-world, calculator, weather, and framework-integrated samples) which clients can discover, invoke, and compose into larger agent workflows. You can run a server script that boots an MCP server, register tools with their descriptions and input schemas, then connect clients via STDIO or a transport adaptor to list and call those tools. The examples demonstrate both a minimal server and more involved scenarios, including framework integrations and agentic capabilities.
To use the server, start it with a PHP script that boots McpServer and registers one or more tools, then connect a client through a suitable transport (STDIO for local runs, HTTP or WebSocket for remote clients). End users can list available tools, inspect their schemas, and invoke tools with structured arguments. The included examples show how to define tools, describe their input shape, and return structured MCP content that can be rendered by clients. This setup is designed to be composer-based and framework-friendly, so you can embed MCP tooling into Laravel, Symfony, or PSR-compliant components as demonstrated in the documentation.
How to install
Prerequisites:
- PHP 8.1+
- Composer for PHP dependency management
- ext-json and ext-mbstring PHP extensions
Installation steps:
-
Install PHP MCP SDK via Composer: composer require dalehurley/php-mcp-sdk
-
If you want the development/main version: composer require dalehurley/php-mcp-sdk:dev-main
-
Create and run a simple MCP server script (examples are provided in the repository). Example snippet (server.php):
//!/usr/bin/env php
<?php require_once __DIR__ . '/vendor/autoload.php'; use MCP\Server\McpServer; use MCP\Types\Implementation; use MCP\Server\Transport\StdioServerTransport; use function Amp\async; $server = new McpServer( new Implementation('my-php-app', '1.0.0') ); // Register a simple tool (example) $server->tool( 'hello', 'Says hello', [ 'type' => 'object', 'properties' => [ 'name' => ['type' => 'string', 'description' => 'Name to greet'] ], 'required' => ['name'] ], function (array $args): array { $name = $args['name'] ?? 'World'; return ['content' => [['type' => 'text', 'text' => "Hello, {$name}!" ]]]; } ); async(function () use ($server) { $transport = new StdioServerTransport(); $server->connect($transport)->await(); })->await(); -
Run the server: php path/to/server.php
-
To test using a client, follow the examples to connect via STDIO, HTTP streaming, or WebSocket transports as shown in the documentation.
Additional notes
Tips and common issues:
- Ensure PHP 8.1+ and required extensions (ext-json, ext-mbstring) are installed.
- If you’re using a PHP framework, prefer the PSR-compliant structure demonstrated in the framework integration examples.
- When debugging, use the STDIO transport locally to quickly verify tool listing and tool invocation.
- If you encounter transport connection issues, verify that the client and server agree on transport endpoints and that any required environment configuration is set (e.g., base URLs, auth settings).
- The examples include both simple and production-ready patterns (e.g., Docker deployment, Laravel/Symfony integration). Leverage these to adapt MCP tooling to your stack.
Related MCP Servers
mcp
Official MCP Servers for AWS
mcp-router
A Unified MCP Server Management App (MCP Manager).
laravel-restify
Laravel API for Ai Agents and humans.
remote
Remote MCP Server that securely connects Enterprise context with your LLM, IDE, or agent platform of choice.
ollama
An MCP Server for Ollama
furi
CLI & API for MCP management