MCP PHP SDK

ResourceTemplateReference extends ElementReference

Tags
phpstan-import-type

Handler from ElementReference

author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Properties

$completionProviders  : array<string|int, mixed>
$handler  : Closure|array<string|int, mixed>|string
$isManual  : bool
$resourceTemplate  : ResourceTemplate
$uriTemplateRegex  : string
$variableNames  : array<int, string>

Methods

__construct()  : mixed
extractVariables()  : array<string, mixed>
formatResult()  : array<int, ResourceContents>
Formats the raw result of a resource read operation into MCP ResourceContent items.
getVariableNames()  : array<int, string>
matches()  : bool
compileTemplate()  : void

Properties

$handler read-only

public Closure|array<string|int, mixed>|string $handler

Methods

__construct()

public __construct(ResourceTemplate $resourceTemplate, Handler $handler[, bool $isManual = false ][, array<string, class-string|object> $completionProviders = [] ]) : mixed
Parameters
$resourceTemplate : ResourceTemplate
$handler : Handler
$isManual : bool = false
$completionProviders : array<string, class-string|object> = []

extractVariables()

public extractVariables(string $uri) : array<string, mixed>
Parameters
$uri : string
Return values
array<string, mixed>

formatResult()

Formats the raw result of a resource read operation into MCP ResourceContent items.

public formatResult(mixed $readResult, string $uri[, string|null $mimeType = null ]) : array<int, ResourceContents>
Parameters
$readResult : mixed

the raw result from the resource handler method

$uri : string

the URI of the resource that was read

$mimeType : string|null = null
Return values
array<int, ResourceContents>

array of ResourceContents objects

Supported result types:

  • ResourceContents: Used as-is
  • EmbeddedResource: Resource is extracted from the EmbeddedResource
  • string: Converted to text content with guessed or provided MIME type
  • stream resource: Read and converted to blob with provided MIME type
  • array with 'blob' key: Used as blob content
  • array with 'text' key: Used as text content
  • SplFileInfo: Read and converted to blob
  • array: Converted to JSON if MIME type is application/json or contains 'json' For other MIME types, will try to convert to JSON with a warning

        
On this page

Search results