fix: because the cached discoveryState does not use ->setDiscoveryState(), it is found that the discoveryState cannot be used (#120)

Co-authored-by: X2NX <x2nx@qq.com>
This commit is contained in:
OK Xaas 2025-10-27 06:25:09 +08:00 • committed by GitHub
commit 42b5261612
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 90 additions and 121 deletions

View file

@ -20,7 +20,6 @@ use Mcp\Capability\Completion\EnumCompletionProvider;
use Mcp\Capability\Completion\ListCompletionProvider;
use Mcp\Capability\Completion\ProviderInterface;
use Mcp\Capability\Registry\PromptReference;
use Mcp\Capability\Registry\ReferenceRegistryInterface;
use Mcp\Capability\Registry\ResourceReference;
use Mcp\Capability\Registry\ResourceTemplateReference;
use Mcp\Capability\Registry\ToolReference;
@ -48,7 +47,6 @@ use Symfony\Component\Finder\SplFileInfo;
class Discoverer
{
public function __construct(
private readonly ReferenceRegistryInterface $registry,
private readonly LoggerInterface $logger = new NullLogger(),
private ?DocBlockParser $docBlockParser = null,
private ?SchemaGenerator $schemaGenerator = null,
@ -95,10 +93,7 @@ class Discoverer
'base_path' => $basePath,
]);
$emptyState = new DiscoveryState();
$this->registry->setDiscoveryState($emptyState);
return $emptyState;
return new DiscoveryState();
}
$finder->files()
@ -125,11 +120,7 @@ class Discoverer
'resourceTemplates' => $discoveredCount['resourceTemplates'],
]);
$discoveryState = new DiscoveryState($tools, $resources, $prompts, $resourceTemplates);
$this->registry->setDiscoveryState($discoveryState);
return $discoveryState;
return new DiscoveryState($tools, $resources, $prompts, $resourceTemplates);
}
/**

View file

@ -38,12 +38,14 @@ final class DiscoveryLoader implements LoaderInterface
public function load(ReferenceRegistryInterface $registry): void
{
// This now encapsulates the discovery process
$discoverer = new Discoverer($registry, $this->logger);
$discoverer = new Discoverer($this->logger);
$cachedDiscoverer = $this->cache
? new CachedDiscoverer($discoverer, $this->cache, $this->logger)
: $discoverer;
$cachedDiscoverer->discover($this->basePath, $this->scanDirs, $this->excludeDirs);
$discoveryState = $cachedDiscoverer->discover($this->basePath, $this->scanDirs, $this->excludeDirs);
$registry->setDiscoveryState($discoveryState);
}
}