Registry implements RegistryInterface
Registry implementation that manages MCP element registration and access.
Tags
Table of Contents
Interfaces
Properties
- $eventDispatcher : EventDispatcherInterface|null
- $logger : LoggerInterface
- $nameValidator : NameValidator
- $prompts : array<string, PromptReference>
- $resources : array<string, ResourceReference>
- $resourceTemplates : array<string, ResourceTemplateReference>
- $tools : array<string, ToolReference>
Methods
- __construct() : mixed
- clear() : void
- Clear discovered elements from registry.
- getDiscoveryState() : DiscoveryState
- Get the current discovery state (only discovered elements, not manual ones).
- getPrompt() : PromptReference
- Gets a prompt reference by name.
- getPrompts() : Page
- Gets all registered prompts.
- getResource() : ResourceReference|ResourceTemplateReference
- Gets a resource reference by URI (includes template matching if enabled).
- getResources() : Page
- Gets all registered resources.
- getResourceTemplate() : ResourceTemplateReference
- Gets a resource template reference by URI template.
- getResourceTemplates() : Page
- Gets all registered resource templates.
- getTool() : ToolReference
- Gets a tool reference by name.
- getTools() : Page
- Gets all registered tools.
- hasPrompts() : bool
- hasResources() : bool
- hasResourceTemplates() : bool
- hasTools() : bool
- registerPrompt() : void
- Registers a prompt with its handler and completion providers.
- registerResource() : void
- Registers a resource with its handler.
- registerResourceTemplate() : void
- Registers a resource template with its handler and completion providers.
- registerTool() : void
- Registers a tool with its handler.
- setDiscoveryState() : void
- Set the discovery state, replacing all discovered elements.
- calculateNextCursor() : string|null
- Calculate next cursor for pagination.
- paginateResults() : array<int|string, mixed>
- Helper method to paginate results using cursor-based pagination.
Properties
$eventDispatcher read-only
private
EventDispatcherInterface|null
$eventDispatcher
= null
$logger read-only
private
LoggerInterface
$logger
= new NullLogger()
$nameValidator read-only
private
NameValidator
$nameValidator
= new NameValidator()
$prompts
private
array<string, PromptReference>
$prompts
= []
$resources
private
array<string, ResourceReference>
$resources
= []
$resourceTemplates
private
array<string, ResourceTemplateReference>
$resourceTemplates
= []
$tools
private
array<string, ToolReference>
$tools
= []
Methods
__construct()
public
__construct([EventDispatcherInterface|null $eventDispatcher = null ][, LoggerInterface $logger = new NullLogger() ][, NameValidator $nameValidator = new NameValidator() ]) : mixed
Parameters
- $eventDispatcher : EventDispatcherInterface|null = null
- $logger : LoggerInterface = new NullLogger()
- $nameValidator : NameValidator = new NameValidator()
clear()
Clear discovered elements from registry.
public
clear() : void
getDiscoveryState()
Get the current discovery state (only discovered elements, not manual ones).
public
getDiscoveryState() : DiscoveryState
Return values
DiscoveryStategetPrompt()
Gets a prompt reference by name.
public
getPrompt(string $name) : PromptReference
Parameters
- $name : string
Return values
PromptReferencegetPrompts()
Gets all registered prompts.
public
getPrompts([int|null $limit = null ][, string|null $cursor = null ]) : Page
Parameters
- $limit : int|null = null
- $cursor : string|null = null
Return values
PagegetResource()
Gets a resource reference by URI (includes template matching if enabled).
public
getResource(string $uri[, bool $includeTemplates = true ]) : ResourceReference|ResourceTemplateReference
Parameters
- $uri : string
- $includeTemplates : bool = true
Return values
ResourceReference|ResourceTemplateReferencegetResources()
Gets all registered resources.
public
getResources([int|null $limit = null ][, string|null $cursor = null ]) : Page
Parameters
- $limit : int|null = null
- $cursor : string|null = null
Return values
PagegetResourceTemplate()
Gets a resource template reference by URI template.
public
getResourceTemplate(string $uriTemplate) : ResourceTemplateReference
Parameters
- $uriTemplate : string
Return values
ResourceTemplateReferencegetResourceTemplates()
Gets all registered resource templates.
public
getResourceTemplates([int|null $limit = null ][, string|null $cursor = null ]) : Page
Parameters
- $limit : int|null = null
- $cursor : string|null = null
Return values
PagegetTool()
Gets a tool reference by name.
public
getTool(string $name) : ToolReference
Parameters
- $name : string
Return values
ToolReferencegetTools()
Gets all registered tools.
public
getTools([int|null $limit = null ][, string|null $cursor = null ]) : Page
Parameters
- $limit : int|null = null
- $cursor : string|null = null
Return values
PagehasPrompts()
public
hasPrompts() : bool
Return values
bool —true if any prompts are registered
hasResources()
public
hasResources() : bool
Return values
bool —true if any resources are registered
hasResourceTemplates()
public
hasResourceTemplates() : bool
Return values
bool —true if any resource templates are registered
hasTools()
public
hasTools() : bool
Return values
bool —true if any tools are registered
registerPrompt()
Registers a prompt with its handler and completion providers.
public
registerPrompt(Prompt $prompt, callable|array<string|int, mixed>|string $handler[, array<string|int, mixed> $completionProviders = [] ][, bool $isManual = false ]) : void
Parameters
- $prompt : Prompt
- $handler : callable|array<string|int, mixed>|string
- $completionProviders : array<string|int, mixed> = []
- $isManual : bool = false
registerResource()
Registers a resource with its handler.
public
registerResource(Resource $resource, callable|array<string|int, mixed>|string $handler[, bool $isManual = false ]) : void
Parameters
- $resource : Resource
- $handler : callable|array<string|int, mixed>|string
- $isManual : bool = false
registerResourceTemplate()
Registers a resource template with its handler and completion providers.
public
registerResourceTemplate(ResourceTemplate $template, callable|array<string|int, mixed>|string $handler[, array<string|int, mixed> $completionProviders = [] ][, bool $isManual = false ]) : void
Parameters
- $template : ResourceTemplate
- $handler : callable|array<string|int, mixed>|string
- $completionProviders : array<string|int, mixed> = []
- $isManual : bool = false
registerTool()
Registers a tool with its handler.
public
registerTool(Tool $tool, callable|array<string|int, mixed>|string $handler[, bool $isManual = false ]) : void
Parameters
- $tool : Tool
- $handler : callable|array<string|int, mixed>|string
- $isManual : bool = false
setDiscoveryState()
Set the discovery state, replacing all discovered elements.
public
setDiscoveryState(DiscoveryState $state) : void
Manual elements are preserved.
Parameters
- $state : DiscoveryState
calculateNextCursor()
Calculate next cursor for pagination.
private
calculateNextCursor(int $totalItems, string|null $currentCursor, int $limit) : string|null
Parameters
- $totalItems : int
-
Count of all items
- $currentCursor : string|null
-
Current cursor position
- $limit : int
-
Number requested/returned per page
Return values
string|nullpaginateResults()
Helper method to paginate results using cursor-based pagination.
private
paginateResults(array<int|string, mixed> $items, int $limit[, string|null $cursor = null ]) : array<int|string, mixed>
Parameters
- $items : array<int|string, mixed>
-
The full array of items to paginate The full array of items to paginate
- $limit : int
-
Maximum number of items to return
- $cursor : string|null = null
-
Base64 encoded offset position
Tags
Return values
array<int|string, mixed> —Paginated results