Skip to content

Commit 05407d2

Browse files
committed
Fix missing instructions from builder to handler
1 parent 41486bf commit 05407d2

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

examples/01-discovery-stdio-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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ parameters:
7878
count: 1
7979
path: src/Server/Builder.php
8080

81-
-
82-
message: '#^Property Mcp\\Server\\Builder\:\:\$instructions is never read, only written\.$#'
83-
identifier: property.onlyWritten
84-
count: 1
85-
path: src/Server/Builder.php
86-
8781
-
8882
message: '#^Property Mcp\\Server\\Builder\:\:\$prompts type has no value type specified in iterable type array\.$#'
8983
identifier: missingType.iterableValue

src/Server/Builder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,17 @@ public function build(): Server
337337
jsonRpcHandler: JsonRpcHandler::make(
338338
registry: $registry,
339339
referenceProvider: $registry,
340-
implementation: $this->serverInfo,
340+
configuration: new Configuration(
341+
$this->serverInfo,
342+
$registry->getCapabilities(),
343+
$this->paginationLimit, $this->instructions,
344+
),
341345
toolCaller: $toolCaller,
342346
resourceReader: $resourceReader,
343347
promptGetter: $promptGetter,
344348
sessionStore: $sessionStore,
345349
sessionFactory: $sessionFactory,
346350
logger: $logger,
347-
paginationLimit: $this->paginationLimit,
348351
),
349352
logger: $logger,
350353
);

src/Server/Handler/JsonRpcHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
use Mcp\Exception\InvalidInputMessageException;
2222
use Mcp\Exception\NotFoundExceptionInterface;
2323
use Mcp\JsonRpc\MessageFactory;
24-
use Mcp\Schema\Implementation;
2524
use Mcp\Schema\JsonRpc\Error;
2625
use Mcp\Schema\JsonRpc\HasMethodInterface;
2726
use Mcp\Schema\JsonRpc\Request;
2827
use Mcp\Schema\JsonRpc\Response;
2928
use Mcp\Schema\Request\InitializeRequest;
29+
use Mcp\Server\Configuration;
3030
use Mcp\Server\Handler;
3131
use Mcp\Server\Session\SessionFactoryInterface;
3232
use Mcp\Server\Session\SessionInterface;
@@ -65,7 +65,7 @@ public function __construct(
6565
public static function make(
6666
ReferenceRegistryInterface $registry,
6767
ReferenceProviderInterface $referenceProvider,
68-
Implementation $implementation,
68+
Configuration $configuration,
6969
ToolCallerInterface $toolCaller,
7070
ResourceReaderInterface $resourceReader,
7171
PromptGetterInterface $promptGetter,
@@ -80,7 +80,7 @@ public static function make(
8080
sessionStore: $sessionStore,
8181
methodHandlers: [
8282
new Notification\InitializedHandler(),
83-
new Handler\Request\InitializeHandler($registry->getCapabilities(), $implementation),
83+
new Handler\Request\InitializeHandler($configuration),
8484
new Handler\Request\PingHandler(),
8585
new Handler\Request\ListPromptsHandler($referenceProvider, $paginationLimit),
8686
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)