@@ -101,9 +101,11 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
101101 return [$ readResult ->resource ];
102102 }
103103
104+ $ _meta = $ this ->resourceTemplate ->_meta ;
105+
104106 if (\is_array ($ readResult )) {
105107 if (empty ($ readResult )) {
106- return [new TextResourceContents ($ uri , 'application/json ' , '[] ' )];
108+ return [new TextResourceContents ($ uri , 'application/json ' , '[] ' , $ _meta )];
107109 }
108110
109111 $ allAreResourceContents = true ;
@@ -151,14 +153,15 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
151153 if (\is_string ($ readResult )) {
152154 $ mimeType = $ mimeType ?? $ this ->guessMimeTypeFromString ($ readResult );
153155
154- return [new TextResourceContents ($ uri , $ mimeType , $ readResult )];
156+ return [new TextResourceContents ($ uri , $ mimeType , $ readResult, $ _meta )];
155157 }
156158
157159 if (\is_resource ($ readResult ) && 'stream ' === get_resource_type ($ readResult )) {
158160 $ result = BlobResourceContents::fromStream (
159161 $ uri ,
160162 $ readResult ,
161- $ mimeType ?? 'application/octet-stream '
163+ $ mimeType ?? 'application/octet-stream ' ,
164+ $ _meta
162165 );
163166
164167 @fclose ($ readResult );
@@ -169,21 +172,21 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
169172 if (\is_array ($ readResult ) && isset ($ readResult ['blob ' ]) && \is_string ($ readResult ['blob ' ])) {
170173 $ mimeType = $ readResult ['mimeType ' ] ?? $ mimeType ?? 'application/octet-stream ' ;
171174
172- return [new BlobResourceContents ($ uri , $ mimeType , $ readResult ['blob ' ])];
175+ return [new BlobResourceContents ($ uri , $ mimeType , $ readResult ['blob ' ], $ _meta )];
173176 }
174177
175178 if (\is_array ($ readResult ) && isset ($ readResult ['text ' ]) && \is_string ($ readResult ['text ' ])) {
176179 $ mimeType = $ readResult ['mimeType ' ] ?? $ mimeType ?? 'text/plain ' ;
177180
178- return [new TextResourceContents ($ uri , $ mimeType , $ readResult ['text ' ])];
181+ return [new TextResourceContents ($ uri , $ mimeType , $ readResult ['text ' ], $ _meta )];
179182 }
180183
181184 if ($ readResult instanceof \SplFileInfo && $ readResult ->isFile () && $ readResult ->isReadable ()) {
182185 if ($ mimeType && str_contains (strtolower ($ mimeType ), 'text ' )) {
183- return [new TextResourceContents ($ uri , $ mimeType , file_get_contents ($ readResult ->getPathname ()))];
186+ return [new TextResourceContents ($ uri , $ mimeType , file_get_contents ($ readResult ->getPathname ()), $ _meta )];
184187 }
185188
186- return [BlobResourceContents::fromSplFileInfo ($ uri , $ readResult , $ mimeType )];
189+ return [BlobResourceContents::fromSplFileInfo ($ uri , $ readResult , $ mimeType, $ _meta )];
187190 }
188191
189192 if (\is_array ($ readResult )) {
@@ -192,7 +195,7 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
192195 try {
193196 $ jsonString = json_encode ($ readResult , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT );
194197
195- return [new TextResourceContents ($ uri , $ mimeType , $ jsonString )];
198+ return [new TextResourceContents ($ uri , $ mimeType , $ jsonString, $ _meta )];
196199 } catch (\JsonException $ e ) {
197200 throw new RuntimeException ("Failed to encode array as JSON for URI ' {$ uri }': {$ e ->getMessage ()}" );
198201 }
@@ -202,7 +205,7 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
202205 $ jsonString = json_encode ($ readResult , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT );
203206 $ mimeType = $ mimeType ?? 'application/json ' ;
204207
205- return [new TextResourceContents ($ uri , $ mimeType , $ jsonString )];
208+ return [new TextResourceContents ($ uri , $ mimeType , $ jsonString, $ _meta )];
206209 } catch (\JsonException $ e ) {
207210 throw new RuntimeException ("Failed to encode array as JSON for URI ' {$ uri }': {$ e ->getMessage ()}" );
208211 }
0 commit comments