Add possibility to set custom ServerCapabilities. (#95)
This commit is contained in:
parent
2dbd411194
commit
709a815cde
2 changed files with 68 additions and 1 deletions
|
|
@ -63,6 +63,8 @@ final class Registry implements ReferenceProviderInterface, ReferenceRegistryInt
|
|||
*/
|
||||
private array $resourceTemplates = [];
|
||||
|
||||
private ServerCapabilities $serverCapabilities;
|
||||
|
||||
public function __construct(
|
||||
private readonly ?EventDispatcherInterface $eventDispatcher = null,
|
||||
private readonly LoggerInterface $logger = new NullLogger(),
|
||||
|
|
@ -75,7 +77,7 @@ final class Registry implements ReferenceProviderInterface, ReferenceRegistryInt
|
|||
$this->logger->info('No capabilities registered on server.');
|
||||
}
|
||||
|
||||
return new ServerCapabilities(
|
||||
return $this->serverCapabilities ?? new ServerCapabilities(
|
||||
tools: [] !== $this->tools,
|
||||
toolsListChanged: $this->eventDispatcher instanceof EventDispatcherInterface,
|
||||
resources: [] !== $this->resources || [] !== $this->resourceTemplates,
|
||||
|
|
@ -453,4 +455,9 @@ final class Registry implements ReferenceProviderInterface, ReferenceRegistryInt
|
|||
|
||||
return array_values(\array_slice($items, $offset, $limit));
|
||||
}
|
||||
|
||||
public function setServerCapabilities(ServerCapabilities $serverCapabilities): void
|
||||
{
|
||||
$this->serverCapabilities = $serverCapabilities;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,6 +138,8 @@ final class Builder
|
|||
*/
|
||||
private array $discoveryExcludeDirs = [];
|
||||
|
||||
private ?ServerCapabilities $serverCapabilities = null;
|
||||
|
||||
/**
|
||||
* Sets the server's identity. Required.
|
||||
*/
|
||||
|
|
@ -264,6 +266,13 @@ final class Builder
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setServerCapabilities(ServerCapabilities $serverCapabilities): self
|
||||
{
|
||||
$this->serverCapabilities = $serverCapabilities;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually registers a tool handler.
|
||||
*
|
||||
|
|
@ -348,6 +357,9 @@ final class Builder
|
|||
$registry = new Registry($this->eventDispatcher, $logger);
|
||||
|
||||
$this->registerCapabilities($registry, $logger);
|
||||
if ($this->serverCapabilities) {
|
||||
$registry->setServerCapabilities($this->serverCapabilities);
|
||||
}
|
||||
|
||||
if (null !== $this->discoveryBasePath) {
|
||||
$this->performDiscovery($registry, $logger);
|
||||
|
|
|
|||
Loading…
Reference in a new issue