Upgrading the MCP PHP SDK
The official PHP SDK for the Model Context Protocol, mcp/sdk, is not at 1.0 yet, and almost every
release breaks something: version 0.10 alone moved nearly all classes into the namespaces Mcp\Server,
Mcp\Client and Mcp\Schema. The package dresscode/upgrade-mcp holds 186 such changes since
version 0.2: with it, DressCode rewrites Mcp\Server to Mcp\Server\Server, providerClass: of
#[CompletionProvider] to provider:, and the removed argument $isManual of the registry; for
the API that is gone, it says what to do next.
Installation
To upgrade an application that still runs on PHP older than 8.4, install DressCode globally, because DressCode itself needs PHP 8.4 (see Where DressCode Runs):
composer global require dresscode/dresscode dresscode/upgrade-mcp phpstan/phpstan
dresscode upgrade today
The second line already rewrites the code: upgrade today finds the data of the package on its own, needs no
configuration, and leaves the style of the code as it is. Upgrading Code describes
the procedure and what to do with what is left. A project that already runs on PHP 8.4 to 8.6 can also add the package as a
development dependency, composer require --dev dresscode/upgrade-mcp phpstan/phpstan, and then run
vendor/bin/dresscode upgrade today.
What Gets Fixed
Here is an MCP server written for the SDK 0.9, in a project on the current version:
use Mcp\Capability\Attribute\CompletionProvider; // Class `Mcp\Capability\Attribute\CompletionProvider` is replaced by `Mcp\Server\Capability\Attribute\CompletionProvider`.
use Mcp\Capability\Attribute\McpTool; // Class `Mcp\Capability\Attribute\McpTool` is replaced by `Mcp\Server\Capability\Attribute\McpTool`.
use Mcp\Exception\ToolCallException; // Class `Mcp\Exception\ToolCallException` is replaced by `Mcp\Server\Exception\ToolCallException`.
use Mcp\Server; // Class `Mcp\Server` is replaced by `Mcp\Server\Server`.
class WeatherServer
{
#[McpTool(name: 'forecast')]
public function forecast(
#[CompletionProvider(providerClass: CityProvider::class)]
string $city,
): string
{
return $city ?: throw new ToolCallException('Unknown city');
}
}
After dresscode upgrade today:
use Mcp\Server\Capability\Attribute\CompletionProvider;
use Mcp\Server\Capability\Attribute\McpTool;
use Mcp\Server\Exception\ToolCallException;
use Mcp\Server\Server;
class WeatherServer
{
#[McpTool(name: 'forecast')]
public function forecast(
#[CompletionProvider(provider: CityProvider::class)]
string $city,
): string
{
return $city ?: throw new ToolCallException('Unknown city');
}
}
DressCode moves every class of the namespace split of version 0.10 to its new place, in imports, type declarations, attributes
and doc comments: Mcp\Client to Mcp\Client\Client, Mcp\Capability\* and
Mcp\Event\* under Mcp\Server, Mcp\JsonRpc\MessageFactory to
Mcp\Schema\MessageFactory. It also renames the classes of older versions, such as Resource to
ResourceDefinition or Psr16StoreSession to Psr16SessionStore, passes by name the factories
before which version 0.9 inserted a parameter, and drops the arguments the SDK removed.
What Is Left to You
Where there is no replacement, DressCode reports the place and says what to do next. This covers, for example, the generic exceptions that version 0.10 split by package, or sampling, which the protocol revision 2026–07–28 drops:
Class `Mcp\Exception\RuntimeException` is removed: use `RuntimeException` of `Mcp\Server\Exception`, `Mcp\Client\Exception` or `Mcp\Schema\Exception`, by the package the code calls, since mcp/sdk 0.10.
Method `Mcp\Server\ClientGateway::sample()` is deprecated: there is no replacement; protocol revision 2026-07-28 drops sampling; call the API of an LLM provider directly, since mcp/sdk 0.8.
DressCode also reports, for example, the classes of the OAuth authorization server that version 0.9 removed, the constructors whose arguments changed meaning, and logging, sampling and roots, which the SDK deprecated in version 0.8 together with the protocol.
Most of the breaks of the SDK change behavior: HTTP status codes, sessions, the validation of arguments. The data does not capture changes in behavior at all; the changelog of the SDK describes them.
Keeping the Old API from Coming Back
The everyday check watches for the old API too, for example in continuous integration, once the configuration adds the types
and the set deprecations (see Upgrading Code). The package carries only
data, no plugin, so you do not have to name it in use:
typeAnalysis: phpstan
use:
- perCs # your standard
- deprecations
What the Package Covers
| library | versions |
|---|---|
mcp/sdk |
0.2 to 0.10 |
Upgrading Code describes how to proceed one major version at a time.