Php Sdk
Official PHP SDK for the Model Context Protocol
Replaces —
Who it's for
A team with an existing PHP service wants to let an LLM-powered host call their business logic as MCP tools. They annotate service methods with `#[McpTool]`, start the server over STDIO or HTTP, and the host connects without any custom protocol code.
A framework-based PHP application integrates MCP through `symfony/mcp-bundle` or equivalent community packages, exposing application entities, configuration, or domain actions as resources and tools to AI assistants.
You are not using a supported PHP framework and do not want to write integration glue.
A PHP application acts as an MCP client, connecting to external MCP servers to call their tools or read their resources, using the client SDK's builder API and transport options.
You only need to build a server and have no interest in consuming external MCP servers.
A Drupal site or Kirby CMS installation uses the available MCP modules to expose pages, configuration, and entities as MCP resources, making site content queryable by any MCP-compatible AI host.
Your platform does not have an existing MCP integration module and you prefer not to build one.
The problem
PHP developers building applications that integrate with LLMs have no standardized way to expose tools, data sources, or prompts to AI hosts. Without a shared protocol and a framework-agnostic library, every integration requires custom serialization, transport logic, and schema generation, making it difficult to connect PHP applications to the growing ecosystem of MCP-compatible AI hosts and clients.
How it works
Annotate plain PHP class methods with `#[McpTool]` and `#[McpResource]` to expose them as MCP capabilities. JSON Schema is derived from PHP type hints automatically, removing manual schema authoring.
Ships with both standard MCP transports out of the box. STDIO suits process-based hosts; Streamable HTTP suits web deployments. Optional PSR packages connect the HTTP transport to any PSR-compatible framework.
A matching client API lets PHP applications connect to any MCP server, list tools, call them, read resources, and handle server-initiated requests, all through the same builder pattern used by the server side.
Implements both the `initialize`-handshake protocol era and the stateless `2026-07-28` revision. Conformance against both revisions is verified weekly using the official MCP Conformance Test Framework.
Community libraries connect the SDK to Symfony (`symfony/mcp-bundle`), API Platform (`api-platform/mcp`), Drupal (`drupal/mcp_server`), Kirby CMS, CakePHP, and Nette, enabling MCP in existing applications without restructuring.
Developed under Symfony's coding standards and backward compatibility promise. Once the 1.0 release ships, the BC promise applies to public APIs, giving library authors a stable upgrade path.
Features
- Attribute-driven server definition
- STDIO and Streamable HTTP transports
- Client SDK
- Dual protocol revision support
- Framework integration
- Symfony-grade development standards
How to install
composer require mcp/sdk
Recommended for this setup
Strengths
- Minimal boilerplate: A complete MCP server requires a PHP class with type-hinted methods and three lines of wiring. The SDK derives schemas from native PHP types, handles protocol negotiation, and manages transport, so application code focuses solely on business logic.
- Official and specification-aligned: Produced by the PHP Foundation and Symfony project as the official SDK, not a community fork. Weekly conformance runs against the MCP Conformance Test Framework provide public, verifiable evidence of spec alignment for both server and client roles.
- Framework-agnostic core: The core SDK has no mandatory framework dependency. Symfony Finder is optional for attribute discovery; PSR packages are optional for HTTP. This keeps the library usable in vanilla PHP, Laravel, Symfony, or any other stack.
- Broad ecosystem coverage: The growing list of libraries built on the SDK -- covering Symfony, API Platform, Drupal, Kirby, CakePHP, and Nette -- means most existing PHP applications have a direct integration path without writing custom glue code.
Trade-offs
- Pre-1.0 and experimental: The SDK is explicitly marked experimental until the first major release. Public APIs may change before 1.0 ships. The roadmap documents what is still planned, so teams building production systems should review it before committing.
- Attribute discovery requires symfony/finder: The auto-discovery mechanism that scans directories for `#[McpTool]` and `#[McpResource]` attributes depends on `symfony/finder`. Without it the server starts but registers no capabilities, which may not be obvious to newcomers.
- PHP 8.1 minimum: Named arguments, attributes, and intersection types used by the SDK require PHP 8.1 or later. Projects running on older PHP versions cannot use it.
Tech stack
FAQ
Yes. It is the official PHP SDK for the Model Context Protocol, produced as a collaboration between the PHP Foundation and the Symfony project, and hosted under the `modelcontextprotocol` GitHub organization.
The SDK is explicitly experimental until the first major release. The Symfony backward compatibility promise will apply to public APIs once 1.0 ships. Teams should review the roadmap and changelog before using it in production.
STDIO and Streamable HTTP. Optional PSR packages connect the HTTP transport to any PSR-compatible HTTP server or client. The transport is passed when starting the server or connecting the client.
No. The SDK derives JSON Schema from PHP type hints on method parameters. A method declared as `add(int $a, int $b): int` produces the correct schema automatically.
PHP 8.1 or later. The SDK uses PHP attributes, named arguments, and other PHP 8.1 features that are not available in earlier versions.