ResourceResultFormatter
FinalYes
Formats the raw result of a resource read operation into MCP ResourceContent items.
Tags
Table of Contents
Methods
- format() : array<string|int, ResourceContents>
- Formats the raw result of a resource read operation into MCP ResourceContent items.
- guessMimeTypeFromString() : string
- Guesses MIME type from string content (very basic).
- textOrBlob() : ResourceContents
- Text that is not valid UTF-8 cannot be sent as JSON, so it is sent as a blob with the same MIME type instead of failing the whole read.
Methods
format()
Formats the raw result of a resource read operation into MCP ResourceContent items.
public
format(mixed $readResult, string $uri[, string|null $mimeType = null ][, mixed $meta = 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
- $meta : mixed = null
-
optional metadata to include in the ResourceContents
Tags
Return values
array<string|int, ResourceContents> —array of ResourceContents objects
guessMimeTypeFromString()
Guesses MIME type from string content (very basic).
private
guessMimeTypeFromString(string $content) : string
Parameters
- $content : string
Return values
stringtextOrBlob()
Text that is not valid UTF-8 cannot be sent as JSON, so it is sent as a blob with the same MIME type instead of failing the whole read.
private
textOrBlob(string $uri, string $mimeType, string $content, mixed $meta) : ResourceContents
Parameters
- $uri : string
- $mimeType : string
- $content : string
- $meta : mixed