|
197 | 197 | $client->clearCache(); |
198 | 198 | }); |
199 | 199 |
|
| 200 | +it('paginates tools list using cursor', function (): void { |
| 201 | + $transport = new FakeClientTransport([ |
| 202 | + json_encode([ |
| 203 | + 'jsonrpc' => '2.0', |
| 204 | + 'id' => 1, |
| 205 | + 'result' => [ |
| 206 | + 'protocolVersion' => '2025-11-25', |
| 207 | + 'capabilities' => [], |
| 208 | + 'serverInfo' => ['name' => 'test', 'version' => '1.0.0'], |
| 209 | + ], |
| 210 | + ]), |
| 211 | + json_encode([ |
| 212 | + 'jsonrpc' => '2.0', |
| 213 | + 'id' => 2, |
| 214 | + 'result' => [ |
| 215 | + 'tools' => [ |
| 216 | + ['name' => 'tool-1', 'description' => 'First tool'], |
| 217 | + ], |
| 218 | + 'nextCursor' => 'cursor-abc', |
| 219 | + ], |
| 220 | + ]), |
| 221 | + json_encode([ |
| 222 | + 'jsonrpc' => '2.0', |
| 223 | + 'id' => 3, |
| 224 | + 'result' => [ |
| 225 | + 'tools' => [ |
| 226 | + ['name' => 'tool-2', 'description' => 'Second tool'], |
| 227 | + ], |
| 228 | + ], |
| 229 | + ]), |
| 230 | + ]); |
| 231 | + |
| 232 | + $client = new Client($transport, 'test-client'); |
| 233 | + $client->connect(); |
| 234 | + |
| 235 | + $tools = $client->tools(); |
| 236 | + |
| 237 | + expect($tools)->toHaveCount(2) |
| 238 | + ->and($tools->first()->name())->toBe('tool-1') |
| 239 | + ->and($tools->last()->name())->toBe('tool-2'); |
| 240 | + |
| 241 | + $sent = $transport->sentMessages(); |
| 242 | + expect($sent)->toHaveCount(3); |
| 243 | + |
| 244 | + $secondRequest = json_decode($sent[1], true); |
| 245 | + expect($secondRequest['method'])->toBe('tools/list') |
| 246 | + ->and($secondRequest)->not->toHaveKey('params'); |
| 247 | + |
| 248 | + $thirdRequest = json_decode($sent[2], true); |
| 249 | + expect($thirdRequest['method'])->toBe('tools/list') |
| 250 | + ->and($thirdRequest['params']['cursor'])->toBe('cursor-abc'); |
| 251 | +}); |
| 252 | + |
| 253 | +it('sends ping request', function (): void { |
| 254 | + $transport = new FakeClientTransport([ |
| 255 | + json_encode([ |
| 256 | + 'jsonrpc' => '2.0', |
| 257 | + 'id' => 1, |
| 258 | + 'result' => [ |
| 259 | + 'protocolVersion' => '2025-11-25', |
| 260 | + 'capabilities' => [], |
| 261 | + 'serverInfo' => ['name' => 'test', 'version' => '1.0.0'], |
| 262 | + ], |
| 263 | + ]), |
| 264 | + json_encode([ |
| 265 | + 'jsonrpc' => '2.0', |
| 266 | + 'id' => 2, |
| 267 | + 'result' => [], |
| 268 | + ]), |
| 269 | + ]); |
| 270 | + |
| 271 | + $client = new Client($transport, 'test-client'); |
| 272 | + $client->connect(); |
| 273 | + |
| 274 | + $client->ping(); |
| 275 | + |
| 276 | + $sent = $transport->sentMessages(); |
| 277 | + expect($sent)->toHaveCount(2); |
| 278 | + |
| 279 | + $pingRequest = json_decode($sent[1], true); |
| 280 | + expect($pingRequest['method'])->toBe('ping'); |
| 281 | +}); |
| 282 | + |
| 283 | +it('sends capabilities during initialization', function (): void { |
| 284 | + $transport = new FakeClientTransport([ |
| 285 | + json_encode([ |
| 286 | + 'jsonrpc' => '2.0', |
| 287 | + 'id' => 1, |
| 288 | + 'result' => [ |
| 289 | + 'protocolVersion' => '2025-11-25', |
| 290 | + 'capabilities' => [], |
| 291 | + 'serverInfo' => ['name' => 'test', 'version' => '1.0.0'], |
| 292 | + ], |
| 293 | + ]), |
| 294 | + ]); |
| 295 | + |
| 296 | + $client = new Client($transport, 'test-client', capabilities: ['sampling' => []]); |
| 297 | + $client->connect(); |
| 298 | + |
| 299 | + $sent = $transport->sentMessages(); |
| 300 | + $initRequest = json_decode($sent[0], true); |
| 301 | + expect($initRequest['params']['capabilities'])->toBe(['sampling' => []]); |
| 302 | +}); |
| 303 | + |
| 304 | +it('sends empty capabilities object when none configured', function (): void { |
| 305 | + $transport = new FakeClientTransport([ |
| 306 | + json_encode([ |
| 307 | + 'jsonrpc' => '2.0', |
| 308 | + 'id' => 1, |
| 309 | + 'result' => [ |
| 310 | + 'protocolVersion' => '2025-11-25', |
| 311 | + 'capabilities' => [], |
| 312 | + 'serverInfo' => ['name' => 'test', 'version' => '1.0.0'], |
| 313 | + ], |
| 314 | + ]), |
| 315 | + ]); |
| 316 | + |
| 317 | + $client = new Client($transport, 'test-client'); |
| 318 | + $client->connect(); |
| 319 | + |
| 320 | + $sent = $transport->sentMessages(); |
| 321 | + $initRequest = json_decode($sent[0], true); |
| 322 | + expect($initRequest['params']['capabilities'])->toBeEmpty(); |
| 323 | +}); |
| 324 | + |
200 | 325 | it('clears cache', function (): void { |
201 | 326 | $transport = new FakeClientTransport([ |
202 | 327 | json_encode([ |
|
0 commit comments