Fix missing instructions from builder to handler (#90)

This commit is contained in:
Christopher Hertel 2025-10-07 23:32:51 +02:00 • committed by GitHub
commit cbd1b298e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 15 deletions

View file

@ -362,14 +362,17 @@ final class Builder
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,
);

View file

@ -22,12 +22,12 @@ use Mcp\Exception\HandlerNotFoundException;
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;
@ -66,7 +66,7 @@ class JsonRpcHandler
public static function make(
ReferenceRegistryInterface $registry,
ReferenceProviderInterface $referenceProvider,
Implementation $implementation,
Configuration $configuration,
ToolCallerInterface $toolCaller,
ResourceReaderInterface $resourceReader,
PromptGetterInterface $promptGetter,
@ -81,7 +81,7 @@ class JsonRpcHandler
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),

View file

@ -17,6 +17,7 @@ use Mcp\Schema\JsonRpc\Response;
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;
@ -26,8 +27,7 @@ use Mcp\Server\Session\SessionInterface;
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,
) {
}
@ -44,7 +44,11 @@ final class InitializeHandler implements MethodHandlerInterface
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,
),
);
}
}