PHP MCP SDK logo

PHP MCP SDK

Community
dalehurley

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

Publisherdalehurley
Repositoryphp-mcp-sdk
LanguagePHP
Forks
3
Stars
27
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    PHP MCP SDK exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    27 stars and 3 forks from the linked repository.

PHP MCP SDK

Latest Version PHP Version Total Downloads License Documentation

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

bash
composer require dalehurley/php-mcp-sdk

Development Version

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

⚡ Quick Start

Creating an MCP Server

php
#!/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

php
#!/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";

        // List available tools
        $result = yield $client->listTools();
        echo "📋 Available tools:\n";
        foreach ($result['tools'] as $tool) {
            echo "  - {$tool['name']}: {$tool['description']}\n";
        }

        // Call the weather tool
        $result = yield $client->callTool('get-weather', [
            'location' => 'London, UK'
        ]);

        echo "\n🌤️  Weather result:\n";
        echo $result['content'][0]['text'] . "\n";

        yield $client->close();

    } catch (\Exception $error) {
        echo "❌ Error: " . $error->getMessage() . "\n";
    } finally {
        Loop::stop();
    }
});

Loop::run();

Test Your Implementation

bash
# Run the hello-world server
php examples/getting-started/hello-world-server.php

# Test with Claude Desktop by adding to your configuration:
{
  "mcpServers": {
    "hello-world": {
      "command": "php",
      "args": ["/path/to/examples/getting-started/hello-world-server.php"]
    }
  }
}

# Or test with the MCP Inspector (Node.js required)
npx @modelcontextprotocol/inspector examples/getting-started/hello-world-server.php

🎯 Examples Overview

The PHP MCP SDK includes 20+ comprehensive examples across all skill levels:

🎓 Getting Started (4 examples)

  • Hello World - Simplest possible server and client
  • Calculator - Multi-tool server with math operations
  • File Reader - Secure file system integration
  • Weather Client - External API integration patterns

🏗️ Framework Integration (2 examples)

  • Laravel Integration - Complete Laravel patterns with service container
  • Symfony Integration - Full Symfony integration with DI container

🤖 Agentic AI (4 examples)

  • Working Agentic Demo - Rule-based agent reasoning
  • Personal Assistant - Multi-MCP server coordination
  • Multi-Agent Orchestrator - Specialized agent coordination
  • OpenAI Integration - LLM-powered intelligent agents

🏭 Real-World Applications (5 examples)

  • Blog CMS - Complete content management system
  • Task Manager - Project management with analytics
  • API Gateway - Enterprise API orchestration
  • Code Analyzer - Development quality tools
  • Data Pipeline - ETL and data processing

🏢 Enterprise & Production (3 examples)

  • Docker Deployment - Production containerization
  • Microservices Architecture - Distributed systems patterns
  • Monitoring & Observability - Production monitoring

All examples are tested and working! 🎉

Framework Integration

The PHP MCP SDK is designed to work with any PHP framework through its PSR-compliant architecture.

Laravel Integration

You can use the core PHP MCP SDK directly in Laravel applications:

bash
composer require dalehurley/php-mcp-sdk
php
// In a Laravel controller or service
use MCP\Server\McpServer;
use MCP\Types\Implementation;

class McpController extends Controller
{
    public function createServer()
    {
        $server = new McpServer(
            new Implementation('my-laravel-app', '1.0.0')
        );

        // Register your tools, resources, and prompts
        $server->tool('search-users', 'Search for users', [
            'type' => 'object',
            'properties' => [
                'query' => ['type' => 'string', 'description' => 'Search query']
            ]
        ], function($params) {
            return [
                'content' => [
                    [
                        'type' => 'text',
                        'text' => json_encode(User::where('name', 'like', "%{$params['query']}%")->get())
                    ]
                ]
            ];
        });

        return $server;
    }
}

For a complete Laravel package with service providers, Artisan commands, and Laravel-specific features, see the separate laravel-mcp-sdk package.

📚 Documentation

The most comprehensive MCP SDK documentation in the ecosystem is available in the docs/ directory:

🎓 Getting Started (Beginner-Friendly)

🏗️ Implementation Guides

🤖 Agentic AI Development

🏭 Real-World Applications

🏢 Enterprise & Production

📖 API Reference

🔄 Migration & Examples

Testing

bash
# Run tests
composer test

# Run tests with coverage
composer test-coverage

# Run static analysis
composer phpstan
composer psalm

# Fix code style
composer cs-fix

# Run all checks
composer check

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

Changelog

All notable changes to this project are documented in the CHANGELOG.md. Please update it when making changes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Installation

TypingMind
{
  "mcpServers": {
    "php-mcp-sdk": {
      "command": "php",
      "args": [
        "examples/getting-started/hello-world-server.php"
      ]
    }
  }
}

Use PHP MCP SDK MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once PHP MCP SDK is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add PHP MCP SDK as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the PHP MCP SDK MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "php-mcp-sdk": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the PHP MCP SDK MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the PHP MCP SDK MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use PHP MCP SDK to help me with this task?
PHP MCP SDK
Sure. I read it.
Here is what I found using PHP MCP SDK.

Frequently asked questions

What is the PHP MCP SDK MCP server used for?

PHP MCP SDK is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use PHP MCP SDK MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use PHP MCP SDK with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use PHP MCP SDK MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With PHP MCP SDK connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect PHP MCP SDK MCP to TypingMind?

PHP MCP SDK runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does PHP MCP SDK MCP provide in TypingMind?

PHP MCP SDK exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use PHP MCP SDK MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If PHP MCP SDK requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