Skip to content

Commit 55b7157

Browse files
klapaudiusgithub-actions[bot]
authored andcommitted
Fix styling
1 parent 59306eb commit 55b7157

File tree

8 files changed

+16
-27
lines changed

8 files changed

+16
-27
lines changed

src/Data/Requests/NotificationData.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
*/
1111
class NotificationData
1212
{
13-
1413
/**
1514
* The client ID of the client that sent the notification.
16-
*
1715
*/
1816
public string $clientId;
1917

@@ -59,6 +57,7 @@ public static function fromArray(array $data): self
5957
if (isset($data['clientId']) && empty($data['params'])) {
6058
$data['params'] = ['clientId' => $data['clientId']];
6159
}
60+
6261
return new self(
6362
method: $data['method'] ?? null,
6463
jsonRpc: $data['jsonrpc'],

src/Protocol/MCPProtocol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(private readonly TransportInterface $transport)
4646
$this->transport->onMessage([$this, 'handleMessage']);
4747
if ($this->transport instanceof SseTransportInterface) {
4848
$this->registerNotificationHandler(new PongHandler($this->transport->getAdapter()));
49-
$this->registerRequestHandler(new PingHandler( $this->transport ));
49+
$this->registerRequestHandler(new PingHandler($this->transport));
5050
}
5151
}
5252

src/Server/Notification/PongHandler.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use KLP\KlpMcpServer\Protocol\Handlers\NotificationHandler;
77
use KLP\KlpMcpServer\Transports\SseAdapters\SseAdapterInterface;
88

9-
109
/**
1110
* Handles the processing of "Pong" notifications for managing client-server interactions.
1211
* This class specifically implements the NotificationHandler interface.
@@ -15,9 +14,7 @@
1514
*/
1615
readonly class PongHandler implements NotificationHandler
1716
{
18-
public function __construct(private ?SseAdapterInterface $adapter = null)
19-
{
20-
}
17+
public function __construct(private ?SseAdapterInterface $adapter = null) {}
2118

2219
public function isHandle(?string $method): bool
2320
{
@@ -27,7 +24,7 @@ public function isHandle(?string $method): bool
2724
/**
2825
* Executes a specified method with optional parameters.
2926
*
30-
* @param array|null $params Optional parameters to pass to the method. Null if not provided.
27+
* @param array|null $params Optional parameters to pass to the method. Null if not provided.
3128
* @return array The result of the execution, returned as an array.
3229
*/
3330
public function execute(?array $params = null): array

src/Server/Request/PingHandler.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,22 @@
22

33
namespace KLP\KlpMcpServer\Server\Request;
44

5-
use KLP\KlpMcpServer\Data\Requests\InitializeData;
6-
use KLP\KlpMcpServer\Exceptions\JsonRpcErrorException;
75
use KLP\KlpMcpServer\Protocol\Handlers\RequestHandler;
8-
use KLP\KlpMcpServer\Server\MCPServer;
96
use KLP\KlpMcpServer\Transports\SseTransportInterface;
107

118
class PingHandler implements RequestHandler
129
{
13-
14-
public function __construct(private readonly SseTransportInterface $transport)
15-
{
16-
}
10+
public function __construct(private readonly SseTransportInterface $transport) {}
1711

1812
public function isHandle(string $method): bool
1913
{
2014
return $method === 'ping';
2115
}
2216

23-
2417
public function execute(string $method, string|int $messageId, ?array $params = null): array
2518
{
26-
$this->transport->send(["id" => $messageId, "jsonrpc" => "2.0", "result" => []]);
19+
$this->transport->send(['id' => $messageId, 'jsonrpc' => '2.0', 'result' => []]);
20+
2721
return [];
2822
}
2923
}

src/Server/Request/ToolsCallHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function isHandle(string $method): bool
2727
* Executes a specified method with provided parameters and returns the result.
2828
*
2929
* @param string $method The method to be executed.
30-
* @param string|int $messageId The ID of the request message. Used for response identification.
30+
* @param string|int $messageId The ID of the request message. Used for response identification.
3131
* @param array|null $params An associative array of parameters required for execution. Must include 'name' as the tool identifier and optionally 'arguments'.
3232
* @return array The response array containing the execution result, which may vary based on the method.
3333
*

src/Transports/SseAdapters/RedisAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function getMessageCount(string $clientId): int
206206
public function storeLastPongResponseTimestamp(string $clientId, ?int $timestamp = null): void
207207
{
208208
try {
209-
$key = $this->getQueueKey($clientId).":last_pong";
209+
$key = $this->getQueueKey($clientId).':last_pong';
210210
$timestamp = $timestamp ?? time();
211211

212212
$this->redis->set($key, $timestamp);
@@ -229,7 +229,7 @@ public function storeLastPongResponseTimestamp(string $clientId, ?int $timestamp
229229
public function getLastPongResponseTimestamp(string $clientId): ?int
230230
{
231231
try {
232-
$key = $this->getQueueKey($clientId).":last_pong";
232+
$key = $this->getQueueKey($clientId).':last_pong';
233233

234234
$timestamp = $this->redis->get($key);
235235

src/Transports/SseAdapters/SseAdapterInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function hasMessages(string $clientId): bool;
6767
* @return int The number of messages
6868
*/
6969
public function getMessageCount(string $clientId): int;
70-
70+
7171
/**
7272
* Store the last pong response timestamp for a specific client
7373
*
@@ -77,7 +77,7 @@ public function getMessageCount(string $clientId): int;
7777
* @throws \Exception If the timestamp cannot be stored
7878
*/
7979
public function storeLastPongResponseTimestamp(string $clientId, ?int $timestamp = null): void;
80-
80+
8181
/**
8282
* Get the last pong response timestamp for a specific client
8383
*

src/Transports/SseTransport.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,15 @@ public function onMessage(callable $handler): void
219219
*/
220220
public function isConnected(): bool
221221
{
222-
if ( time() - $this->lastPingTimestamp > $this->pingInterval / 1000 ) {
222+
if (time() - $this->lastPingTimestamp > $this->pingInterval / 1000) {
223223
$this->lastPingTimestamp = time();
224224
$this->send(message: ['jsonrpc' => '2.0', 'method' => 'ping']);
225225
}
226226
$pingTest = time() - $this->getLastPongResponseTimestamp() < ($this->pingInterval / 1000) + 5;
227227
if (! $pingTest) {
228228
$this->logger?->info('SSE Transport::isConnected: pingTest failed');
229229
}
230+
230231
return $pingTest && connection_aborted() === 0;
231232
}
232233

@@ -337,7 +338,6 @@ private function getEndpoint(string $sessionId): string
337338
}
338339

339340
/**
340-
* @return int|null
341341
* @throws Exception
342342
*/
343343
protected function getLastPongResponseTimestamp(): ?int
@@ -348,9 +348,8 @@ protected function getLastPongResponseTimestamp(): ?int
348348
/**
349349
* Sets the interval for sending ping requests.
350350
*
351-
* @param int $pingInterval The interval in milliseconds at which ping requests should be sent.
352-
* The value must be between 10,000 and 30,000 ms.
353-
* @return void
351+
* @param int $pingInterval The interval in milliseconds at which ping requests should be sent.
352+
* The value must be between 10,000 and 30,000 ms.
354353
*/
355354
protected function setPingInterval(int $pingInterval): void
356355
{

0 commit comments

Comments
 (0)