Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -56,7 +58,7 @@ class Client

protected readonly LoopInterface $loop;

protected readonly MessageIdGenerator $idGenerator;
protected readonly MessageIdGeneratorInterface $idGenerator;

protected readonly TransportFactory $transportFactory;

Expand Down
7 changes: 3 additions & 4 deletions src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,7 +33,7 @@ class ClientBuilder

protected ?EventDispatcherInterface $eventDispatcher = null;

protected ?MessageIdGenerator $idGenerator = null;
protected ?MessageIdGeneratorInterface $idGenerator = null;

protected ?LoopInterface $loop = null;

Expand Down Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions src/ClientConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/Contracts/MessageIdGeneratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace PhpMcp\Client\Contracts;

interface MessageIdGeneratorInterface
{
public function generate(): string;
}
4 changes: 3 additions & 1 deletion src/Factory/MessageIdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace PhpMcp\Client\Factory;

use PhpMcp\Client\Contracts\MessageIdGeneratorInterface;

/**
* Generates unique IDs for JSON-RPC requests.
*/
class MessageIdGenerator
class MessageIdGenerator implements MessageIdGeneratorInterface
{
private int $counter = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/JsonRpc/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PhpMcp\Client\JsonRpc;

use Psy\Readline\Hoa\ProtocolException;
use PhpMcp\Client\Exception\ProtocolException;

class Error
{
Expand Down
2 changes: 1 addition & 1 deletion src/JsonRpc/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PhpMcp\Client\JsonRpc;

use Psy\Readline\Hoa\ProtocolException;
use PhpMcp\Client\Exception\ProtocolException;

final class Notification extends Message
{
Expand Down