modelcontextprotocol /php-sdk
The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation.
★ 1,674⑂ 204👁 24⑃ 536● 202▤ 14
+2
日增长
1,674
stars
204
forks
24
watchers
536
prs
202
issues
14
releases
README
MCP PHP SDK
The official PHP SDK for the Model Context Protocol (MCP). It provides a framework-agnostic API for implementing MCP
servers and clients in PHP — tools, resources, prompts, STDIO and HTTP transports, sessions, authorization, and both
protocol eras (the initialize handshake and the stateless 2026-07-28 revision).
This project represents a collaboration between the PHP Foundation and the Symfony project. It adopts
development practices and standards from the Symfony project, including Coding Standards and the
Backward Compatibility Promise.
Until the first major release, this SDK is considered experimental, please see the roadmap for
planned next steps and features.
Protocol Conformance
Measured weekly against the MCP Conformance Test Framework,
as passing checks out of total. The 2026-07-28 scores run against the framework's alpha releases, so they move as
upstream publishes new scenarios.
| Revision | Server | Client |
|:--------:|:------:|:------:|
| 2026-07-28 | | |
| 2025-11-25 | | |
Installation
bash
composer require mcp/sdk
Build a server
A server is a plain PHP class plus a few lines of wiring:
php
2];
}
}
exit(Server::builder()
-setServerInfo('Calculator', '1.0.0')
-setDiscovery(__DIR__, ['.'], excludeDirs: ['vendor'])
-build()
-run(new StdioTransport()));
The setDiscovery() call needs symfony/finder:
bash
composer require symfony/finder
The walkthrough in First server explains each piece, and
Try it with the Inspector shows it running.
Build a client
php
use Mcp\Client\Client;
use Mcp\Client\Transport\StdioTransport;
$client = Client::builder()
-setClientInfo('My Application', '1.0.0')
-build();
$client-connect(new StdioTransport(command: 'php', args: ['/path/to/server.php']));
$tools = $client-listTools();
$result = $client-callTool('add', ['a' = 5, 'b' = 3]);
$client-disconnect();
See Transports for STDIO and HTTP, Connecting to a server
for timeouts, and Server-initiated requests for the handlers that
answer requests from the server.
Documentation
The full documentation is published at php.sdk.modelcontextprotocol.io.
- Get started — Install the SDK and build your first server
- Servers — Tools, resources, resource templates, prompts, and how to register them
- Inside your handler — Talking back to the client, logging, and asking for input
- Running your server — Server builder, STDIO and HTTP transports, framework integration, sessions, authorization
- Clients — Client SDK for connecting to and communicating with MCP servers
- Protocol versions — The two protocol eras, and what revision 2026-07-28 changed
- Advanced — Events, protocol extensions (including MCP Apps), and custom message handlers
- Deprecation policy — How deprecated features are handled
- SDK tier target — Where the SDK stands on the MCP SDK tiers
- Examples — Runnable server and client examples
- API Reference — Generated class reference
External Resources
- Model Context Protocol DTop issues
#489Slicing the SDK into Multiple Packages4 comments · 2026-08-29#468[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStan3 comments · 2026-08-20#733[Server] Decode an HTTP request body once instead of per pipeline stage2 comments · 2026-11-10#631[Capability] Describe nullable parameters with `anyOf` instead of a `type` array?2 comments · 2026-10-27#309Streamable HTTP server does not validate body/header protocol-version consistency on initialize2 comments · 2026-05-16#286Add server lifecycle events (ServerStarted / ServerStopped)2 comments · 2026-04-16#13[Schema] Generate Schema based on official JSON Schema2 comments · 2025-08-29#495[Server][Capability] Element sources should return values, and RegistryInterface should be sliced by role1 comments · 2026-09-03
Latest release
v0.10.0 v0.10.0 2026-11-10What's Changed TL;DR The SDK is split into the Mcp\Schema, Mcp\Client and Mcp\Server namespaces, ahead of separate packages: most imports change PHP 8.2 or higher is required, and JSON-RPC batches are gone The client authorizes with OAuth: authorization code, client credentials, private_key_jwt and experimental cross-app access Handshake-era servers over HTTP run without sessions unless Builder::setSession() is called, and sessions belong to the principal that opened them Request handlers can run under an event loop (Revolt, ReactPHP) with the opt-in Builder::setFiberScheduler(