freshcrate
Skin:/
Home > MCP Servers > mcp-sdk-php

mcp-sdk-php

Model Context Protocol SDK for PHP

Why this rank:Strong adoptionRecent releaseHealthy release cadence

Description

Model Context Protocol SDK for PHP

README

Model Context Protocol SDK for PHP

English | 中文

This package provides a PHP implementation of the Model Context Protocol. The primary goal of this project is to provide both a MCP server and a MCP client using pure PHP, making it easy to use in PHP/Apache/cPanel hosting environments with typical server configurations.

Overview

This PHP SDK implements the full MCP specification, making it easy to:

  • Build MCP clients that can connect to any MCP server
  • Create MCP servers that expose resources, prompts and tools
  • Use standard transports like stdio and HTTP
  • Handle all MCP protocol messages and lifecycle events

This SDK began as a PHP port of the official Python SDK for the Model Context Protocol. It has since been expanded to fully support MCP using native PHP functions, helping to maximize compatibility with most standard web hosting environments.

This SDK is primarily targeted at developers working on frontier AI integration solutions. Some functionality may be incomplete and implementations should undergo thorough testing and security review by experienced developers prior to production use.

Installation

You can install the package via composer:

composer require logiscape/mcp-sdk-php

Requirements

  • PHP 8.1 or higher
  • ext-curl
  • ext-json
  • ext-pcntl (optional, recommended for CLI environments)
  • monolog/monolog (optional, used by example clients/servers for logging)

Basic Usage

Creating an MCP Server

For detailed documentation and examples of MCP servers, see the Server Development Guide.

Here's a complete example of an MCP server that provides a simple tool:

<?php

// An example server with a basic addition tool

require 'vendor/autoload.php';

use Mcp\Server\McpServer;

$server = new McpServer('example-mcp-server');

$server
    // Define a tool
    ->tool('add-numbers', 'Adds two numbers together', function (float $a, float $b): string {
        return 'Sum: ' . ($a + $b);
    })

    // Start the server
    ->run();

Save this as example_server.php

Creating an MCP Client

Here's how to create a client that connects to the example server and calls the addition tool:

<?php

// A basic example client that connects to example_server.php and calls a tool

require 'vendor/autoload.php';

use Mcp\Client\Client;

$client = new Client();

try {
    // Connect to the server over stdio
    $session = $client->connect('php', ['example_server.php']);

    // Call the add-numbers tool with two arguments
    $result = $session->callTool('add-numbers', ['a' => 5, 'b' => 25]);

    // Output the result
    echo $result->content[0]->text . "\n";

} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
    exit(1);
} finally {
    $client->close();
}

Save this as example_client.php and run it:

php example_client.php

Advanced Examples

The "examples" directory includes additional clients and servers for both the STDIO and HTTP transports. All examples are designed to run in the same directory where you installed the SDK.

Some examples use monolog for logging, which can be installed via composer:

composer require monolog/monolog

MCP Web Client

The "webclient" directory includes a web-based application for testing MCP servers. It was designed to demonstrate a MCP client capable of running in a typical web hosting environment.

Setting Up The Web Client

To setup the web client, upload the contents of "webclient" to a web directory, such as public_html on a cPanel server. Ensure that the MCP SDK for PHP is installed in that same directory by running the Composer command found in the Installation section of this README.

Using The Web Client

Once the web client has been uploaded to a web directory, navigate to index.php to open the interface. To connect to the included MCP test server, enter php in the Command field and test_server.php in the Arguments field and click Connect to Server. The interface allows you to test Prompts, Tools, and Resources. There is also a Debug Panel allowing you to view the JSON-RPC messages being sent between the Client and Server.

Web Client Notes And Limitations

This MCP Web Client is intended for developers to test MCP servers, and it is not recommended to be made publicly accessible as a web interface without additional testing for security, error handling, and resource management.

OAuth Authorization

The HTTP server transport includes optional OAuth 2.1 support. For more details see the OAuth Authentication Example.

Documentation

For detailed information about the Model Context Protocol, visit the official documentation.

Latest Updates

The SDK is currently aiming to support the 2025-11-25 revision of the MCP Spec.

Implemented

  • Structured tool output
  • New metadata such as icons
  • Experimental support for tasks
  • Elicitation

Partial Implementation or In Development

  • Experimental support for task-augmented elicitation

Credits

This PHP SDK was developed by:

Additional debugging and refactoring done by Josh Abbott using OpenAI ChatGPT o1 pro mode and OpenAI Codex.

Special acknowledgement to Roman Pronskiy for simplifying the server building process with his convenience wrapper project: https://github.com/pronskiy/mcp

  • Mcp\Server\McpServer — adapted from Pronskiy\Mcp\Server
  • Mcp\Server\McpServerException — adapted from Pronskiy\Mcp\McpServerException

License

The MIT License (MIT). Please see License File for more information.

Release History

