Skip to content

Commit 9be9e38

Browse files
authored
ability to append loaders to server builder (#132)
1 parent ff26b4f commit 9be9e38

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Server/Builder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Mcp\Capability\Registry\ElementReference;
1717
use Mcp\Capability\Registry\Loader\ArrayLoader;
1818
use Mcp\Capability\Registry\Loader\DiscoveryLoader;
19+
use Mcp\Capability\Registry\Loader\LoaderInterface;
1920
use Mcp\Capability\Registry\ReferenceHandler;
2021
use Mcp\JsonRpc\MessageFactory;
2122
use Mcp\Schema\Annotations;
@@ -130,6 +131,11 @@ final class Builder
130131

131132
private ?ServerCapabilities $serverCapabilities = null;
132133

134+
/**
135+
* @var LoaderInterface[]
136+
*/
137+
private array $loaders = [];
138+
133139
/**
134140
* Sets the server's identity. Required.
135141
*/
@@ -356,6 +362,16 @@ public function addPrompt(\Closure|array|string $handler, ?string $name = null,
356362
return $this;
357363
}
358364

365+
/**
366+
* @param LoaderInterface[] $loaders
367+
*/
368+
public function addLoaders(...$loaders): self
369+
{
370+
$this->loaders = [...$this->loaders, ...$loaders];
371+
372+
return $this;
373+
}
374+
359375
/**
360376
* Builds the fully configured Server instance.
361377
*/
@@ -366,6 +382,7 @@ public function build(): Server
366382
$registry = new Registry($this->eventDispatcher, $logger);
367383

368384
$loaders = [
385+
...$this->loaders,
369386
new ArrayLoader($this->tools, $this->resources, $this->resourceTemplates, $this->prompts, $logger),
370387
];
371388

0 commit comments

Comments
 (0)