From 382f2f65f269bb2f9835af38e724402367f5b2b1 Mon Sep 17 00:00:00 2001 From: Sean Tymon Date: Fri, 15 Aug 2025 22:56:40 +0100 Subject: [PATCH 1/2] feat: init result instructions --- src/Client.php | 8 ++++++++ tests/Feature/ClientAsyncApiTest.php | 2 ++ tests/Feature/ClientSyncApiTest.php | 4 +++- tests/Pest.php | 4 +++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index d0b4ebc..0ac99dc 100644 --- a/src/Client.php +++ b/src/Client.php @@ -83,6 +83,8 @@ class Client protected string $preferredProtocolVersion = '2024-11-05'; + protected string $instructions = null; + /** * @internal Use ClientBuilder::make()->...->build() instead. */ @@ -128,6 +130,11 @@ public function getNegotiatedCapabilities(): ?Capabilities return $this->serverCapabilities; } + public function getInstructions(): ?string + { + return $this->instructions; + } + public function getNegotiatedProtocolVersion(): ?string { return $this->negotiatedProtocolVersion; @@ -920,6 +927,7 @@ function (Response $response) { $this->serverName = $initResult->serverName; $this->serverVersion = $initResult->serverVersion; $this->serverCapabilities = $initResult->capabilities; + $this->instructions = $initResult->instructions; $this->logger->debug("Sending 'initialized' notification to '{$this->getServerName()}'."); diff --git a/tests/Feature/ClientAsyncApiTest.php b/tests/Feature/ClientAsyncApiTest.php index 0a5b8fe..ed8e8aa 100644 --- a/tests/Feature/ClientAsyncApiTest.php +++ b/tests/Feature/ClientAsyncApiTest.php @@ -145,6 +145,7 @@ function ($reason) use (&$rejectedReason) { 'protocolVersion' => '2024-11-05', 'serverInfo' => ['name' => 'AsyncMockServer', 'version' => '2.0'], 'capabilities' => ['tools' => new \stdClass], + 'instructions' => 'You are a helpful assistant', ]; $initResponse = new Response(id: $initRequestId, result: $initResultData); @@ -160,6 +161,7 @@ function ($reason) use (&$rejectedReason) { expect($this->client->getStatus())->toBe(ConnectionStatus::Ready); expect($this->client->getServerName())->toBe('AsyncMockServer'); expect($this->client->getServerVersion())->toBe('2.0'); + expect($this->client->getInstructions())->toBe('You are a helpful assistant'); })->group('usesLoop'); diff --git a/tests/Feature/ClientSyncApiTest.php b/tests/Feature/ClientSyncApiTest.php index 9ed4f41..b22421a 100644 --- a/tests/Feature/ClientSyncApiTest.php +++ b/tests/Feature/ClientSyncApiTest.php @@ -70,7 +70,8 @@ $initRequestId, $this->messageListenerCallback, $this->mockTransport, - $this->loop + $this->loop, + 'You are a helpful assistant', ); // Act @@ -80,6 +81,7 @@ expect($returnedClient)->toBe($this->client); expect($this->client->getStatus())->toBe(ConnectionStatus::Ready); expect($this->client->getServerName())->toBe('MockServer'); + expect($this->client->getInstructions())->toBe('You are a helpful assistant'); })->group('usesLoop'); diff --git a/tests/Pest.php b/tests/Pest.php index d783010..9fc9d0d 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -71,7 +71,8 @@ function simulateSuccessfulHandshake( &$messageListenerCallback, MockInterface&TransportInterface $mockTransport, LoopInterface $loop, - ?array $serverCaps = null + ?array $serverCaps = null, + ?string $instructions = null, ): void { $connectDeferred = new Deferred; $mockTransport->shouldReceive('connect')->once()->andReturn($connectDeferred->promise()); @@ -91,6 +92,7 @@ function simulateSuccessfulHandshake( 'protocolVersion' => '2024-11-05', 'serverInfo' => ['name' => 'MockServer', 'version' => '1.0'], 'capabilities' => $serverCaps ?? ['tools' => new stdClass], + 'instructions' => $instructions, ]; $initResponse = new Response($initRequestId, $initResultData); $loop->addTimer(0.003, fn () => $initResponseDeferred->resolve(null)); From 60d62c5f85a1e7cd4f7ceda0c2e70212a0e203cd Mon Sep 17 00:00:00 2001 From: Sean Tymon Date: Fri, 15 Aug 2025 23:25:42 +0100 Subject: [PATCH 2/2] more generic --- tests/Feature/ClientAsyncApiTest.php | 4 ++-- tests/Feature/ClientSyncApiTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Feature/ClientAsyncApiTest.php b/tests/Feature/ClientAsyncApiTest.php index ed8e8aa..c30698e 100644 --- a/tests/Feature/ClientAsyncApiTest.php +++ b/tests/Feature/ClientAsyncApiTest.php @@ -145,7 +145,7 @@ function ($reason) use (&$rejectedReason) { 'protocolVersion' => '2024-11-05', 'serverInfo' => ['name' => 'AsyncMockServer', 'version' => '2.0'], 'capabilities' => ['tools' => new \stdClass], - 'instructions' => 'You are a helpful assistant', + 'instructions' => 'test instructions', ]; $initResponse = new Response(id: $initRequestId, result: $initResultData); @@ -161,7 +161,7 @@ function ($reason) use (&$rejectedReason) { expect($this->client->getStatus())->toBe(ConnectionStatus::Ready); expect($this->client->getServerName())->toBe('AsyncMockServer'); expect($this->client->getServerVersion())->toBe('2.0'); - expect($this->client->getInstructions())->toBe('You are a helpful assistant'); + expect($this->client->getInstructions())->toBe('test instructions'); })->group('usesLoop'); diff --git a/tests/Feature/ClientSyncApiTest.php b/tests/Feature/ClientSyncApiTest.php index b22421a..8950ae4 100644 --- a/tests/Feature/ClientSyncApiTest.php +++ b/tests/Feature/ClientSyncApiTest.php @@ -71,7 +71,7 @@ $this->messageListenerCallback, $this->mockTransport, $this->loop, - 'You are a helpful assistant', + 'test instructions', ); // Act @@ -81,7 +81,7 @@ expect($returnedClient)->toBe($this->client); expect($this->client->getStatus())->toBe(ConnectionStatus::Ready); expect($this->client->getServerName())->toBe('MockServer'); - expect($this->client->getInstructions())->toBe('You are a helpful assistant'); + expect($this->client->getInstructions())->toBe('test instructions'); })->group('usesLoop');