modelcontextprotocol/php-sdk

The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation.

MCP PHP SDK – Quick Overview

What it is – A first‑party PHP library that lets you write Model Context Protocol (MCP) servers and clients. MCP is a protocol for exposing tools, resources, prompts and other AI‑related capabilities to LLMs (think “function calling” but framework‑agnostic). The SDK works with any PHP codebase – no need to be on Symfony, Laravel, etc.

Key pieces

  • Server builder – Turn a plain PHP class with #[McpTool] and #[McpResource] attributes into an MCP‑compliant server.
  • Transports – Communicate over STDIO (for local processes) or HTTP. The transport layer is pluggable.
  • Client API – Discover tools, invoke them, handle server‑initiated requests, and manage sessions/authorisation.
  • Protocol eras – Supports the historic initialize handshake and the newer stateless revision 2026‑07‑28.
  • Conformance testing – Weekly CI runs against the official MCP Conformance Test Framework; badges show current pass rates.

Installation

composer require mcp/sdk

If you want the automatic discovery feature you’ll also need symfony/finder.

Getting started

  • Server – Write a class, annotate methods with #[McpTool] (functions) or #[McpResource] (data), then run the builder:
    exit(Server::builder()
        ->setServerInfo('Calculator', '1.0.0')
        ->setDiscovery(__DIR__, ['.'], excludeDirs: ['vendor'])
        ->build()
        ->run(new StdioTransport()));
    
  • Client – Build a client, connect via STDIO or HTTP, list tools, call a tool, then disconnect:
    $client = Client::builder()
        ->setClientInfo('My App', '1.0.0')
        ->build();
    $client->connect(new StdioTransport(command: 'php', args: ['/path/to/server.php']));
    $result = $client->callTool('add', ['a'=>5,'b'=>3]);
    $client->disconnect();
    

Documentation & examples – Full docs are hosted at https://php.sdk.modelcontextprotocol.io, with sections on getting started, server internals, transports, protocol versions, advanced extensions, and an API reference. Example projects are listed in the repo’s Examples page.

Ecosystem – Several PHP frameworks already ship MCP integrations built on this SDK:

  • API Platform (api-platform/mcp)
  • Kirby CMS (bnomei/kirby-mcp)
  • Drupal (drupal/mcp_server)
  • CakePHP (josbeir/cakephp-synapse)
  • Symfony (symfony/mcp-bundle, symfony/ai-mate)

Contributing – Follow the usual GitHub workflow: open issues, submit PRs, and run the CI checks. The project follows Symfony’s coding standards and backward‑compatibility promise.

License – New contributions are Apache‑2.0; legacy code remains MIT. See the LICENSE file for details.


Bottom line – If you need to expose PHP‑based functionality (tools, config, prompts, etc.) to an LLM via the Model Context Protocol, the MCP PHP SDK gives you a ready‑made, standards‑compliant way to do it, with both server and client sides, multiple transports, and active conformance testing.

Related

  • Project
  • Project
  • Project
  • Project
  • Project