Skip to content
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
9 changes: 6 additions & 3 deletions src/Server/Transport/BaseTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Mcp\Schema\JsonRpc\Error;
use Mcp\Schema\JsonRpc\Response;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Uid\Uuid;

/**
Expand All @@ -38,9 +39,11 @@ abstract class BaseTransport
*/
protected ?\Fiber $sessionFiber = null;

public function __construct(
protected readonly LoggerInterface $logger,
) {
protected LoggerInterface $logger;

public function __construct(?LoggerInterface $logger = null)
{
$this->logger = $logger ?? new NullLogger();
}

public function initialize(): void
Expand Down
6 changes: 6 additions & 0 deletions src/Server/Transport/InMemoryTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Mcp\Server\Transport;

use Psr\Log\LoggerInterface;
use Symfony\Component\Uid\Uuid;

/**
Expand All @@ -27,7 +28,9 @@ class InMemoryTransport extends BaseTransport implements TransportInterface
*/
public function __construct(
private readonly array $messages = [],
?LoggerInterface $logger = null,
) {
parent::__construct($logger);
}

public function initialize(): void
Expand All @@ -51,10 +54,13 @@ public function send(string $data, array $context): void
*/
public function listen(): mixed
{
$this->logger->info('InMemoryTransport is processing messages...');

foreach ($this->messages as $message) {
$this->handleMessage($message, $this->sessionId);
}

$this->logger->info('InMemoryTransport finished processing.');
$this->handleSessionEnd($this->sessionId);

$this->sessionId = null;
Expand Down
3 changes: 1 addition & 2 deletions src/Server/Transport/StdioTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Mcp\Schema\JsonRpc\Error;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

/**
* @implements TransportInterface<int>
Expand All @@ -29,7 +28,7 @@ class StdioTransport extends BaseTransport implements TransportInterface
public function __construct(
private $input = \STDIN,
private $output = \STDOUT,
LoggerInterface $logger = new NullLogger(),
?LoggerInterface $logger = null,
) {
parent::__construct($logger);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Server/Transport/StreamableHttpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Uid\Uuid;

/**
Expand All @@ -45,7 +44,7 @@ public function __construct(
?ResponseFactoryInterface $responseFactory = null,
?StreamFactoryInterface $streamFactory = null,
array $corsHeaders = [],
LoggerInterface $logger = new NullLogger(),
?LoggerInterface $logger = null,
) {
parent::__construct($logger);
$sessionIdString = $this->request->getHeaderLine('Mcp-Session-Id');
Expand Down