Skip to content

Commit b4af500

Browse files
committed
ability to append loaders to server builder
1 parent ff26b4f commit b4af500

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Server/Builder.php

Lines changed: 16 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,15 @@ 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+
$this->loaders = [...$this->loaders, ...$loaders];
370+
371+
return $this;
372+
}
373+
359374
/**
360375
* Builds the fully configured Server instance.
361376
*/
@@ -366,6 +381,7 @@ public function build(): Server
366381
$registry = new Registry($this->eventDispatcher, $logger);
367382

368383
$loaders = [
384+
...$this->loaders,
369385
new ArrayLoader($this->tools, $this->resources, $this->resourceTemplates, $this->prompts, $logger),
370386
];
371387

0 commit comments

Comments
 (0)