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
- 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
- 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
$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()
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
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