MCP PHP SDK

Registry implements RegistryInterface

FinalYes

Registry implementation that manages MCP element registration and access.

Tags
author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Interfaces

RegistryInterface

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

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

getPrompts()

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
Page

getResources()

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
Page

getResourceTemplates()

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
Page

getTools()

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
Page

hasPrompt()

public hasPrompt(string $name) : bool
Parameters
$name : string
Return values
bool

hasPrompts()

public hasPrompts() : bool
Return values
bool

true if any prompts are registered

hasResource()

public hasResource(string $uri) : bool
Parameters
$uri : string
Return values
bool

hasResources()

public hasResources() : bool
Return values
bool

true if any resources are registered

hasResourceTemplate()

public hasResourceTemplate(string $uriTemplate) : bool
Parameters
$uriTemplate : string
Return values
bool

hasResourceTemplates()

public hasResourceTemplates() : bool
Return values
bool

true if any resource templates are registered

hasTool()

public hasTool(string $name) : bool
Parameters
$name : string
Return values
bool

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 = [] ]) : 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
PromptReference

registerResource()

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
ResourceReference

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 = [] ]) : 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
ResourceTemplateReference

registerTool()

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
ToolReference

unregisterPrompt()

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|null

paginateResults()

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
throws
InvalidCursorException

When cursor is invalid (MCP error code -32602)

Return values
array<int|string, mixed>

Paginated results

On this page

Search results