ability to append loaders to server builder (#132)

This commit is contained in:
Antoine Bluchet 2025-11-04 22:44:53 +01:00 • committed by GitHub
commit 9be9e38815
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,6 +16,7 @@ use Mcp\Capability\Registry\Container;
use Mcp\Capability\Registry\ElementReference;
use Mcp\Capability\Registry\Loader\ArrayLoader;
use Mcp\Capability\Registry\Loader\DiscoveryLoader;
use Mcp\Capability\Registry\Loader\LoaderInterface;
use Mcp\Capability\Registry\ReferenceHandler;
use Mcp\JsonRpc\MessageFactory;
use Mcp\Schema\Annotations;
@ -130,6 +131,11 @@ final class Builder
private ?ServerCapabilities $serverCapabilities = null;
/**
* @var LoaderInterface[]
*/
private array $loaders = [];
/**
* Sets the server's identity. Required.
*/
@ -356,6 +362,16 @@ final class Builder
return $this;
}
/**
* @param LoaderInterface[] $loaders
*/
public function addLoaders(...$loaders): self
{
$this->loaders = [...$this->loaders, ...$loaders];
return $this;
}
/**
* Builds the fully configured Server instance.
*/
@ -366,6 +382,7 @@ final class Builder
$registry = new Registry($this->eventDispatcher, $logger);
$loaders = [
...$this->loaders,
new ArrayLoader($this->tools, $this->resources, $this->resourceTemplates, $this->prompts, $logger),
];