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

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

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

hasPrompts()

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