Get the FREE Ultimate OpenClaw Setup Guide →

mcp-sdk-php

Model Context Protocol SDK for PHP

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio logiscape-mcp-sdk-php php server.php

How to use

The MCP SDK for PHP provides a PHP-based implementation of the Model Context Protocol, allowing you to build both MCP servers and clients using native PHP. This means you can run an MCP server within typical PHP hosting environments (Apache, FPM, or CLI) and communicate with MCP clients over standard transports like STDIO or HTTP. The server exposes resources, prompts, and tools that clients can invoke via JSON-RPC, and it includes a simple API surface for defining tools and handling lifecycle events. To get started, install the package via Composer, create a server script that instantiates McpServer, define tools, and call run() to start listening for requests. You can also use the provided client classes to connect over STDIO or HTTP transports to interact with your server.

Typical usage involves two pieces: a server script that defines the MCP server and its capabilities, and a client that connects to the server to call tools or query resources. The examples show how to create a basic addition tool and expose it via the server, and how to write a client that connects via the stdio transport to invoke the tool. The HTTP transport and OAuth 2.1 authorization are supported, enabling web-based deployments and secure access patterns. The web client in the repository demonstrates a web UI for testing prompts, tools, and resources against your server.

How to install

Prerequisites before installing:

  • PHP 8.1 or higher
  • PHP extensions: curl (ext-curl), json (ext-json)
  • Optional: ext-pcntl (recommended for CLI environments)
  • Optional: monolog/monolog (for logging in examples)

Install steps:

  1. Ensure PHP and Composer are installed on your system.
  2. Create a new project directory or navigate to your project.
  3. Install the MCP PHP SDK package via Composer:
composer require logiscape/mcp-sdk-php
  1. (Optional) Install logging dependency for examples:
composer require monolog/monolog
  1. Create your MCP server script (for example server.php) that wires up McpServer, defines tools, and calls run(). See the README for examples of defining a tool:
<?php

require 'vendor/autoload.php';

use Mcp\Server\McpServer;

$server = new McpServer('my-mcp-server');
$server
    ->tool('add-numbers', 'Adds two numbers together', function (float $a, float $b): string {
        return 'Sum: ' . ($a + $b);
    })
    ->run();
  1. Run the server via the PHP CLI:
php server.php

If you prefer HTTP-based transports or other clients, configure your server accordingly (for example, through the provided HTTP transport examples in the repo).

Additional notes

Tips and notes:

  • This PHP MCP SDK is designed to work well in shared hosting environments where long-running processes may be restricted. The library includes transport options that can fit typical hosting setups, with attention to lifecycle management.
  • If using the CLI, consider enabling pcntl (if available) for improved process control in longer-running CLI sessions.
  • For testing, the repository includes a web client (webclient) that can connect to a local PHP MCP server. Ensure you expose the correct transport (stdio or HTTP) consistent with your server script.
  • When deploying to production, review OAuth 2.1 integration if you plan to protect HTTP endpoints. The repository mentions an OAuth example; adapt it to your hosting environment and security requirements.
  • If you encounter issues with autoloading or dependencies, running composer dump-autoload can help refresh the autoloader after changes.

Related MCP Servers

Sponsor this space

Reach thousands of developers