MCP PHP SDK

ResourceReference extends ElementReference

Tags
phpstan-import-type

Handler from ElementReference

author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Properties

$handler  : Closure|array<string|int, mixed>|string
$isManual  : bool
$resource  : Resource

Methods

__construct()  : mixed
formatResult()  : array<string|int, ResourceContents>
Formats the raw result of a resource read operation into MCP ResourceContent items.

Properties

$handler read-only

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

Methods

__construct()

public __construct(Resource $resource, Handler $handler[, bool $isManual = false ]) : mixed
Parameters
$resource : Resource
$handler : Handler
$isManual : bool = false

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

the MIME type from the ResourceDefinition

Return values
array<string|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