Discoverer
in package
Tags
Table of Contents
Properties
- $docBlockParser : DocBlockParser|null
- $logger : LoggerInterface
- $schemaGenerator : SchemaGenerator|null
Methods
- __construct() : mixed
- discover() : DiscoveryState
- Discover MCP elements in the specified directories and return the discovery state.
- getClassFromFile() : class-string|null
- Attempt to determine the FQCN from a PHP file path.
- getCompletionProviders() : array<string, string|ProviderInterface>
- processFile() : void
- Process a single PHP file for MCP elements on classes or methods.
- processMethod() : void
- Process a method with a given MCP attribute instance.
Properties
$docBlockParser
private
DocBlockParser|null
$docBlockParser
= null
$logger read-only
private
LoggerInterface
$logger
= new NullLogger()
$schemaGenerator
private
SchemaGenerator|null
$schemaGenerator
= null
Methods
__construct()
public
__construct([LoggerInterface $logger = new NullLogger() ][, DocBlockParser|null $docBlockParser = null ][, SchemaGenerator|null $schemaGenerator = null ]) : mixed
Parameters
- $logger : LoggerInterface = new NullLogger()
- $docBlockParser : DocBlockParser|null = null
- $schemaGenerator : SchemaGenerator|null = null
discover()
Discover MCP elements in the specified directories and return the discovery state.
public
discover(string $basePath, array<string|int, string> $directories[, array<string|int, string> $excludeDirs = [] ]) : DiscoveryState
Parameters
- $basePath : string
-
the base path for resolving directories
- $directories : array<string|int, string>
-
list of directories (relative to base path) to scan
- $excludeDirs : array<string|int, string> = []
-
list of directories (relative to base path) to exclude from the scan
Return values
DiscoveryStategetClassFromFile()
Attempt to determine the FQCN from a PHP file path.
private
getClassFromFile(SplFileInfo $file) : class-string|null
Uses tokenization to extract namespace and class name.
Parameters
- $file : SplFileInfo
Return values
class-string|null —the FQCN or null if not found/determinable
getCompletionProviders()
private
getCompletionProviders(ReflectionMethod $reflectionMethod) : array<string, string|ProviderInterface>
Parameters
- $reflectionMethod : ReflectionMethod
Return values
array<string, string|ProviderInterface>processFile()
Process a single PHP file for MCP elements on classes or methods.
private
processFile(SplFileInfo $file, DiscoveredCount &$discoveredCount, array<string, ToolReference> &$tools, array<string, ResourceReference> &$resources, array<string, PromptReference> &$prompts, array<string, ResourceTemplateReference> &$resourceTemplates) : void
Parameters
- $file : SplFileInfo
- $discoveredCount : DiscoveredCount
- $tools : array<string, ToolReference>
- $resources : array<string, ResourceReference>
- $prompts : array<string, PromptReference>
- $resourceTemplates : array<string, ResourceTemplateReference>
processMethod()
Process a method with a given MCP attribute instance.
private
processMethod(ReflectionMethod $method, DiscoveredCount &$discoveredCount, ReflectionAttribute<string|int, McpTool|McpResource|McpPrompt|McpResourceTemplate> $attribute, array<string, ToolReference> &$tools, array<string, ResourceReference> &$resources, array<string, PromptReference> &$prompts, array<string, ResourceTemplateReference> &$resourceTemplates) : void
Can be called for regular methods or the __invoke method of an invokable class.
Parameters
- $method : ReflectionMethod
-
The target method (e.g., regular method or __invoke).
- $discoveredCount : DiscoveredCount
-
pass by reference to update counts
- $attribute : ReflectionAttribute<string|int, McpTool|McpResource|McpPrompt|McpResourceTemplate>
-
the ReflectionAttribute instance found (on method or class)
- $tools : array<string, ToolReference>
- $resources : array<string, ResourceReference>
- $prompts : array<string, PromptReference>
- $resourceTemplates : array<string, ResourceTemplateReference>