@@ -58,7 +58,7 @@ public function __construct(
5858 * - array: Converted to JSON if MIME type is application/json or contains 'json'
5959 * For other MIME types, will try to convert to JSON with a warning
6060 */
61- public function formatResult (mixed $ readResult , string $ uri , ?string $ mimeType = null ): array
61+ public function formatResult (mixed $ readResult , string $ uri , ?string $ mimeType = null , ? array $ _meta = null ): array
6262 {
6363 if ($ readResult instanceof ResourceContents) {
6464 return [$ readResult ];
@@ -118,7 +118,7 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
118118 if (\is_string ($ readResult )) {
119119 $ mimeType = $ mimeType ?? $ this ->guessMimeTypeFromString ($ readResult );
120120
121- return [new TextResourceContents ($ uri , $ mimeType , $ readResult )];
121+ return [new TextResourceContents ($ uri , $ mimeType , $ readResult, $ _meta )];
122122 }
123123
124124 if (\is_resource ($ readResult ) && 'stream ' === get_resource_type ($ readResult )) {
@@ -142,12 +142,12 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
142142 if (\is_array ($ readResult ) && isset ($ readResult ['text ' ]) && \is_string ($ readResult ['text ' ])) {
143143 $ mimeType = $ readResult ['mimeType ' ] ?? $ mimeType ?? 'text/plain ' ;
144144
145- return [new TextResourceContents ($ uri , $ mimeType , $ readResult ['text ' ])];
145+ return [new TextResourceContents ($ uri , $ mimeType , $ readResult ['text ' ], $ _meta )];
146146 }
147147
148148 if ($ readResult instanceof \SplFileInfo && $ readResult ->isFile () && $ readResult ->isReadable ()) {
149149 if ($ mimeType && str_contains (strtolower ($ mimeType ), 'text ' )) {
150- return [new TextResourceContents ($ uri , $ mimeType , file_get_contents ($ readResult ->getPathname ()))];
150+ return [new TextResourceContents ($ uri , $ mimeType , file_get_contents ($ readResult ->getPathname ()), $ _meta )];
151151 }
152152
153153 return [BlobResourceContents::fromSplFileInfo ($ uri , $ readResult , $ mimeType )];
@@ -159,7 +159,7 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
159159 try {
160160 $ jsonString = json_encode ($ readResult , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT );
161161
162- return [new TextResourceContents ($ uri , $ mimeType , $ jsonString )];
162+ return [new TextResourceContents ($ uri , $ mimeType , $ jsonString, $ _meta )];
163163 } catch (\JsonException $ e ) {
164164 throw new RuntimeException (\sprintf ('Failed to encode array as JSON for URI "%s": %s ' , $ uri , $ e ->getMessage ()));
165165 }
@@ -169,7 +169,7 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
169169 $ jsonString = json_encode ($ readResult , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT );
170170 $ mimeType = $ mimeType ?? 'application/json ' ;
171171
172- return [new TextResourceContents ($ uri , $ mimeType , $ jsonString )];
172+ return [new TextResourceContents ($ uri , $ mimeType , $ jsonString, $ _meta )];
173173 } catch (\JsonException $ e ) {
174174 throw new RuntimeException (\sprintf ('Failed to encode array as JSON for URI "%s": %s ' , $ uri , $ e ->getMessage ()));
175175 }
0 commit comments