|
11 | 11 |
|
12 | 12 | namespace Mcp\Server; |
13 | 13 |
|
| 14 | +use Mcp\Capability\Discovery\DiscovererInterface; |
14 | 15 | use Mcp\Capability\Discovery\SchemaGeneratorInterface; |
15 | 16 | use Mcp\Capability\Registry; |
16 | 17 | use Mcp\Capability\Registry\Container; |
@@ -61,6 +62,8 @@ final class Builder |
61 | 62 |
|
62 | 63 | private ?SchemaGeneratorInterface $schemaGenerator = null; |
63 | 64 |
|
| 65 | + private ?DiscovererInterface $discoverer = null; |
| 66 | + |
64 | 67 | private ?SessionFactoryInterface $sessionFactory = null; |
65 | 68 |
|
66 | 69 | private ?SessionStoreInterface $sessionStore = null; |
@@ -296,6 +299,13 @@ public function setSchemaGenerator(SchemaGeneratorInterface $schemaGenerator): s |
296 | 299 | return $this; |
297 | 300 | } |
298 | 301 |
|
| 302 | + public function setDiscoverer(DiscovererInterface $discoverer): self |
| 303 | + { |
| 304 | + $this->discoverer = $discoverer; |
| 305 | + |
| 306 | + return $this; |
| 307 | + } |
| 308 | + |
299 | 309 | public function setSession( |
300 | 310 | SessionStoreInterface $sessionStore, |
301 | 311 | SessionFactoryInterface $sessionFactory = new SessionFactory(), |
@@ -480,7 +490,8 @@ public function build(): Server |
480 | 490 | ]; |
481 | 491 |
|
482 | 492 | if (null !== $this->discoveryBasePath) { |
483 | | - $loaders[] = new DiscoveryLoader($this->discoveryBasePath, $this->discoveryScanDirs, $this->discoveryExcludeDirs, $logger, $this->discoveryCache, $this->schemaGenerator); |
| 493 | + $discoverer = $this->discoverer ?? $this->createDiscoverer($logger); |
| 494 | + $loaders[] = new DiscoveryLoader($this->discoveryBasePath, $this->discoveryScanDirs, $this->discoveryExcludeDirs, $discoverer); |
484 | 495 | } |
485 | 496 |
|
486 | 497 | foreach ($loaders as $loader) { |
@@ -537,4 +548,15 @@ public function build(): Server |
537 | 548 |
|
538 | 549 | return new Server($protocol, $logger); |
539 | 550 | } |
| 551 | + |
| 552 | + private function createDiscoverer(LoggerInterface $logger): DiscovererInterface |
| 553 | + { |
| 554 | + $discoverer = new \Mcp\Capability\Discovery\Discoverer($logger, null, $this->schemaGenerator); |
| 555 | + |
| 556 | + if (null !== $this->discoveryCache) { |
| 557 | + return new \Mcp\Capability\Discovery\CachedDiscoverer($discoverer, $this->discoveryCache, $logger); |
| 558 | + } |
| 559 | + |
| 560 | + return $discoverer; |
| 561 | + } |
540 | 562 | } |
0 commit comments