MCP PHP SDK

Discoverer
in package

Tags
phpstan-type

DiscoveredCount array{ tools: int, resources: int, prompts: int, resourceTemplates: int, }

author

Kyrian Obikwelu koshnawaza@gmail.com

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

$logger read-only

private LoggerInterface $logger = new NullLogger()

Methods

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
DiscoveryState

getClassFromFile()

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>

        
On this page

Search results