Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions docs/discovery-caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use Symfony\Component\Cache\Psr16Cache;

$server = Server::make()
->setServerInfo('My Server', '1.0.0')
->setDiscovery(__DIR__, ['.'])
->setCache(new Psr16Cache(new ArrayAdapter())) // Enable caching
->setDiscovery(__DIR__, ['.'], [], new Psr16Cache(new ArrayAdapter())) // Enable caching
->build();
```

Expand Down Expand Up @@ -69,8 +68,7 @@ $cache = DoctrineProvider::wrap(new ArrayCache());
$cache = new Psr16Cache(new ArrayAdapter());

$server = Server::make()
->setDiscovery(__DIR__, ['.'])
->setCache($cache)
->setDiscovery(__DIR__, ['.'], [], $cache)
->build();
```

Expand All @@ -81,8 +79,7 @@ $server = Server::make()
$cache = new Psr16Cache(new FilesystemAdapter('mcp-discovery', 0, '/var/cache'));

$server = Server::make()
->setDiscovery(__DIR__, ['.'])
->setCache($cache)
->setDiscovery(__DIR__, ['.'], [], $cache)
->build();
```

Expand Down
3 changes: 1 addition & 2 deletions examples/09-cached-discovery-stdio/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
->setServerInfo('Cached Discovery Calculator', '1.0.0', 'Calculator with cached discovery for better performance.')
->setContainer(container())
->setLogger(logger())
->setDiscovery(__DIR__, ['.'])
->setCache(new Psr16Cache(new ArrayAdapter()))
->setDiscovery(__DIR__, ['.'], [], new Psr16Cache(new ArrayAdapter()))
->build();

$transport = new StdioTransport(logger: logger());
Expand Down
18 changes: 5 additions & 13 deletions src/Server/ServerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class ServerBuilder

private ?LoggerInterface $logger = null;

private ?CacheInterface $cache = null;
private ?CacheInterface $discoveryCache = null;

private ?ToolCallerInterface $toolCaller = null;

Expand Down Expand Up @@ -220,20 +220,12 @@ public function setDiscovery(
string $basePath,
array $scanDirs = ['.', 'src'],
array $excludeDirs = [],
?CacheInterface $cache = null,
): self {
$this->discoveryBasePath = $basePath;
$this->discoveryScanDirs = $scanDirs;
$this->discoveryExcludeDirs = $excludeDirs;

return $this;
}

/**
* Enables discovery caching with the provided cache implementation.
*/
public function setCache(CacheInterface $cache): self
{
$this->cache = $cache;
$this->discoveryCache = $cache;

return $this;
}
Expand Down Expand Up @@ -323,8 +315,8 @@ public function build(): Server
if (null !== $this->discoveryBasePath) {
$discovery = new Discoverer($registry, $logger);

if (null !== $this->cache) {
$discovery = new CachedDiscoverer($discovery, $this->cache, $logger);
if (null !== $this->discoveryCache) {
$discovery = new CachedDiscoverer($discovery, $this->discoveryCache, $logger);
}

$discovery->discover($this->discoveryBasePath, $this->discoveryScanDirs, $this->discoveryExcludeDirs);
Expand Down