VersionChangesUrgencyDate
v1.7.2This update includes expanded docs, bug fixes, and publishes a roadmap for 2026-07-28 spec support. ## What's Changed * docs: use article grammar for MCP examples by @scosemicolon in https://github.com/logiscape/mcp-sdk-php/pull/60 ## New Contributors * @scosemicolon made their first contribution in https://github.com/logiscape/mcp-sdk-php/pull/60 **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.7.1...v1.7.2High5/31/2026
v1.7.1This release includes project quality improvements, including GitHub actions for the official MCP conformance tests along with unit tests and PHPStan. Documentation has been expanded with a formal roadmap, changelog, and other key files expected for a MCP SDK project. **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.7.0...v1.7.1High4/23/2026
v1.7.0This release represents a significant milestone for the SDK: a 100% pass rate on the applicable required [MCP Conformance Tests](https://github.com/modelcontextprotocol/conformance). The included webclient example has been improved and rewritten as a streamlined wrapper for the underlying SDK client. When uploaded to a web server, it can demonstrate both a functional MCP client and MCP server with a single Composer command. **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compaHigh4/21/2026
v1.6.1Bug fix in elicitation results **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.6.0...v1.6.1High4/11/2026
v1.6.0This release adds elicitation support ## What's Changed * Allow custom MCP server version configuration by @vjik in https://github.com/logiscape/mcp-sdk-php/pull/58 ## New Contributors * @vjik made their first contribution in https://github.com/logiscape/mcp-sdk-php/pull/58 **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.5.1...v1.6.0Medium4/10/2026
v1.5.1This release includes additional bug fixes **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.5.0...v1.5.1Medium3/24/2026
v1.5.0This release focuses on bug fixes, code quality improvements, and cleanup of dead code and deprecated features. Support for JSON-RPC batching has been removed. **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.4.0...v1.5.0Low3/22/2026
v1.4.0This release brings new features and changes from the 2025-11-25 revision of the MCP Spec. **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.3.0...v1.4.0Low3/9/2026
v1.3.0This update adds a McpServer convenience wrapper — a developer-friendly, fluent API for creating MCP servers with minimal boilerplate. It's adapted from [pronskiy/mcp](https://github.com/pronskiy/mcp) with enhancements including HTTP transport support and automatic transport routing, allowing both local and remote PHP MCP servers to be created with just a few lines of simple code. **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.2.9...v1.3.0Low2/28/2026
v1.2.9Client side bug fixes and improvements to session management and OAuth support **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.2.8...v1.2.9Low2/8/2026
v1.2.8This release includes bug fixes and improvements to client side OAuth support **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.2.7...v1.2.8Low2/1/2026
v1.2.7This release adds OAuth authorization support to the client side of the SDK, and updates the included webclient for testing both local and remote MCP servers. Server side OAuth authorization support has also been improved, fixing some issues with RS256 for improved compatibility with common authorization server providers. **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.2.6...v1.2.7Low1/31/2026
v1.2.6**Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.2.5...v1.2.6Low12/31/2025
v1.2.5## What's Changed * Fix notification parameter inheritance by @logiscapedev in https://github.com/logiscape/mcp-sdk-php/pull/55 **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.2.4...v1.2.5Low11/7/2025
v1.2.4## What's Changed * code tweaks for Stdio Transport constructor by @TheDigitalOrchard in https://github.com/logiscape/mcp-sdk-php/pull/49 * make properties protected to avoid PHP deprecation errors by @pjordaan in https://github.com/logiscape/mcp-sdk-php/pull/50 * Fix server session handler registration by @logiscapedev in https://github.com/logiscape/mcp-sdk-php/pull/52 * Restore typed parameters for server handlers by @logiscapedev in https://github.com/logiscape/mcp-sdk-php/pull/53 ## Low10/29/2025
v1.2.3## What's Changed * Allow empty value for completion argument by @chriskapp in https://github.com/logiscape/mcp-sdk-php/pull/44 ## New Contributors * @chriskapp made their first contribution in https://github.com/logiscape/mcp-sdk-php/pull/44 **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.2.2...v1.2.3Low7/26/2025
v1.2.2## What's Changed * Update Chinese README with latest SDK details by @jundayw in https://github.com/logiscape/mcp-sdk-php/pull/39 * complete implementation of processSseResponse by @jmenendez-telecoming in https://github.com/logiscape/mcp-sdk-php/pull/43 * Make ToolInputProperties iterable by implementing IteratorAggregate by @happystraw in https://github.com/logiscape/mcp-sdk-php/pull/42 ## New Contributors * @jmenendez-telecoming made their first contribution in https://github.com/logisLow7/12/2025
v1.2.1## What's Changed * Fix WWW-Authenticate link for OAuth metadata by @logiscapedev in https://github.com/logiscape/mcp-sdk-php/pull/38 **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.2.0...v1.2.1Low6/18/2025
v1.2.0## What's Changed * Add OAuth token validation by @logiscapedev in https://github.com/logiscape/mcp-sdk-php/pull/34 * Support OAuth resource metadata by @logiscapedev in https://github.com/logiscape/mcp-sdk-php/pull/35 * Implement OAuth enforcement in HTTP server by @logiscapedev in https://github.com/logiscape/mcp-sdk-php/pull/36 * Add claim validation in JwtTokenValidator by @logiscapedev in https://github.com/logiscape/mcp-sdk-php/pull/37 **Full Changelog**: https://github.com/logiscLow6/12/2025
v1.1.3## What's Changed * refactor: split InitializationState enum from ServerSession to follow SRP by @jundayw in https://github.com/logiscape/mcp-sdk-php/pull/24 * fix: change visibility of multiple handlers to protected for subclass access by @jundayw in https://github.com/logiscape/mcp-sdk-php/pull/23 * Revert "fix: change visibility of multiple handlers to protected for subclass access" by @logiscape in https://github.com/logiscape/mcp-sdk-php/pull/25 * Fix client notification param parsing bLow5/27/2025
v1.1.2## What's Changed * Update Chinese README with latest SDK details by @esrever10 in https://github.com/logiscape/mcp-sdk-php/pull/20 * fix: unmatched } by @kauffinger in https://github.com/logiscape/mcp-sdk-php/pull/21 ## New Contributors * @esrever10 made their first contribution in https://github.com/logiscape/mcp-sdk-php/pull/20 * @kauffinger made their first contribution in https://github.com/logiscape/mcp-sdk-php/pull/21 **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/Low5/19/2025
v1.1.1This is a bug fix release. Thank you to all the new contributors who have been testing the SDK and helping to make it better! ## What's Changed * Fix Tool.php failing due to type mismatch for tools with annotations by @artpi in https://github.com/logiscape/mcp-sdk-php/pull/15 * fix: Make package psr/log v2 compatible by @gerdemann in https://github.com/logiscape/mcp-sdk-php/pull/16 * Remove duplicate class declaration by @swissspidy in https://github.com/logiscape/mcp-sdk-php/pull/17 ##Low4/25/2025
v1.1.0## MCP Protocol Version 2025-03-26 Release This is the first release of the MCP SDK for PHP that implements the 2025-03-26 revision of the MCP protocol. It includes working examples of a PHP-based client and server that can communicate remotely over the HTTP transport. It implements a session management system to support stateful MCP sessions in a standard web hosting environment. ## Next Steps Support for authorization via OAuth 2.1 is currently being explored. There is some framework in pLow4/18/2025
v1.0.1## What's Changed * The MCP Inspector and other non-PHP clients can now connect to PHP MCP servers * add register resources/templates/list by @chengxs1994 in https://github.com/logiscape/mcp-sdk-php/pull/2 ## New Contributors * @chengxs1994 made their first contribution in https://github.com/logiscape/mcp-sdk-php/pull/2 **Full Changelog**: https://github.com/logiscape/mcp-sdk-php/compare/v1.0.0...v1.0.1Low3/22/2025
v1.0.0# MCP SDK for PHP - First Stable Release We're pleased to announce the first stable release of the PHP implementation of the Model Context Protocol (MCP) SDK. This release marks successful client compatibility testing with the official "Everything MCP Server". ## Major Achievement - Successful compatibility test with `@modelcontextprotocol/server-everything`, the official MCP test server - Execution of prompts, tools, and resources through the MCP Web Client in a standard cPanel web hostLow1/21/2025
v1.0.0-alpha.2# MCP SDK for PHP - Alpha Release 1.0.0-alpha.2 This release builds upon the initial alpha, focusing on client-side improvements and cross-SDK compatibility. Major additions include a new web-based testing interface and enhanced type implementations. ## Major Updates - Added MCP Web Client for testing and development - Improved Types classes for better schema compliance - Some PHP client testing with non-PHP MCP servers via stdio ## New Features ### MCP Web Client - Web-based intLow1/3/2025
v1.0.0-alpha# MCP SDK for PHP - Initial Alpha Release This is the initial alpha release of the PHP implementation of the Model Context Protocol (MCP) SDK. The SDK enables standardized context provisioning for Large Language Models (LLMs), separating context handling from LLM interactions. ## Current Features - Full implementation of MCP protocol types and structures according to schema - Support for both MCP server and client development - Stdio transport implementation for local communication - WLow12/22/2024

Dependencies & License Audit

Loading dependencies...

Similar Packages

mcp-client-laravelLaravel-native client for Model Context Protocol (MCP) servers. Built by Redberry (Diamond-tier Laravel partner). Used by LarAgent and other frameworks to enable AI agent functionality.v1.1.1
aiA productive AI coworker that learns, self-improves, and ships work.main@2026-06-06
claude-plugins-officialOfficial, Anthropic-managed directory of high quality Claude Code Plugins.main@2026-06-06
justoneapi-mcpProduction-ready MCP server exposing JustOneAPI endpoints to AI agents with raw JSON responses.main@2026-06-06
pipulateLocal First AI SEO Software on Nix, FastHTML & HTMXmain@2026-06-06

More in MCP Servers

AstrBotAgentic IM Chatbot infrastructure that integrates lots of IM platforms, LLMs, plugins and AI feature, and can be your openclaw alternative. ✨
agentscopeBuild and run agents you can see, understand and trust.
claude-plugins-officialOfficial, Anthropic-managed directory of high quality Claude Code Plugins.
langchain4jLangChain4j is an open-source Java library that simplifies the integration of LLMs into Java applications through a unified API, providing access to popular LLMs and vector databases. It makes impleme