logiscape/mcp-sdk-php

Model Context Protocol SDK for PHP

What it is

logiscape/mcp-sdk-php is a PHP software development kit that implements the Model Context Protocol (MCP). MCP is a JSON‑RPC‑style protocol for describing AI‑powered resources such as prompts, tools, and data sources, and for orchestrating calls to large language models. The SDK lets you write both an MCP server (exposes tools, prompts, etc.) and an MCP client (calls those tools) entirely in PHP, which works on typical shared‑hosting stacks (Apache, cPanel, PHP‑FPM).

Who might use it

  • PHP developers who want to expose AI‑driven functionality (e.g., a “add‑numbers” tool, a search tool, or a custom prompt) from a web‑hosted site.
  • Teams building internal AI services that need to interoperate with other MCP‑compatible services written in other languages.
  • Anyone needing a lightweight, stateless way to call LLM‑backed tools from a PHP backend without managing long‑lived processes.

Core features (as described in the README)

Feature What it means for you
Full MCP spec support Implements every version of the protocol from the 2024‑11‑05 spec up to the 2026‑07‑28 “stateless core”. The SDK automatically negotiates the version a peer uses.
Stateless core (2026‑07‑28) No session handshake; each request contains everything needed. Perfect for the request‑per‑process model of typical PHP hosting.
Dual‑era negotiation A single codebase can talk to both modern and legacy MCP peers.
Tools & Tasks extensions (SEP‑2663) Long‑running tool calls return a task handle that can be polled, cancelled, or fed more input. Implemented with a simple file‑based store that works on shared hosting.
Apps extension (SEP‑1865) Attach a host‑rendered HTML UI to a tool with a single ->ui(...) call.
Transport flexibility Communicates over stdio (CLI), HTTP, or any custom transport you implement.
OAuth 2.1 support Optional authentication for HTTP‑based servers.
Conformance‑tested 100 % pass rate on the official MCP conformance suite for both stable and draft spec tracks.
Composer‑installable composer require logiscape/mcp-sdk-php pulls in the library and optional logging (monolog/monolog).

How you would get started (from the README)

  1. Install the SDK with Composer (requires PHP 8.1+ and the curl, json extensions).
    composer require logiscape/mcp-sdk-php
    
  2. Write a server – instantiate Mcp\Server\McpServer, register tools, then call ->run(). The README shows a tiny “add‑numbers” example.
  3. Write a client – create a Mcp\Client\Client, connect to the server (e.g., via php example_server.php using stdio), and call tools with callTool().
  4. Run the examples – the repository ships an examples/ folder that demonstrates every major feature, plus a web‑based client (webclient/) that can be dropped into a public_html directory for quick testing.
  5. Read the docs – detailed guides live under docs/ (server‑dev, client‑dev, tasks, apps, compatibility, testing, etc.).

Maturity & ecosystem

  • Version: v2, with a migration guide from v1.
  • Testing: CI runs unit tests, PHPStan static analysis, and the official MCP conformance harness.
  • Governance: Open‑source MIT‑licensed project with CONTRIBUTING, ROADMAP, and GOVERNANCE docs; community‑driven via issue labels and a tier‑audit.
  • Dependencies: Core only needs PHP extensions; optional logging and OAuth support pull in monolog/monolog.

Bottom line

If you are building PHP‑based services that need to expose or consume AI‑driven tools via the Model Context Protocol, this SDK gives you a ready‑made, spec‑compliant implementation that works on the kind of shared‑hosting environments many PHP sites run on. It abstracts the protocol details, handles version negotiation, and even supports long‑running tasks and UI‑enhanced tools, letting you focus on the actual AI logic.

Related

  • Project
  • Project
  • Project
  • Project
  • Project