@@ -68,9 +68,11 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
6868 return [$ readResult ->resource ];
6969 }
7070
71+ $ meta = $ this ->schema ->meta ;
72+
7173 if (\is_array ($ readResult )) {
7274 if (empty ($ readResult )) {
73- return [new TextResourceContents ($ uri , 'application/json ' , '[] ' )];
75+ return [new TextResourceContents ($ uri , 'application/json ' , '[] ' , $ meta )];
7476 }
7577
7678 $ allAreResourceContents = true ;
@@ -118,14 +120,15 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
118120 if (\is_string ($ readResult )) {
119121 $ mimeType = $ mimeType ?? $ this ->guessMimeTypeFromString ($ readResult );
120122
121- return [new TextResourceContents ($ uri , $ mimeType , $ readResult )];
123+ return [new TextResourceContents ($ uri , $ mimeType , $ readResult, $ meta )];
122124 }
123125
124126 if (\is_resource ($ readResult ) && 'stream ' === get_resource_type ($ readResult )) {
125127 $ result = BlobResourceContents::fromStream (
126128 $ uri ,
127129 $ readResult ,
128- $ mimeType ?? 'application/octet-stream '
130+ $ mimeType ?? 'application/octet-stream ' ,
131+ $ meta
129132 );
130133
131134 @fclose ($ readResult );
@@ -136,21 +139,21 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
136139 if (\is_array ($ readResult ) && isset ($ readResult ['blob ' ]) && \is_string ($ readResult ['blob ' ])) {
137140 $ mimeType = $ readResult ['mimeType ' ] ?? $ mimeType ?? 'application/octet-stream ' ;
138141
139- return [new BlobResourceContents ($ uri , $ mimeType , $ readResult ['blob ' ])];
142+ return [new BlobResourceContents ($ uri , $ mimeType , $ readResult ['blob ' ], $ meta )];
140143 }
141144
142145 if (\is_array ($ readResult ) && isset ($ readResult ['text ' ]) && \is_string ($ readResult ['text ' ])) {
143146 $ mimeType = $ readResult ['mimeType ' ] ?? $ mimeType ?? 'text/plain ' ;
144147
145- return [new TextResourceContents ($ uri , $ mimeType , $ readResult ['text ' ])];
148+ return [new TextResourceContents ($ uri , $ mimeType , $ readResult ['text ' ], $ meta )];
146149 }
147150
148151 if ($ readResult instanceof \SplFileInfo && $ readResult ->isFile () && $ readResult ->isReadable ()) {
149152 if ($ mimeType && str_contains (strtolower ($ mimeType ), 'text ' )) {
150- return [new TextResourceContents ($ uri , $ mimeType , file_get_contents ($ readResult ->getPathname ()))];
153+ return [new TextResourceContents ($ uri , $ mimeType , file_get_contents ($ readResult ->getPathname ()), $ meta )];
151154 }
152155
153- return [BlobResourceContents::fromSplFileInfo ($ uri , $ readResult , $ mimeType )];
156+ return [BlobResourceContents::fromSplFileInfo ($ uri , $ readResult , $ mimeType, $ meta )];
154157 }
155158
156159 if (\is_array ($ readResult )) {
@@ -159,7 +162,7 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
159162 try {
160163 $ jsonString = json_encode ($ readResult , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT );
161164
162- return [new TextResourceContents ($ uri , $ mimeType , $ jsonString )];
165+ return [new TextResourceContents ($ uri , $ mimeType , $ jsonString, $ meta )];
163166 } catch (\JsonException $ e ) {
164167 throw new RuntimeException (\sprintf ('Failed to encode array as JSON for URI "%s": %s ' , $ uri , $ e ->getMessage ()));
165168 }
@@ -169,7 +172,7 @@ public function formatResult(mixed $readResult, string $uri, ?string $mimeType =
169172 $ jsonString = json_encode ($ readResult , \JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT );
170173 $ mimeType = $ mimeType ?? 'application/json ' ;
171174
172- return [new TextResourceContents ($ uri , $ mimeType , $ jsonString )];
175+ return [new TextResourceContents ($ uri , $ mimeType , $ jsonString, $ meta )];
173176 } catch (\JsonException $ e ) {
174177 throw new RuntimeException (\sprintf ('Failed to encode array as JSON for URI "%s": %s ' , $ uri , $ e ->getMessage ()));
175178 }
0 commit comments