Skip to content

Commit ada83bf

Browse files
committed
Fix missing instructions from builder to handler
1 parent d06b57d commit ada83bf

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

examples/stdio-discovery-calculator/server.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
$server = Server::builder()
2222
->setServerInfo('Stdio Calculator', '1.1.0', 'Basic Calculator over STDIO transport.')
23+
->setInstructions('This server supports basic arithmetic operations: add, subtract, multiply, and divide. Send JSON-RPC requests to perform calculations.')
2324
->setContainer(container())
2425
->setLogger(logger())
2526
->setDiscovery(__DIR__, ['.'])

phpstan-baseline.neon

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,3 @@ parameters:
1717
identifier: return.type
1818
count: 1
1919
path: src/Schema/Result/ReadResourceResult.php
20-
21-
-
22-
message: '#^Property Mcp\\Server\\Builder\:\:\$instructions is never read, only written\.$#'
23-
identifier: property.onlyWritten
24-
count: 1
25-
path: src/Server/Builder.php
26-

src/Server/Builder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,17 @@ public function build(): Server
362362
jsonRpcHandler: JsonRpcHandler::make(
363363
registry: $registry,
364364
referenceProvider: $registry,
365-
implementation: $this->serverInfo,
365+
configuration: new Configuration(
366+
$this->serverInfo,
367+
$registry->getCapabilities(),
368+
$this->paginationLimit, $this->instructions,
369+
),
366370
toolCaller: $toolCaller,
367371
resourceReader: $resourceReader,
368372
promptGetter: $promptGetter,
369373
sessionStore: $sessionStore,
370374
sessionFactory: $sessionFactory,
371375
logger: $logger,
372-
paginationLimit: $this->paginationLimit,
373376
),
374377
logger: $logger,
375378
);

src/Server/Handler/JsonRpcHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
use Mcp\Exception\InvalidInputMessageException;
2323
use Mcp\Exception\NotFoundExceptionInterface;
2424
use Mcp\JsonRpc\MessageFactory;
25-
use Mcp\Schema\Implementation;
2625
use Mcp\Schema\JsonRpc\Error;
2726
use Mcp\Schema\JsonRpc\HasMethodInterface;
2827
use Mcp\Schema\JsonRpc\Request;
2928
use Mcp\Schema\JsonRpc\Response;
3029
use Mcp\Schema\Request\InitializeRequest;
30+
use Mcp\Server\Configuration;
3131
use Mcp\Server\Handler;
3232
use Mcp\Server\Session\SessionFactoryInterface;
3333
use Mcp\Server\Session\SessionInterface;
@@ -66,7 +66,7 @@ public function __construct(
6666
public static function make(
6767
ReferenceRegistryInterface $registry,
6868
ReferenceProviderInterface $referenceProvider,
69-
Implementation $implementation,
69+
Configuration $configuration,
7070
ToolCallerInterface $toolCaller,
7171
ResourceReaderInterface $resourceReader,
7272
PromptGetterInterface $promptGetter,
@@ -81,7 +81,7 @@ public static function make(
8181
sessionStore: $sessionStore,
8282
methodHandlers: [
8383
new Notification\InitializedHandler(),
84-
new Handler\Request\InitializeHandler($registry->getCapabilities(), $implementation),
84+
new Handler\Request\InitializeHandler($configuration),
8585
new Handler\Request\PingHandler(),
8686
new Handler\Request\ListPromptsHandler($referenceProvider, $paginationLimit),
8787
new Handler\Request\GetPromptHandler($promptGetter),

src/Server/Handler/Request/InitializeHandler.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Mcp\Schema\Request\InitializeRequest;
1818
use Mcp\Schema\Result\InitializeResult;
1919
use Mcp\Schema\ServerCapabilities;
20+
use Mcp\Server\Configuration;
2021
use Mcp\Server\Handler\MethodHandlerInterface;
2122
use Mcp\Server\Session\SessionInterface;
2223

@@ -26,8 +27,7 @@
2627
final class InitializeHandler implements MethodHandlerInterface
2728
{
2829
public function __construct(
29-
public readonly ?ServerCapabilities $capabilities = new ServerCapabilities(),
30-
public readonly ?Implementation $serverInfo = new Implementation(),
30+
public readonly ?Configuration $configuration = null,
3131
) {
3232
}
3333

@@ -44,7 +44,11 @@ public function handle(InitializeRequest|HasMethodInterface $message, SessionInt
4444

4545
return new Response(
4646
$message->getId(),
47-
new InitializeResult($this->capabilities, $this->serverInfo),
47+
new InitializeResult(
48+
$this->configuration->capabilities ?? new ServerCapabilities(),
49+
$this->configuration->serverInfo ?? new Implementation(),
50+
$this->configuration?->instructions,
51+
),
4852
);
4953
}
5054
}

0 commit comments

Comments
 (0)