Skip to content

Commit 1d8b482

Browse files
committed
Switch to set* and add* on ServerBuilder instead of with*
1 parent 99bf56e commit 1d8b482

File tree

11 files changed

+83
-107
lines changed

11 files changed

+83
-107
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ use Mcp\Server;
9898
use Mcp\Server\Transport\StdioTransport;
9999

100100
Server::make()
101-
->withServerInfo('Stdio Calculator', '1.1.0', 'Basic Calculator over STDIO transport.')
102-
->withDiscovery(__DIR__, ['.'])
101+
->setServerInfo('Stdio Calculator', '1.1.0', 'Basic Calculator over STDIO transport.')
102+
->setDiscovery(__DIR__, ['.'])
103103
->build()
104104
->connect(new StdioTransport());
105105
```

examples/01-discovery-stdio-calculator/server.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
logger()->info('Starting MCP Stdio Calculator Server...');
2020

2121
Server::make()
22-
->withServerInfo('Stdio Calculator', '1.1.0', 'Basic Calculator over STDIO transport.')
23-
->withContainer(container())
24-
->withLogger(logger())
25-
->withDiscovery(__DIR__, ['.'])
22+
->setServerInfo('Stdio Calculator', '1.1.0', 'Basic Calculator over STDIO transport.')
23+
->setContainer(container())
24+
->setLogger(logger())
25+
->setDiscovery(__DIR__, ['.'])
2626
->build()
2727
->connect(new StdioTransport(logger: logger()));
2828

examples/02-discovery-http-userprofile/server.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
$container->set(LoggerInterface::class, logger());
2525

2626
Server::make()
27-
->withServerInfo('HTTP User Profiles', '1.0.0')
28-
->withLogger(logger())
29-
->withContainer($container)
30-
->withDiscovery(__DIR__, ['.'])
31-
->withTool(
27+
->setServerInfo('HTTP User Profiles', '1.0.0')
28+
->setLogger(logger())
29+
->setContainer($container)
30+
->setDiscovery(__DIR__, ['.'])
31+
->addTool(
3232
function (float $a, float $b, string $operation = 'add'): array {
3333
$result = match ($operation) {
3434
'add' => $a + $b,
@@ -47,7 +47,7 @@ function (float $a, float $b, string $operation = 'add'): array {
4747
name: 'calculator',
4848
description: 'Perform basic math operations (add, subtract, multiply, divide)'
4949
)
50-
->withResource(
50+
->addResource(
5151
function (): array {
5252
$memoryUsage = memory_get_usage(true);
5353
$memoryPeak = memory_get_peak_usage(true);

examples/03-manual-registration-stdio/server.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
logger()->info('Starting MCP Manual Registration (Stdio) Server...');
2121

2222
Server::make()
23-
->withServerInfo('Manual Reg Server', '1.0.0')
24-
->withLogger(logger())
25-
->withContainer(container())
26-
->withTool([SimpleHandlers::class, 'echoText'], 'echo_text')
27-
->withResource([SimpleHandlers::class, 'getAppVersion'], 'app://version', 'application_version', mimeType: 'text/plain')
28-
->withPrompt([SimpleHandlers::class, 'greetingPrompt'], 'personalized_greeting')
29-
->withResourceTemplate([SimpleHandlers::class, 'getItemDetails'], 'item://{itemId}/details', 'get_item_details', mimeType: 'application/json')
23+
->setServerInfo('Manual Reg Server', '1.0.0')
24+
->setLogger(logger())
25+
->setContainer(container())
26+
->addTool([SimpleHandlers::class, 'echoText'], 'echo_text')
27+
->addResource([SimpleHandlers::class, 'getAppVersion'], 'app://version', 'application_version', mimeType: 'text/plain')
28+
->addPrompt([SimpleHandlers::class, 'greetingPrompt'], 'personalized_greeting')
29+
->addResourceTemplate([SimpleHandlers::class, 'getItemDetails'], 'item://{itemId}/details', 'get_item_details', mimeType: 'application/json')
3030
->build()
3131
->connect(new StdioTransport(logger: logger()));
3232

examples/04-combined-registration-http/server.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
logger()->info('Starting MCP Combined Registration (HTTP) Server...');
2121

2222
Server::make()
23-
->withServerInfo('Combined HTTP Server', '1.0.0')
24-
->withLogger(logger())
25-
->withContainer(container())
26-
->withDiscovery(__DIR__, ['.'])
27-
->withTool([ManualHandlers::class, 'manualGreeter'])
28-
->withResource(
23+
->setServerInfo('Combined HTTP Server', '1.0.0')
24+
->setLogger(logger())
25+
->setContainer(container())
26+
->setDiscovery(__DIR__, ['.'])
27+
->addTool([ManualHandlers::class, 'manualGreeter'])
28+
->addResource(
2929
[ManualHandlers::class, 'getPriorityConfigManual'],
3030
'config://priority',
3131
'priority_config_manual',

examples/05-stdio-env-variables/server.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
logger()->info('Starting MCP Stdio Environment Variable Example Server...');
5151

5252
Server::make()
53-
->withServerInfo('Env Var Server', '1.0.0')
54-
->withLogger(logger())
55-
->withDiscovery(__DIR__, ['.'])
53+
->setServerInfo('Env Var Server', '1.0.0')
54+
->setLogger(logger())
55+
->setDiscovery(__DIR__, ['.'])
5656
->build()
5757
->connect(new StdioTransport(logger: logger()));
5858

examples/06-custom-dependencies-stdio/server.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
$container->set(Services\StatsServiceInterface::class, $statsService);
2929

3030
Server::make()
31-
->withServerInfo('Task Manager Server', '1.0.0')
32-
->withLogger(logger())
33-
->withContainer($container)
34-
->withDiscovery(__DIR__, ['.'])
31+
->setServerInfo('Task Manager Server', '1.0.0')
32+
->setLogger(logger())
33+
->setContainer($container)
34+
->setDiscovery(__DIR__, ['.'])
3535
->build()
3636
->connect(new StdioTransport(logger: logger()));
3737

examples/07-complex-tool-schema-http/server.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
logger()->info('Starting MCP Complex Schema HTTP Server...');
2020

2121
Server::make()
22-
->withServerInfo('Event Scheduler Server', '1.0.0')
23-
->withLogger(logger())
24-
->withContainer(container())
25-
->withDiscovery(__DIR__, ['.'])
22+
->setServerInfo('Event Scheduler Server', '1.0.0')
23+
->setLogger(logger())
24+
->setContainer(container())
25+
->setDiscovery(__DIR__, ['.'])
2626
->build()
2727
->connect(new HttpServerTransport('127.0.0.1', 8082, 'mcp_scheduler'));
2828

examples/08-schema-showcase-streamable/server.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
logger()->info('Starting MCP Schema Showcase Server...');
2020

2121
Server::make()
22-
->withServerInfo('Schema Showcase', '1.0.0')
23-
->withLogger(logger())
24-
->withDiscovery(__DIR__, ['.'])
22+
->setServerInfo('Schema Showcase', '1.0.0')
23+
->setLogger(logger())
24+
->setDiscovery(__DIR__, ['.'])
2525
->build()
2626
->connect(new StreamableHttpServerTransport('127.0.0.1', 8080, 'mcp'));
2727

phpstan-baseline.neon

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -463,43 +463,43 @@ parameters:
463463
path: src/Server/ServerBuilder.php
464464

465465
-
466-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withDiscovery\(\) has parameter \$excludeDirs with no value type specified in iterable type array\.$#'
466+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:setDiscovery\(\) has parameter \$excludeDirs with no value type specified in iterable type array\.$#'
467467
identifier: missingType.iterableValue
468468
count: 1
469469
path: src/Server/ServerBuilder.php
470470

471471
-
472-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withDiscovery\(\) has parameter \$scanDirs with no value type specified in iterable type array\.$#'
472+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:setDiscovery\(\) has parameter \$scanDirs with no value type specified in iterable type array\.$#'
473473
identifier: missingType.iterableValue
474474
count: 1
475475
path: src/Server/ServerBuilder.php
476476

477477
-
478-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withPrompt\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
478+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addPrompt\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
479479
identifier: missingType.iterableValue
480480
count: 1
481481
path: src/Server/ServerBuilder.php
482482

483483
-
484-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withResource\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
484+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addResource\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
485485
identifier: missingType.iterableValue
486486
count: 1
487487
path: src/Server/ServerBuilder.php
488488

489489
-
490-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withResourceTemplate\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
490+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addResourceTemplate\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
491491
identifier: missingType.iterableValue
492492
count: 1
493493
path: src/Server/ServerBuilder.php
494494

495495
-
496-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withTool\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
496+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addTool\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
497497
identifier: missingType.iterableValue
498498
count: 1
499499
path: src/Server/ServerBuilder.php
500500

501501
-
502-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withTool\(\) has parameter \$inputSchema with no value type specified in iterable type array\.$#'
502+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addTool\(\) has parameter \$inputSchema with no value type specified in iterable type array\.$#'
503503
identifier: missingType.iterableValue
504504
count: 1
505505
path: src/Server/ServerBuilder.php
@@ -535,49 +535,25 @@ parameters:
535535
path: src/Server/ServerBuilder.php
536536

537537
-
538-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualPrompts has unknown class Mcp\\Server\\Closure as its type\.$#'
539-
identifier: class.notFound
540-
count: 1
541-
path: src/Server/ServerBuilder.php
542-
543-
-
544-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualPrompts type has no value type specified in iterable type array\.$#'
538+
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$prompts type has no value type specified in iterable type array\.$#'
545539
identifier: missingType.iterableValue
546540
count: 1
547541
path: src/Server/ServerBuilder.php
548542

549543
-
550-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualResourceTemplates has unknown class Mcp\\Server\\Closure as its type\.$#'
551-
identifier: class.notFound
552-
count: 1
553-
path: src/Server/ServerBuilder.php
554-
555-
-
556-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualResourceTemplates type has no value type specified in iterable type array\.$#'
544+
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$resourceTemplates type has no value type specified in iterable type array\.$#'
557545
identifier: missingType.iterableValue
558546
count: 1
559547
path: src/Server/ServerBuilder.php
560548

561549
-
562-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualResources has unknown class Mcp\\Server\\Closure as its type\.$#'
563-
identifier: class.notFound
564-
count: 1
565-
path: src/Server/ServerBuilder.php
566-
567-
-
568-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualResources type has no value type specified in iterable type array\.$#'
550+
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$resources type has no value type specified in iterable type array\.$#'
569551
identifier: missingType.iterableValue
570552
count: 1
571553
path: src/Server/ServerBuilder.php
572554

573555
-
574-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualTools has unknown class Mcp\\Server\\Closure as its type\.$#'
575-
identifier: class.notFound
576-
count: 1
577-
path: src/Server/ServerBuilder.php
578-
579-
-
580-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualTools type has no value type specified in iterable type array\.$#'
556+
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$tools type has no value type specified in iterable type array\.$#'
581557
identifier: missingType.iterableValue
582558
count: 1
583559
path: src/Server/ServerBuilder.php

0 commit comments

Comments
 (0)