Registry implements RegistryInterface
Registry implementation that manages MCP element registration and access.
Tags
Table of Contents
Interfaces
Properties
- $eventDispatcher : EventDispatcherInterface|null
- $loaded : bool
- $loader : LoaderInterface|null
- $loading : bool
- $logger : LoggerInterface
- $nameValidator : NameValidator
- $prompts : array<string, PromptReference>
- $resources : array<string, ResourceReference>
- $resourceTemplates : array<string, ResourceTemplateReference>
- $tools : array<string, ToolReference>
Methods
- __construct() : mixed
- 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.
- hasPrompt() : bool
- hasPrompts() : bool
- hasResource() : bool
- hasResources() : bool
- hasResourceTemplate() : bool
- hasResourceTemplates() : bool
- hasTool() : bool
- hasTools() : bool
- load() : void
- Runs the configured loader once, on demand. Reads trigger this automatically, so element loading is deferred to the first read (request time) rather than eager at build time — under a persistent runtime a source not yet ready at build no longer freezes the registry empty.
- registerPrompt() : PromptReference
- Registers a prompt with its handler and completion providers.
- registerResource() : ResourceReference
- Registers a resource with its handler. Overwrites any prior registration of the same URI.
- registerResourceTemplate() : ResourceTemplateReference
- Registers a resource template with its handler and completion providers.
- registerTool() : ToolReference
- Registers a tool with its handler. Overwrites any prior registration of the same name.
- unregisterPrompt() : void
- Removes a prompt by name. No-op if absent.
- unregisterResource() : void
- Removes a resource by URI. No-op if absent.
- unregisterResourceTemplate() : void
- Removes a resource template by URI template. No-op if absent.
- unregisterTool() : void
- Removes a tool by name. No-op if absent.
- 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
$loaded
private
bool
$loaded
= false
$loader read-only
private
LoaderInterface|null
$loader
= null
$loading
private
bool
$loading
= false
$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() ][, LoaderInterface|null $loader = null ]) : mixed
Parameters
- $eventDispatcher : EventDispatcherInterface|null = null
- $logger : LoggerInterface = new NullLogger()
- $nameValidator : NameValidator = new NameValidator()
- $loader : LoaderInterface|null = null
getPrompt()
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
PagehasPrompt()
public
hasPrompt(string $name) : bool
Parameters
- $name : string
Return values
boolhasPrompts()
public
hasPrompts() : bool
Return values
bool —true if any prompts are registered
hasResource()
public
hasResource(string $uri) : bool
Parameters
- $uri : string
Return values
boolhasResources()
public
hasResources() : bool
Return values
bool —true if any resources are registered
hasResourceTemplate()
public
hasResourceTemplate(string $uriTemplate) : bool
Parameters
- $uriTemplate : string
Return values
boolhasResourceTemplates()
public
hasResourceTemplates() : bool
Return values
bool —true if any resource templates are registered
hasTool()
public
hasTool(string $name) : bool
Parameters
- $name : string
Return values
boolhasTools()
public
hasTools() : bool
Return values
bool —true if any tools are registered
load()
Runs the configured loader once, on demand. Reads trigger this automatically, so element loading is deferred to the first read (request time) rather than eager at build time — under a persistent runtime a source not yet ready at build no longer freezes the registry empty.
public
load() : void
loaded is set only after success, so a transient failure is retried on the next read. The
loading guard lets a loader read the registry during its own run (e.g. discovery's identity
check) without re-entering the load.
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 = [] ]) : PromptReference
Overwrites any prior registration of the same name. Returns the stored reference, whose identity callers may track to detect later overwrites.
Parameters
- $prompt : Prompt
- $handler : callable|array<string|int, mixed>|string
- $completionProviders : array<string|int, mixed> = []
Return values
PromptReferenceregisterResource()
Registers a resource with its handler. Overwrites any prior registration of the same URI.
public
registerResource(ResourceDefinition $resource, callable|array<string|int, mixed>|string $handler) : ResourceReference
Returns the stored reference, whose identity callers may track to detect later overwrites.
Parameters
- $resource : ResourceDefinition
- $handler : callable|array<string|int, mixed>|string
Return values
ResourceReferenceregisterResourceTemplate()
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 = [] ]) : ResourceTemplateReference
Overwrites any prior registration of the same URI template. Returns the stored reference, whose identity callers may track to detect later overwrites.
Parameters
- $template : ResourceTemplate
- $handler : callable|array<string|int, mixed>|string
- $completionProviders : array<string|int, mixed> = []
Return values
ResourceTemplateReferenceregisterTool()
Registers a tool with its handler. Overwrites any prior registration of the same name.
public
registerTool(Tool $tool, callable|array<string|int, mixed>|string $handler) : ToolReference
Returns the stored reference, whose identity callers may track to detect later overwrites.
Parameters
- $tool : Tool
- $handler : callable|array<string|int, mixed>|string
Return values
ToolReferenceunregisterPrompt()
Removes a prompt by name. No-op if absent.
public
unregisterPrompt(string $name) : void
Parameters
- $name : string
unregisterResource()
Removes a resource by URI. No-op if absent.
public
unregisterResource(string $uri) : void
Parameters
- $uri : string
unregisterResourceTemplate()
Removes a resource template by URI template. No-op if absent.
public
unregisterResourceTemplate(string $uriTemplate) : void
Parameters
- $uriTemplate : string
unregisterTool()
Removes a tool by name. No-op if absent.
public
unregisterTool(string $name) : void
Parameters
- $name : string
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