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..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; @@ -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; @@ -56,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 55b7554..7363415 100644 --- a/src/ClientBuilder.php +++ b/src/ClientBuilder.php @@ -4,9 +4,8 @@ namespace PhpMcp\Client; -use Deprecated; +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; @@ -34,7 +33,7 @@ class ClientBuilder protected ?EventDispatcherInterface $eventDispatcher = null; - protected ?MessageIdGenerator $idGenerator = null; + protected ?MessageIdGeneratorInterface $idGenerator = null; protected ?LoopInterface $loop = null; @@ -104,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 5583cb0..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. @@ -35,8 +36,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 MessageIdGeneratorInterface|null $idGenerator Optional message ID generator. */ public function __construct( public readonly string $name, @@ -47,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 @@ +