|
11 | 11 |
|
12 | 12 | namespace Mcp\Server; |
13 | 13 |
|
| 14 | +use Mcp\Capability\Discovery\CachedDiscoverer; |
| 15 | +use Mcp\Capability\Discovery\Discoverer; |
| 16 | +use Mcp\Capability\Discovery\DiscovererInterface; |
| 17 | +use Mcp\Capability\Discovery\SchemaGeneratorInterface; |
14 | 18 | use Mcp\Capability\Registry; |
15 | 19 | use Mcp\Capability\Registry\Container; |
16 | 20 | use Mcp\Capability\Registry\ElementReference; |
@@ -58,6 +62,10 @@ final class Builder |
58 | 62 |
|
59 | 63 | private ?ContainerInterface $container = null; |
60 | 64 |
|
| 65 | + private ?SchemaGeneratorInterface $schemaGenerator = null; |
| 66 | + |
| 67 | + private ?DiscovererInterface $discoverer = null; |
| 68 | + |
61 | 69 | private ?SessionFactoryInterface $sessionFactory = null; |
62 | 70 |
|
63 | 71 | private ?SessionStoreInterface $sessionStore = null; |
@@ -287,6 +295,20 @@ public function setContainer(ContainerInterface $container): self |
287 | 295 | return $this; |
288 | 296 | } |
289 | 297 |
|
| 298 | + public function setSchemaGenerator(SchemaGeneratorInterface $schemaGenerator): self |
| 299 | + { |
| 300 | + $this->schemaGenerator = $schemaGenerator; |
| 301 | + |
| 302 | + return $this; |
| 303 | + } |
| 304 | + |
| 305 | + public function setDiscoverer(DiscovererInterface $discoverer): self |
| 306 | + { |
| 307 | + $this->discoverer = $discoverer; |
| 308 | + |
| 309 | + return $this; |
| 310 | + } |
| 311 | + |
290 | 312 | public function setSession( |
291 | 313 | SessionStoreInterface $sessionStore, |
292 | 314 | SessionFactoryInterface $sessionFactory = new SessionFactory(), |
@@ -470,11 +492,12 @@ public function build(): Server |
470 | 492 |
|
471 | 493 | $loaders = [ |
472 | 494 | ...$this->loaders, |
473 | | - new ArrayLoader($this->tools, $this->resources, $this->resourceTemplates, $this->prompts, $logger), |
| 495 | + new ArrayLoader($this->tools, $this->resources, $this->resourceTemplates, $this->prompts, $logger, $this->schemaGenerator), |
474 | 496 | ]; |
475 | 497 |
|
476 | 498 | if (null !== $this->discoveryBasePath) { |
477 | | - $loaders[] = new DiscoveryLoader($this->discoveryBasePath, $this->discoveryScanDirs, $this->discoveryExcludeDirs, $logger, $this->discoveryCache); |
| 499 | + $discoverer = $this->discoverer ?? $this->createDiscoverer($logger); |
| 500 | + $loaders[] = new DiscoveryLoader($this->discoveryBasePath, $this->discoveryScanDirs, $this->discoveryExcludeDirs, $discoverer); |
478 | 501 | } |
479 | 502 |
|
480 | 503 | foreach ($loaders as $loader) { |
@@ -531,4 +554,15 @@ public function build(): Server |
531 | 554 |
|
532 | 555 | return new Server($protocol, $logger); |
533 | 556 | } |
| 557 | + |
| 558 | + private function createDiscoverer(LoggerInterface $logger): DiscovererInterface |
| 559 | + { |
| 560 | + $discoverer = new Discoverer($logger, null, $this->schemaGenerator); |
| 561 | + |
| 562 | + if (null !== $this->discoveryCache) { |
| 563 | + return new CachedDiscoverer($discoverer, $this->discoveryCache, $logger); |
| 564 | + } |
| 565 | + |
| 566 | + return $discoverer; |
| 567 | + } |
534 | 568 | } |
0 commit comments