Skip to content

Commit 724f2f9

Browse files
committed
Switch to set* and add* on ServerBuilder instead of with*
1 parent bfc3b82 commit 724f2f9

File tree

11 files changed

+79
-103
lines changed

11 files changed

+79
-103
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ 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.')
101+
->setServerInfo('Stdio Calculator', '1.1.0', 'Basic Calculator over STDIO transport.')
102102
->withDiscovery(__DIR__, ['.'])
103103
->build()
104104
->connect(new StdioTransport());

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
@@ -565,43 +565,43 @@ parameters:
565565
path: src/Server/ServerBuilder.php
566566

567567
-
568-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withDiscovery\(\) has parameter \$excludeDirs with no value type specified in iterable type array\.$#'
568+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:setDiscovery\(\) has parameter \$excludeDirs with no value type specified in iterable type array\.$#'
569569
identifier: missingType.iterableValue
570570
count: 1
571571
path: src/Server/ServerBuilder.php
572572

573573
-
574-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withDiscovery\(\) has parameter \$scanDirs with no value type specified in iterable type array\.$#'
574+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:setDiscovery\(\) has parameter \$scanDirs with no value type specified in iterable type array\.$#'
575575
identifier: missingType.iterableValue
576576
count: 1
577577
path: src/Server/ServerBuilder.php
578578

579579
-
580-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withPrompt\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
580+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addPrompt\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
581581
identifier: missingType.iterableValue
582582
count: 1
583583
path: src/Server/ServerBuilder.php
584584

585585
-
586-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withResource\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
586+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addResource\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
587587
identifier: missingType.iterableValue
588588
count: 1
589589
path: src/Server/ServerBuilder.php
590590

591591
-
592-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withResourceTemplate\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
592+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addResourceTemplate\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
593593
identifier: missingType.iterableValue
594594
count: 1
595595
path: src/Server/ServerBuilder.php
596596

597597
-
598-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withTool\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
598+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addTool\(\) has parameter \$handler with no value type specified in iterable type array\.$#'
599599
identifier: missingType.iterableValue
600600
count: 1
601601
path: src/Server/ServerBuilder.php
602602

603603
-
604-
message: '#^Method Mcp\\Server\\ServerBuilder\:\:withTool\(\) has parameter \$inputSchema with no value type specified in iterable type array\.$#'
604+
message: '#^Method Mcp\\Server\\ServerBuilder\:\:addTool\(\) has parameter \$inputSchema with no value type specified in iterable type array\.$#'
605605
identifier: missingType.iterableValue
606606
count: 1
607607
path: src/Server/ServerBuilder.php
@@ -637,49 +637,25 @@ parameters:
637637
path: src/Server/ServerBuilder.php
638638

639639
-
640-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualPrompts has unknown class Mcp\\Server\\Closure as its type\.$#'
641-
identifier: class.notFound
642-
count: 1
643-
path: src/Server/ServerBuilder.php
644-
645-
-
646-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualPrompts type has no value type specified in iterable type array\.$#'
640+
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$prompts type has no value type specified in iterable type array\.$#'
647641
identifier: missingType.iterableValue
648642
count: 1
649643
path: src/Server/ServerBuilder.php
650644

651645
-
652-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualResourceTemplates has unknown class Mcp\\Server\\Closure as its type\.$#'
653-
identifier: class.notFound
654-
count: 1
655-
path: src/Server/ServerBuilder.php
656-
657-
-
658-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualResourceTemplates type has no value type specified in iterable type array\.$#'
646+
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$resourceTemplates type has no value type specified in iterable type array\.$#'
659647
identifier: missingType.iterableValue
660648
count: 1
661649
path: src/Server/ServerBuilder.php
662650

663651
-
664-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualResources has unknown class Mcp\\Server\\Closure as its type\.$#'
665-
identifier: class.notFound
666-
count: 1
667-
path: src/Server/ServerBuilder.php
668-
669-
-
670-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualResources type has no value type specified in iterable type array\.$#'
652+
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$resources type has no value type specified in iterable type array\.$#'
671653
identifier: missingType.iterableValue
672654
count: 1
673655
path: src/Server/ServerBuilder.php
674656

675657
-
676-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualTools has unknown class Mcp\\Server\\Closure as its type\.$#'
677-
identifier: class.notFound
678-
count: 1
679-
path: src/Server/ServerBuilder.php
680-
681-
-
682-
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$manualTools type has no value type specified in iterable type array\.$#'
658+
message: '#^Property Mcp\\Server\\ServerBuilder\:\:\$tools type has no value type specified in iterable type array\.$#'
683659
identifier: missingType.iterableValue
684660
count: 1
685661
path: src/Server/ServerBuilder.php

0 commit comments

Comments
 (0)