Skip to content

Php MCP SDK

PHP implementation of the Model Context Protocol (MCP), enabling seamless integration between LLM applications and external data sources and tools. Features Complete MCP…

Install

$git clone https://github.com/dalehurley/php-mcp-sdk

Install command taken from the project's README or registry entry. Always review code before running it.

PHP MCP 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 - Built on Amphp for non-blocking I/O operations
  • 🔌 Multiple Transports - STDIO, HTTP Streaming, and WebSocket
  • 🔐 OAuth 2.0 Ready - Built-in authentication with PKCE support
  • 🏗️ Framework Integration - Laravel, Symfony, and PSR-compatible design
  • 📦 PSR Compliant - Follows PSR-4, PSR-7, PSR-12, and PSR-15 standards
  • 🛡️ Production Ready - Comprehensive error handling, logging, and monitoring
  • 🤖 Agentic AI Support - Build intelligent AI agents with MCP tool orchestration
  • 🏭 Real-World Examples - Complete applications (Blog CMS, Task Manager, API Gateway)
  • 📚 Comprehensive Documentation - Best-in-class documentation with tested examples
  • 🧪 Automated Testing - All documentation examples are automatically tested

📋 Requirements

  • PHP 8.1+ - Leverages modern PHP features
  • Composer - For dependency management
  • ext-json - JSON processing
  • ext-mbstring - String handling

🚀 Installation

Via Composer

composer require dalehurley/php-mcp-sdk

Development Version

composer require dalehurley/php-mcp-sdk:dev-main

⚡ Quick Start

Creating an MCP Server

#!/usr/bin/env php
<?php
require_once __DIR__ . '/vendor/autoload.php';

use MCP\Server\McpServer;
use MCP\Server\Transport\StdioServerTransport;
use MCP\Types\Implementation;
use function Amp\async;

// Create the simplest possible MCP server
$server = new McpServer(
    new Implementation(
        'hello-world-server',
        '1.0.0'
    )
);

// Add a simple "say_hello" tool
$server->tool(
    'say_hello',
    'Says hello to someone',
    [
        'type' => 'object',
        'properties' => [
            'name' => [
                'type' => 'string',
                'description' => 'Name of the person to greet'
            ]
        ],
        'required' => ['name']
    ],
    function (array $args): array {
        $name = $args['name'] ?? 'World';

        return [
            'content' => [
                [
                    'type' => 'text',
                    'text' => "Hello, {$name}! 👋 Welcome to MCP!"
                ]
            ]
        ];
    }
);

// Start the server
async(function () use ($server) {
    echo "🚀 Hello World MCP Server starting...\n";

    $transport = new StdioServerTransport();
    $server->connect($transport)->await();
})->await();

Creating an MCP Client

#!/usr/bin/env php
<?php
require_once __DIR__ . '/vendor/autoload.php';

use MCP\Client\Client;
use MCP\Client\Transport\StdioClientTransport;
use MCP\Types\Implementation;
use Amp\Loop;

// Create client
$client = new Client(
    new Implementation('weather-client', '1.0.0')
);

// Connect to weather server
$transport = new StdioClientTransport([
    'command' => 'php',
    'args' => [__DIR__ . '/weather-server.php']
]);

Amp\async(function() use ($client, $transport) {
    try {
        // Connect to server
        yield $client->connect($transport);
        echo "✅ Connected to weather server\n";

Similar plugs

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

Java 面试 & 后端通用面试指南,覆盖计算机基础、数据库、分布式、高并发、系统设计与 AI 应用开发

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype…