From e60ac51274b01edffc2f63c35fc86faf2168131a Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 11 Sep 2025 17:38:17 +0800 Subject: [PATCH 1/3] update --- composer.json | 5 +++-- src/Client.php | 2 ++ src/ClientConfig.php | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 2a293e6..3aeb9f8 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,9 @@ "react/event-loop": "^1.5", "react/http": "^1.11", "react/promise": "^3.2", - "react/stream": "^1.4" - }, + "react/stream": "^1.4", + "ext-pcntl": "*" + }, "require-dev": { "pestphp/pest": "^2.3 || ^3.0", "mockery/mockery": "^1.6", diff --git a/src/Client.php b/src/Client.php index d0b4ebc..0ef86ee 100644 --- a/src/Client.php +++ b/src/Client.php @@ -31,7 +31,9 @@ use PhpMcp\Client\JsonRpc\Results\ListToolsResult; use PhpMcp\Client\JsonRpc\Results\ReadResourceResult; use PhpMcp\Client\Model\Capabilities; +use PhpMcp\Client\Model\Definitions\PromptDefinition; use PhpMcp\Client\Model\Definitions\ResourceDefinition; +use PhpMcp\Client\Model\Definitions\ResourceTemplateDefinition; use PhpMcp\Client\Model\Definitions\ToolDefinition; use PhpMcp\Client\Transport\Stdio\StdioClientTransport; use Psr\Log\LoggerInterface; diff --git a/src/ClientConfig.php b/src/ClientConfig.php index 5583cb0..0392b1d 100644 --- a/src/ClientConfig.php +++ b/src/ClientConfig.php @@ -35,8 +35,9 @@ class ClientConfig * @param LoggerInterface|null $logger Optional PSR-3 logger. Defaults to NullLogger. * @param CacheInterface|null $cache Optional PSR-16 cache for definition caching. * @param EventDispatcherInterface|null $eventDispatcher Optional PSR-14 dispatcher for notifications. - * @param LoopInterface $loop The ReactPHP event loop instance. + * @param LoopInterface|null $loop The ReactPHP event loop instance. * @param int $definitionCacheTtl TTL for cached definitions (tools, resources etc.) in seconds. + * @param MessageIdGenerator|null $idGenerator Optional message ID generator. */ public function __construct( public readonly string $name, From 18db47088a89d7ff4de4776345bb8cf3aa8b34fa Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 11 Sep 2025 18:19:52 +0800 Subject: [PATCH 2/3] updated: ProtocolException --- src/ClientBuilder.php | 1 - src/JsonRpc/Error.php | 2 +- src/JsonRpc/Notification.php | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ClientBuilder.php b/src/ClientBuilder.php index 55b7554..58c8442 100644 --- a/src/ClientBuilder.php +++ b/src/ClientBuilder.php @@ -4,7 +4,6 @@ namespace PhpMcp\Client; -use Deprecated; use PhpMcp\Client\Exception\ConfigurationException; use PhpMcp\Client\Factory\MessageIdGenerator; use PhpMcp\Client\Factory\TransportFactory; // Added use diff --git a/src/JsonRpc/Error.php b/src/JsonRpc/Error.php index c7fade9..e13ff17 100644 --- a/src/JsonRpc/Error.php +++ b/src/JsonRpc/Error.php @@ -4,7 +4,7 @@ namespace PhpMcp\Client\JsonRpc; -use Psy\Readline\Hoa\ProtocolException; +use PhpMcp\Client\Exception\ProtocolException; class Error { diff --git a/src/JsonRpc/Notification.php b/src/JsonRpc/Notification.php index 6ad7034..5c9ae58 100644 --- a/src/JsonRpc/Notification.php +++ b/src/JsonRpc/Notification.php @@ -4,7 +4,7 @@ namespace PhpMcp\Client\JsonRpc; -use Psy\Readline\Hoa\ProtocolException; +use PhpMcp\Client\Exception\ProtocolException; final class Notification extends Message { From eb15b7878ca960c044fc274060819afa057f01d0 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 12 Sep 2025 12:09:42 +0800 Subject: [PATCH 3/3] update: replace MessageIdGenerator --- src/Client.php | 4 ++-- src/ClientBuilder.php | 6 +++--- src/ClientConfig.php | 7 ++++--- src/Contracts/MessageIdGeneratorInterface.php | 10 ++++++++++ src/Factory/MessageIdGenerator.php | 4 +++- 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 src/Contracts/MessageIdGeneratorInterface.php diff --git a/src/Client.php b/src/Client.php index 0ef86ee..15b9d78 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,6 +5,7 @@ namespace PhpMcp\Client; use PhpMcp\Client\Cache\DefinitionCache; +use PhpMcp\Client\Contracts\MessageIdGeneratorInterface; use PhpMcp\Client\Contracts\TransportInterface; use PhpMcp\Client\Enum\ConnectionStatus; use PhpMcp\Client\Exception\ConfigurationException; @@ -15,7 +16,6 @@ use PhpMcp\Client\Exception\TimeoutException; use PhpMcp\Client\Exception\TransportException; use PhpMcp\Client\Exception\UnsupportedCapabilityException; -use PhpMcp\Client\Factory\MessageIdGenerator; use PhpMcp\Client\Factory\TransportFactory; use PhpMcp\Client\JsonRpc\Message; use PhpMcp\Client\JsonRpc\Notification; @@ -58,7 +58,7 @@ class Client protected readonly LoopInterface $loop; - protected readonly MessageIdGenerator $idGenerator; + protected readonly MessageIdGeneratorInterface $idGenerator; protected readonly TransportFactory $transportFactory; diff --git a/src/ClientBuilder.php b/src/ClientBuilder.php index 58c8442..7363415 100644 --- a/src/ClientBuilder.php +++ b/src/ClientBuilder.php @@ -4,8 +4,8 @@ namespace PhpMcp\Client; +use PhpMcp\Client\Contracts\MessageIdGeneratorInterface; use PhpMcp\Client\Exception\ConfigurationException; -use PhpMcp\Client\Factory\MessageIdGenerator; use PhpMcp\Client\Factory\TransportFactory; // Added use use PhpMcp\Client\Model\Capabilities as ClientCapabilities; use Psr\EventDispatcher\EventDispatcherInterface; @@ -33,7 +33,7 @@ class ClientBuilder protected ?EventDispatcherInterface $eventDispatcher = null; - protected ?MessageIdGenerator $idGenerator = null; + protected ?MessageIdGeneratorInterface $idGenerator = null; protected ?LoopInterface $loop = null; @@ -103,7 +103,7 @@ public function withEventDispatcher(EventDispatcherInterface $eventDispatcher): return $this; } - public function withIdGenerator(MessageIdGenerator $generator): self + public function withIdGenerator(MessageIdGeneratorInterface $generator): self { $this->idGenerator = $generator; diff --git a/src/ClientConfig.php b/src/ClientConfig.php index 0392b1d..bbcde00 100644 --- a/src/ClientConfig.php +++ b/src/ClientConfig.php @@ -4,6 +4,7 @@ namespace PhpMcp\Client; +use PhpMcp\Client\Contracts\MessageIdGeneratorInterface; use PhpMcp\Client\Factory\MessageIdGenerator; use PhpMcp\Client\Model\Capabilities as ClientCapabilities; use Psr\EventDispatcher\EventDispatcherInterface; @@ -26,7 +27,7 @@ class ClientConfig public LoopInterface $loop; - public readonly MessageIdGenerator $idGenerator; + public readonly MessageIdGeneratorInterface $idGenerator; /** * @param string $name The name of this client application. @@ -37,7 +38,7 @@ class ClientConfig * @param EventDispatcherInterface|null $eventDispatcher Optional PSR-14 dispatcher for notifications. * @param LoopInterface|null $loop The ReactPHP event loop instance. * @param int $definitionCacheTtl TTL for cached definitions (tools, resources etc.) in seconds. - * @param MessageIdGenerator|null $idGenerator Optional message ID generator. + * @param MessageIdGeneratorInterface|null $idGenerator Optional message ID generator. */ public function __construct( public readonly string $name, @@ -48,7 +49,7 @@ public function __construct( ?EventDispatcherInterface $eventDispatcher = null, ?LoopInterface $loop = null, public int $definitionCacheTtl = 3600, - ?MessageIdGenerator $idGenerator = null, + ?MessageIdGeneratorInterface $idGenerator = null, ) { $this->logger = $logger ?? new NullLogger; $this->cache = $cache; diff --git a/src/Contracts/MessageIdGeneratorInterface.php b/src/Contracts/MessageIdGeneratorInterface.php new file mode 100644 index 0000000..0cdb5d4 --- /dev/null +++ b/src/Contracts/MessageIdGeneratorInterface.php @@ -0,0 +1,10 @@ +