[Server] Handle malformed JSON-RPC input graceful (#412)

* Never let a throwable escape Protocol::processInput()

* Validate payload types in the schema hydration methods

* Stop leaking handler exception messages to the client
This commit is contained in:
Christopher Hertel 2026-08-14 22:34:01 +02:00 • committed by GitHub
commit c8ed07bba2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,38 @@
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Tests\Unit\Fixtures;
use Mcp\Schema\JsonRpc\Request;
/**
* Stands in for a message class that fails with an unexpected throwable instead of a proper
* InvalidInputMessageException, e.g. through a PHP TypeError caused by an unvalidated payload.
*
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
final class ThrowingRequest extends Request
{
public static function getMethod(): string
{
return 'test/throwing';
}
protected static function fromParams(?array $params): static
{
throw new \TypeError('Internal detail that must not leak to the client.');
}
protected function getParams(): ?array
{
return null;
}
}