The revision has no way for a server to put a request on a response stream, so a handler that needs input from the user says so in its result instead: a handler returning InputRequiredResult comes back as resultType: "input_required" with the asks and an opaque requestState, and the client retries the same request carrying inputResponses. RequestContext::getInputContext() is what the handler reads them through. RequestStateCodec signs and time-bounds the state, so a tampered or expired one is refused rather than trusted - the state travels through the client, which is not a place to keep something the server later believes.
70 lines
2.1 KiB
PHP
70 lines
2.1 KiB
PHP
<?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\Schema\Result;
|
|
|
|
use Mcp\Exception\InvalidArgumentException;
|
|
use Mcp\Schema\Enum\ProtocolVersion;
|
|
use Mcp\Schema\Enum\ResultType;
|
|
use Mcp\Schema\JsonRpc\ResultInterface;
|
|
use Mcp\Schema\ServerCapabilities;
|
|
|
|
/**
|
|
* The server's response to a `server/discover` request.
|
|
*
|
|
* The modern era's replacement for `InitializeResult`: it reports every
|
|
* version this server speaks rather than negotiating one, and each request
|
|
* picks from that list.
|
|
*
|
|
* @author Christopher Hertel <mail@christopher-hertel.de>
|
|
*/
|
|
class DiscoverResult implements ResultInterface
|
|
{
|
|
/**
|
|
* @param list<ProtocolVersion> $supportedVersions every revision this server can answer
|
|
*/
|
|
public function __construct(
|
|
public readonly array $supportedVersions,
|
|
public readonly ServerCapabilities $capabilities,
|
|
public readonly ?string $instructions = null,
|
|
) {
|
|
if ([] === $this->supportedVersions) {
|
|
throw new InvalidArgumentException('A DiscoverResult must advertise at least one supported version.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* `resultType`, caching hints and serverInfo are wire vocabulary, stamped
|
|
* by {@see \Mcp\Server\Wire\Rev2026Codec} rather than modelled here.
|
|
*
|
|
* @return array{
|
|
* supportedVersions: list<string>,
|
|
* capabilities: ServerCapabilities,
|
|
* instructions?: string,
|
|
* }
|
|
*/
|
|
public function jsonSerialize(): array
|
|
{
|
|
$data = [
|
|
'supportedVersions' => array_values(array_map(
|
|
static fn (ProtocolVersion $version): string => $version->value,
|
|
$this->supportedVersions,
|
|
)),
|
|
'capabilities' => $this->capabilities,
|
|
];
|
|
|
|
if (null !== $this->instructions) {
|
|
$data['instructions'] = $this->instructions;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|