modelcontextprotocol/php-sdk

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

What it solves

MCP (Model Context Protocol) standardizes how AI models, like LLMs, interact with external tools, data, and prompts. Without a common protocol, each integration would need custom wiring. This SDK gives PHP developers an official, framework-agnostic way to build MCP servers (that expose tools and resources) and MCP clients (that connect to and use those servers). It removes the boilerplate of handling protocol details, letting you focus on the actual functionality.

How it works

You define a server as a plain PHP class and mark methods with attributes like #[McpTool] for tools and #[McpResource] for resources. Then you use the server builder to set server info, scan your codebase with setDiscovery(), and run it over an STDIO or HTTP transport. On the client side, you create a Client via its builder, connect to a server (e.g., by spawning a PHP process), list available tools, call them, and disconnect. The SDK supports both the classic initialize handshake and the newer stateless 2026-07-28 revision, and it handles sessions, authorization, and transport specifics.

Who it's for

PHP developers who want to expose application functionality to AI models (by building MCP servers) or who need to connect to existing MCP servers from within PHP applications. It's also useful for framework integrations (like Symfony, Laravel, or Drupal) that want to offer MCP support to their users.

Highlights

  • Official PHP SDK for MCP, developed with the PHP Foundation and Symfony project.
  • Framework-agnostic: works with or without any framework, and integrations exist for Symfony, CakePHP, Drupal, etc.
  • Supports both STDIO and HTTP transports.
  • Covers two protocol eras: the classic initialize handshake and the stateless 2026-07-28 revision.
  • Regularly measured against the MCP Conformance Test Framework to ensure protocol compliance.
  • Attribute-based definitions for tools and resources keep server code clean and concise.
  • Includes a deprecation policy and follows Symfony coding standards and backward compatibility promise.

Related

  • Project
  • Project
  • Project
  • Project
  • Project