Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

refactor: introduce Interface suffic #27

Merged
merged 1 commit into from
May 26, 2025
Merged
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
8 changes: 4 additions & 4 deletions examples/cli/src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<RequestHandler>
* @return list<RequestHandlerInterface>
*/
public static function buildRequestHandlers(): array
{
Expand Down Expand Up @@ -49,7 +49,7 @@ public static function buildRequestHandlers(): array
}

/**
* @return list<NotificationHandler>
* @return list<NotificationHandlerInterface>
*/
public static function buildNotificationHandlers(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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');
Expand Down
8 changes: 4 additions & 4 deletions src/Server/JsonRpcHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
readonly class JsonRpcHandler
{
/**
* @var array<int, RequestHandler>
* @var array<int, RequestHandlerInterface>
*/
private array $requestHandlers;

/**
* @var array<int, NotificationHandler>
* @var array<int, NotificationHandlerInterface>
*/
private array $notificationHandlers;

/**
* @param iterable<RequestHandler> $requestHandlers
* @param iterable<NotificationHandler> $notificationHandlers
* @param iterable<RequestHandlerInterface> $requestHandlers
* @param iterable<NotificationHandlerInterface> $notificationHandlers
*/
public function __construct(
private Factory $messageFactory,
Expand Down
4 changes: 2 additions & 2 deletions src/Server/NotificationHandler/BaseNotificationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use PhpLlm\McpSdk\Message\Notification;

interface NotificationHandler
interface NotificationHandlerInterface
{
public function supports(Notification $message): bool;

Expand Down
4 changes: 2 additions & 2 deletions src/Server/RequestHandler/BaseRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PhpLlm\McpSdk\Message\Request;
use PhpLlm\McpSdk\Message\Response;

interface RequestHandler
interface RequestHandlerInterface
{
public function supports(Request $message): bool;

Expand Down
4 changes: 2 additions & 2 deletions src/Server/Transport/Sse/Store/CachePoolStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Symfony\Component\Uid\Uuid;

interface Store
interface StoreInterface
{
public function push(Uuid $id, string $message): void;

Expand Down
6 changes: 3 additions & 3 deletions src/Server/Transport/Sse/StreamTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Transport/Stdio/SymfonyConsoleTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

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;

/**
* 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 = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PhpLlm\McpSdk\Server;

interface Transport
interface TransportInterface
{
public function initialize(): void;

Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/InMemoryTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down