From cd015fd05b012225fa21e70951bd242737683c86 Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Mon, 26 May 2025 21:35:20 +0200 Subject: [PATCH] refactor: introduce Interface suffic --- examples/cli/src/Builder.php | 8 ++++---- src/Server.php | 4 ++-- src/Server/JsonRpcHandler.php | 8 ++++---- .../NotificationHandler/BaseNotificationHandler.php | 4 ++-- ...cationHandler.php => NotificationHandlerInterface.php} | 2 +- src/Server/RequestHandler/BaseRequestHandler.php | 4 ++-- .../{RequestHandler.php => RequestHandlerInterface.php} | 2 +- src/Server/Transport/Sse/Store/CachePoolStore.php | 4 ++-- .../Transport/Sse/{Store.php => StoreInterface.php} | 2 +- src/Server/Transport/Sse/StreamTransport.php | 6 +++--- src/Server/Transport/Stdio/SymfonyConsoleTransport.php | 4 ++-- src/Server/{Transport.php => TransportInterface.php} | 2 +- tests/Fixtures/InMemoryTransport.php | 4 ++-- 13 files changed, 27 insertions(+), 27 deletions(-) rename src/Server/{NotificationHandler.php => NotificationHandlerInterface.php} (85%) rename src/Server/{RequestHandler.php => RequestHandlerInterface.php} (89%) rename src/Server/Transport/Sse/{Store.php => StoreInterface.php} (91%) rename src/Server/{Transport.php => TransportInterface.php} (90%) diff --git a/examples/cli/src/Builder.php b/examples/cli/src/Builder.php index 7b91d2b..40e5a9c 100644 --- a/examples/cli/src/Builder.php +++ b/examples/cli/src/Builder.php @@ -5,9 +5,8 @@ use PhpLlm\McpSdk\Capability\PromptChain; use PhpLlm\McpSdk\Capability\ResourceChain; use PhpLlm\McpSdk\Capability\ToolChain; -use PhpLlm\McpSdk\Server\NotificationHandler; use PhpLlm\McpSdk\Server\NotificationHandler\InitializedHandler; -use PhpLlm\McpSdk\Server\RequestHandler; +use PhpLlm\McpSdk\Server\NotificationHandlerInterface; use PhpLlm\McpSdk\Server\RequestHandler\InitializeHandler; use PhpLlm\McpSdk\Server\RequestHandler\PingHandler; use PhpLlm\McpSdk\Server\RequestHandler\PromptGetHandler; @@ -16,11 +15,12 @@ use PhpLlm\McpSdk\Server\RequestHandler\ResourceReadHandler; use PhpLlm\McpSdk\Server\RequestHandler\ToolCallHandler; use PhpLlm\McpSdk\Server\RequestHandler\ToolListHandler; +use PhpLlm\McpSdk\Server\RequestHandlerInterface; class Builder { /** - * @return list + * @return list */ public static function buildRequestHandlers(): array { @@ -49,7 +49,7 @@ public static function buildRequestHandlers(): array } /** - * @return list + * @return list */ public static function buildNotificationHandlers(): array { diff --git a/src/Server.php b/src/Server.php index 06312b8..d6eb39f 100644 --- a/src/Server.php +++ b/src/Server.php @@ -5,7 +5,7 @@ namespace PhpLlm\McpSdk; use PhpLlm\McpSdk\Server\JsonRpcHandler; -use PhpLlm\McpSdk\Server\Transport; +use PhpLlm\McpSdk\Server\TransportInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; @@ -17,7 +17,7 @@ public function __construct( ) { } - public function connect(Transport $transport): void + public function connect(TransportInterface $transport): void { $transport->initialize(); $this->logger->info('Transport initialized'); diff --git a/src/Server/JsonRpcHandler.php b/src/Server/JsonRpcHandler.php index 06c1df6..8256887 100644 --- a/src/Server/JsonRpcHandler.php +++ b/src/Server/JsonRpcHandler.php @@ -17,18 +17,18 @@ readonly class JsonRpcHandler { /** - * @var array + * @var array */ private array $requestHandlers; /** - * @var array + * @var array */ private array $notificationHandlers; /** - * @param iterable $requestHandlers - * @param iterable $notificationHandlers + * @param iterable $requestHandlers + * @param iterable $notificationHandlers */ public function __construct( private Factory $messageFactory, diff --git a/src/Server/NotificationHandler/BaseNotificationHandler.php b/src/Server/NotificationHandler/BaseNotificationHandler.php index 3536afe..96d09cc 100644 --- a/src/Server/NotificationHandler/BaseNotificationHandler.php +++ b/src/Server/NotificationHandler/BaseNotificationHandler.php @@ -5,9 +5,9 @@ namespace PhpLlm\McpSdk\Server\NotificationHandler; use PhpLlm\McpSdk\Message\Notification; -use PhpLlm\McpSdk\Server\NotificationHandler; +use PhpLlm\McpSdk\Server\NotificationHandlerInterface; -abstract class BaseNotificationHandler implements NotificationHandler +abstract class BaseNotificationHandler implements NotificationHandlerInterface { public function supports(Notification $message): bool { diff --git a/src/Server/NotificationHandler.php b/src/Server/NotificationHandlerInterface.php similarity index 85% rename from src/Server/NotificationHandler.php rename to src/Server/NotificationHandlerInterface.php index 6df44c9..d2d71d3 100644 --- a/src/Server/NotificationHandler.php +++ b/src/Server/NotificationHandlerInterface.php @@ -6,7 +6,7 @@ use PhpLlm\McpSdk\Message\Notification; -interface NotificationHandler +interface NotificationHandlerInterface { public function supports(Notification $message): bool; diff --git a/src/Server/RequestHandler/BaseRequestHandler.php b/src/Server/RequestHandler/BaseRequestHandler.php index 9d44530..d7aad40 100644 --- a/src/Server/RequestHandler/BaseRequestHandler.php +++ b/src/Server/RequestHandler/BaseRequestHandler.php @@ -5,9 +5,9 @@ namespace PhpLlm\McpSdk\Server\RequestHandler; use PhpLlm\McpSdk\Message\Request; -use PhpLlm\McpSdk\Server\RequestHandler; +use PhpLlm\McpSdk\Server\RequestHandlerInterface; -abstract class BaseRequestHandler implements RequestHandler +abstract class BaseRequestHandler implements RequestHandlerInterface { public function supports(Request $message): bool { diff --git a/src/Server/RequestHandler.php b/src/Server/RequestHandlerInterface.php similarity index 89% rename from src/Server/RequestHandler.php rename to src/Server/RequestHandlerInterface.php index 4979fd9..80fe783 100644 --- a/src/Server/RequestHandler.php +++ b/src/Server/RequestHandlerInterface.php @@ -8,7 +8,7 @@ use PhpLlm\McpSdk\Message\Request; use PhpLlm\McpSdk\Message\Response; -interface RequestHandler +interface RequestHandlerInterface { public function supports(Request $message): bool; diff --git a/src/Server/Transport/Sse/Store/CachePoolStore.php b/src/Server/Transport/Sse/Store/CachePoolStore.php index 7bea9bb..d768305 100644 --- a/src/Server/Transport/Sse/Store/CachePoolStore.php +++ b/src/Server/Transport/Sse/Store/CachePoolStore.php @@ -4,11 +4,11 @@ namespace PhpLlm\McpSdk\Server\Transport\Sse\Store; -use PhpLlm\McpSdk\Server\Transport\Sse\Store; +use PhpLlm\McpSdk\Server\Transport\Sse\StoreInterface; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Uid\Uuid; -final readonly class CachePoolStore implements Store +final readonly class CachePoolStore implements StoreInterface { public function __construct( private CacheItemPoolInterface $cachePool, diff --git a/src/Server/Transport/Sse/Store.php b/src/Server/Transport/Sse/StoreInterface.php similarity index 91% rename from src/Server/Transport/Sse/Store.php rename to src/Server/Transport/Sse/StoreInterface.php index 2936a15..f6517e0 100644 --- a/src/Server/Transport/Sse/Store.php +++ b/src/Server/Transport/Sse/StoreInterface.php @@ -6,7 +6,7 @@ use Symfony\Component\Uid\Uuid; -interface Store +interface StoreInterface { public function push(Uuid $id, string $message): void; diff --git a/src/Server/Transport/Sse/StreamTransport.php b/src/Server/Transport/Sse/StreamTransport.php index d264c19..7b6d799 100644 --- a/src/Server/Transport/Sse/StreamTransport.php +++ b/src/Server/Transport/Sse/StreamTransport.php @@ -4,14 +4,14 @@ namespace PhpLlm\McpSdk\Server\Transport\Sse; -use PhpLlm\McpSdk\Server\Transport; +use PhpLlm\McpSdk\Server\TransportInterface; use Symfony\Component\Uid\Uuid; -final readonly class StreamTransport implements Transport +final readonly class StreamTransport implements TransportInterface { public function __construct( private string $messageEndpoint, - private Store $store, + private StoreInterface $store, private Uuid $id, ) { } diff --git a/src/Server/Transport/Stdio/SymfonyConsoleTransport.php b/src/Server/Transport/Stdio/SymfonyConsoleTransport.php index 2c61cad..778b2a8 100644 --- a/src/Server/Transport/Stdio/SymfonyConsoleTransport.php +++ b/src/Server/Transport/Stdio/SymfonyConsoleTransport.php @@ -4,7 +4,7 @@ namespace PhpLlm\McpSdk\Server\Transport\Stdio; -use PhpLlm\McpSdk\Server\Transport; +use PhpLlm\McpSdk\Server\TransportInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\StreamableInputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -12,7 +12,7 @@ /** * Heavily inspired by https://jolicode.com/blog/mcp-the-open-protocol-that-turns-llm-chatbots-into-intelligent-agents. */ -final class SymfonyConsoleTransport implements Transport +final class SymfonyConsoleTransport implements TransportInterface { private string $buffer = ''; diff --git a/src/Server/Transport.php b/src/Server/TransportInterface.php similarity index 90% rename from src/Server/Transport.php rename to src/Server/TransportInterface.php index 698861c..6dd8b86 100644 --- a/src/Server/Transport.php +++ b/src/Server/TransportInterface.php @@ -4,7 +4,7 @@ namespace PhpLlm\McpSdk\Server; -interface Transport +interface TransportInterface { public function initialize(): void; diff --git a/tests/Fixtures/InMemoryTransport.php b/tests/Fixtures/InMemoryTransport.php index 72df57f..82fbb53 100644 --- a/tests/Fixtures/InMemoryTransport.php +++ b/tests/Fixtures/InMemoryTransport.php @@ -2,9 +2,9 @@ namespace PhpLlm\McpSdk\Tests\Fixtures; -use PhpLlm\McpSdk\Server\Transport; +use PhpLlm\McpSdk\Server\TransportInterface; -class InMemoryTransport implements Transport +class InMemoryTransport implements TransportInterface { private bool $connected = true;