Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/stdio-discovery-calculator/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

$server = Server::builder()
->setServerInfo('Stdio Calculator', '1.1.0', 'Basic Calculator over STDIO transport.')
->setInstructions('This server supports basic arithmetic operations: add, subtract, multiply, and divide. Send JSON-RPC requests to perform calculations.')
->setContainer(container())
->setLogger(logger())
->setDiscovery(__DIR__, ['.'])
Expand Down
7 changes: 0 additions & 7 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,3 @@ parameters:
identifier: return.type
count: 1
path: src/Schema/Result/ReadResourceResult.php

-
message: '#^Property Mcp\\Server\\Builder\:\:\$instructions is never read, only written\.$#'
identifier: property.onlyWritten
count: 1
path: src/Server/Builder.php

7 changes: 5 additions & 2 deletions src/Server/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,17 @@ public function build(): Server
jsonRpcHandler: JsonRpcHandler::make(
registry: $registry,
referenceProvider: $registry,
implementation: $this->serverInfo,
configuration: new Configuration(
$this->serverInfo,
$registry->getCapabilities(),
$this->paginationLimit, $this->instructions,
),
toolCaller: $toolCaller,
resourceReader: $resourceReader,
promptGetter: $promptGetter,
sessionStore: $sessionStore,
sessionFactory: $sessionFactory,
logger: $logger,
paginationLimit: $this->paginationLimit,
),
logger: $logger,
);
Expand Down
6 changes: 3 additions & 3 deletions src/Server/Handler/JsonRpcHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
use Mcp\Exception\InvalidInputMessageException;
use Mcp\Exception\NotFoundExceptionInterface;
use Mcp\JsonRpc\MessageFactory;
use Mcp\Schema\Implementation;
use Mcp\Schema\JsonRpc\Error;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Request;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\InitializeRequest;
use Mcp\Server\Configuration;
use Mcp\Server\Handler;
use Mcp\Server\Session\SessionFactoryInterface;
use Mcp\Server\Session\SessionInterface;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function __construct(
public static function make(
ReferenceRegistryInterface $registry,
ReferenceProviderInterface $referenceProvider,
Implementation $implementation,
Configuration $configuration,
ToolCallerInterface $toolCaller,
ResourceReaderInterface $resourceReader,
PromptGetterInterface $promptGetter,
Expand All @@ -81,7 +81,7 @@ public static function make(
sessionStore: $sessionStore,
methodHandlers: [
new Notification\InitializedHandler(),
new Handler\Request\InitializeHandler($registry->getCapabilities(), $implementation),
new Handler\Request\InitializeHandler($configuration),
new Handler\Request\PingHandler(),
new Handler\Request\ListPromptsHandler($referenceProvider, $paginationLimit),
new Handler\Request\GetPromptHandler($promptGetter),
Expand Down
10 changes: 7 additions & 3 deletions src/Server/Handler/Request/InitializeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Mcp\Schema\Request\InitializeRequest;
use Mcp\Schema\Result\InitializeResult;
use Mcp\Schema\ServerCapabilities;
use Mcp\Server\Configuration;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

Expand All @@ -26,8 +27,7 @@
final class InitializeHandler implements MethodHandlerInterface
{
public function __construct(
public readonly ?ServerCapabilities $capabilities = new ServerCapabilities(),
public readonly ?Implementation $serverInfo = new Implementation(),
public readonly ?Configuration $configuration = null,
) {
}

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

return new Response(
$message->getId(),
new InitializeResult($this->capabilities, $this->serverInfo),
new InitializeResult(
$this->configuration->capabilities ?? new ServerCapabilities(),
$this->configuration->serverInfo ?? new Implementation(),
$this->configuration?->instructions,
),
);
}
}