Skip to content

Commit 62b8efc

Browse files
author
klapaudius
committed
Add test for requestMessage invoking transport processMessage
Removed unused import and redundant exception handling in MCPProtocol. Added a test to verify that requestMessage correctly invokes the transport's processMessage method. This improves test coverage and simplifies the error-handling logic.
1 parent dccf3c4 commit 62b8efc

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Protocol/MCPProtocol.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ public function handleMessage(string $clientId, array $message): void
149149
throw new JsonRpcErrorException(message: 'Invalid Request: Message format not recognized', code: JsonRpcErrorCode::INVALID_REQUEST, data: $message);
150150
} catch (JsonRpcErrorException $e) {
151151
$this->pushMessage(clientId: $clientId, message: new JsonRpcErrorResource(exception: $e, id: $messageId));
152-
} catch (Exception $e) {
153-
throw $e;
154152
}
155153
}
156154

tests/Protocol/MCPProtocolTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use KLP\KlpMcpServer\Protocol\Handlers\NotificationHandler;
77
use KLP\KlpMcpServer\Protocol\MCPProtocol;
88
use KLP\KlpMcpServer\Transports\SseTransportInterface;
9-
use KLP\KlpMcpServer\Transports\TransportInterface;
109
use PHPUnit\Framework\Attributes\Small;
1110
use PHPUnit\Framework\MockObject\MockObject;
1211
use PHPUnit\Framework\TestCase;
@@ -386,4 +385,20 @@ public function test_handle_message_handles_notification_handler_throw_exception
386385

387386
$this->mcpProtocol->handleMessage($clientId, $validNotificationMessage);
388387
}
388+
389+
/**
390+
* Test that requestMessage invokes processMessage on the transport
391+
*/
392+
public function test_request_message_invokes_transport_process_message(): void
393+
{
394+
$clientId = 'test_client';
395+
$message = ['key' => 'value'];
396+
397+
$this->mockTransport
398+
->expects($this->once())
399+
->method('processMessage')
400+
->with($this->equalTo($clientId), $this->equalTo($message));
401+
402+
$this->mcpProtocol->requestMessage($clientId, $message);
403+
}
389404
}

0 commit comments

Comments
 (0)