Skip to content

Commit 72f85f5

Browse files
refactor(Protocol): streamline capability checks for server features
[skip ci]
1 parent c459d92 commit 72f85f5

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/Protocol.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,44 +299,44 @@ private function assertRequestCapability(string $method): void
299299

300300
case 'tools/list':
301301
case 'tools/call':
302-
if ($capabilities->tools === null) {
302+
if (!$capabilities->tools) {
303303
throw McpServerException::methodNotFound($method, 'Tools are not enabled on this server.');
304304
}
305305
break;
306306

307307
case 'resources/list':
308308
case 'resources/templates/list':
309309
case 'resources/read':
310-
if ($capabilities->resources === null) {
310+
if (!$capabilities->resources) {
311311
throw McpServerException::methodNotFound($method, 'Resources are not enabled on this server.');
312312
}
313313
break;
314314

315315
case 'resources/subscribe':
316316
case 'resources/unsubscribe':
317-
if ($capabilities->resources === null) {
317+
if (!$capabilities->resources) {
318318
throw McpServerException::methodNotFound($method, 'Resources are not enabled on this server.');
319319
}
320-
if (!$capabilities->resources['subscribe']) {
320+
if (!$capabilities->resourcesSubscribe) {
321321
throw McpServerException::methodNotFound($method, 'Resources subscription is not enabled on this server.');
322322
}
323323
break;
324324

325325
case 'prompts/list':
326326
case 'prompts/get':
327-
if ($capabilities->prompts === null) {
327+
if (!$capabilities->prompts) {
328328
throw McpServerException::methodNotFound($method, 'Prompts are not enabled on this server.');
329329
}
330330
break;
331331

332332
case 'logging/setLevel':
333-
if ($capabilities->logging === null) {
333+
if (!$capabilities->logging) {
334334
throw McpServerException::methodNotFound($method, 'Logging is not enabled on this server.');
335335
}
336336
break;
337337

338338
case 'completion/complete':
339-
if ($capabilities->completions === null) {
339+
if (!$capabilities->completions) {
340340
throw McpServerException::methodNotFound($method, 'Completions are not enabled on this server.');
341341
}
342342
break;
@@ -354,29 +354,29 @@ private function canSendNotification(string $method): bool
354354

355355
switch ($method) {
356356
case 'notifications/message':
357-
if ($capabilities->logging === null) {
357+
if (!$capabilities->logging) {
358358
$this->logger->warning('Logging is not enabled on this server. Notifications/message will not be sent.');
359359
$valid = false;
360360
}
361361
break;
362362

363363
case "notifications/resources/updated":
364364
case "notifications/resources/list_changed":
365-
if ($capabilities->resources === null || !$capabilities->resources['listChanged']) {
365+
if (!$capabilities->resources || !$capabilities->resourcesListChanged) {
366366
$this->logger->warning('Resources list changed notifications are not enabled on this server. Notifications/resources/list_changed will not be sent.');
367367
$valid = false;
368368
}
369369
break;
370370

371371
case "notifications/tools/list_changed":
372-
if ($capabilities->tools === null || !$capabilities->tools['listChanged']) {
372+
if (!$capabilities->tools || !$capabilities->toolsListChanged) {
373373
$this->logger->warning('Tools list changed notifications are not enabled on this server. Notifications/tools/list_changed will not be sent.');
374374
$valid = false;
375375
}
376376
break;
377377

378378
case "notifications/prompts/list_changed":
379-
if ($capabilities->prompts === null || !$capabilities->prompts['listChanged']) {
379+
if (!$capabilities->prompts || !$capabilities->promptsListChanged) {
380380
$this->logger->warning('Prompts list changed notifications are not enabled on this server. Notifications/prompts/list_changed will not be sent.');
381381
$valid = false;
382382
}

tests/Unit/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
it('constructs configuration object with specific capabilities', function () {
9191
$customCaps = ServerCapabilities::make(
9292
resourcesSubscribe: true,
93-
loggingEnabled: true,
93+
logging: true,
9494
);
9595

9696
$config = new Configuration(
@@ -104,5 +104,5 @@
104104

105105
expect($config->capabilities)->toBe($customCaps);
106106
expect($config->capabilities->resourcesSubscribe)->toBeTrue();
107-
expect($config->capabilities->loggingEnabled)->toBeTrue();
107+
expect($config->capabilities->logging)->toBeTrue();
108108
});

tests/Unit/ProtocolTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function expectSuccessResponse(mixed $response, mixed $expectedResult, string|in
271271
$request = createRequest('tools/list');
272272
$configuration = new Configuration(
273273
serverInfo: $this->configuration->serverInfo,
274-
capabilities: ServerCapabilities::make(toolsEnabled: false),
274+
capabilities: ServerCapabilities::make(tools: false),
275275
logger: $this->logger,
276276
loop: $this->configuration->loop,
277277
cache: $this->configuration->cache,
@@ -509,10 +509,10 @@ function expectSuccessResponse(mixed $response, mixed $expectedResult, string|in
509509
it('allows initialize and ping regardless of capabilities', function (string $method) {
510510
$request = createRequest($method);
511511
$capabilities = ServerCapabilities::make(
512-
toolsEnabled: false,
513-
resourcesEnabled: false,
514-
promptsEnabled: false,
515-
loggingEnabled: false,
512+
tools: false,
513+
resources: false,
514+
prompts: false,
515+
logging: false,
516516
);
517517
$configuration = new Configuration(
518518
serverInfo: $this->configuration->serverInfo,

0 commit comments

Comments
 (0)