Ability to set custom protocol version (#117)
This commit is contained in:
parent
85549cb835
commit
09596c0382
3 changed files with 124 additions and 4 deletions
24
src/Schema/Enum/ProtocolVersion.php
Normal file
24
src/Schema/Enum/ProtocolVersion.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?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\Enum;
|
||||
|
||||
/**
|
||||
* Available protocol versions for MCP.
|
||||
*/
|
||||
enum ProtocolVersion: string
|
||||
{
|
||||
case V2024_11_05 = '2024-11-05';
|
||||
|
||||
case V2025_03_26 = '2025-03-26';
|
||||
|
||||
case V2025_06_18 = '2025-06-18';
|
||||
}
|
||||
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
namespace Mcp\Schema\JsonRpc;
|
||||
|
||||
use Mcp\Schema\Enum\ProtocolVersion;
|
||||
|
||||
/**
|
||||
* Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent.
|
||||
*
|
||||
|
|
@ -19,5 +21,5 @@ namespace Mcp\Schema\JsonRpc;
|
|||
interface MessageInterface extends \JsonSerializable
|
||||
{
|
||||
public const JSONRPC_VERSION = '2.0';
|
||||
public const PROTOCOL_VERSION = '2025-06-18';
|
||||
public const PROTOCOL_VERSION = ProtocolVersion::V2025_06_18;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace Mcp\Schema\Result;
|
||||
|
||||
use Mcp\Exception\InvalidArgumentException;
|
||||
use Mcp\Schema\Enum\ProtocolVersion;
|
||||
use Mcp\Schema\Implementation;
|
||||
use Mcp\Schema\JsonRpc\MessageInterface;
|
||||
use Mcp\Schema\JsonRpc\Response;
|
||||
|
|
@ -38,6 +39,7 @@ class InitializeResult implements ResultInterface
|
|||
public readonly Implementation $serverInfo,
|
||||
public readonly ?string $instructions = null,
|
||||
public readonly ?array $_meta = null,
|
||||
public readonly ?ProtocolVersion $protocolVersion = null,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +68,8 @@ class InitializeResult implements ResultInterface
|
|||
ServerCapabilities::fromArray($data['capabilities']),
|
||||
Implementation::fromArray($data['serverInfo']),
|
||||
$data['instructions'] ?? null,
|
||||
$data['_meta'] ?? null
|
||||
$data['_meta'] ?? null,
|
||||
ProtocolVersion::tryFrom($data['protocolVersion']),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -81,8 +84,9 @@ class InitializeResult implements ResultInterface
|
|||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
$protocolVersion = $this->protocolVersion ?? MessageInterface::PROTOCOL_VERSION;
|
||||
$data = [
|
||||
'protocolVersion' => MessageInterface::PROTOCOL_VERSION,
|
||||
'protocolVersion' => $protocolVersion->value,
|
||||
'capabilities' => $this->capabilities,
|
||||
'serverInfo' => $this->serverInfo,
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in a new issue