You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update MCP docs to add outputSchema and struturedContent (#10932)
* Update MCP docs to add outputSchema and struturedCOntent
* Update MCP docs to replace JsonSchema with Contracts\JsonSchema
* formatting
---------
Co-authored-by: Taylor Otwell <taylor@laravel.com>
@@ -290,14 +291,14 @@ class CurrentWeatherTool extends Tool
290
291
<aname="tool-input-schemas"></a>
291
292
### Tool Input Schemas
292
293
293
-
Tools can define input schemas to specify what arguments they accept from AI clients. Use Laravel's `Illuminate\JsonSchema\JsonSchema` builder to define your tool's input requirements:
294
+
Tools can define input schemas to specify what arguments they accept from AI clients. Use Laravel's `Illuminate\Contracts\JsonSchema\JsonSchema` builder to define your tool's input requirements:
294
295
295
296
```php
296
297
<?php
297
298
298
299
namespace App\Mcp\Tools;
299
300
300
-
use Illuminate\JsonSchema\JsonSchema;
301
+
use Illuminate\Contracts\JsonSchema\JsonSchema;
301
302
use Laravel\Mcp\Server\Tool;
302
303
303
304
class CurrentWeatherTool extends Tool
@@ -323,6 +324,45 @@ class CurrentWeatherTool extends Tool
323
324
}
324
325
```
325
326
327
+
<aname="tool-output-schemas"></a>
328
+
### Tool Output Schemas
329
+
330
+
Tools can define [output schemas](https://modelcontextprotocol.io/specification/2025-06-18/server/tools#output-schema) to specify the structure of their responses. This enables better integration with AI clients that need parseable tool results. Use the `outputSchema` method to define your tool's output structure:
331
+
332
+
```php
333
+
<?php
334
+
335
+
namespace App\Mcp\Tools;
336
+
337
+
use Illuminate\Contracts\JsonSchema\JsonSchema;
338
+
use Laravel\Mcp\Server\Tool;
339
+
340
+
class CurrentWeatherTool extends Tool
341
+
{
342
+
/**
343
+
* Get the tool's output schema.
344
+
*
345
+
* @return array<string,JsonSchema>
346
+
*/
347
+
public function outputSchema(JsonSchema $schema): array
348
+
{
349
+
return [
350
+
'temperature' => $schema->number()
351
+
->description('Temperature in Celsius')
352
+
->required(),
353
+
354
+
'conditions' => $schema->string()
355
+
->description('Weather conditions')
356
+
->required(),
357
+
358
+
'humidity' => $schema->integer()
359
+
->description('Humidity percentage')
360
+
->required(),
361
+
];
362
+
}
363
+
}
364
+
```
365
+
326
366
<aname="validating-tool-arguments"></a>
327
367
### Validating Tool Arguments
328
368
@@ -533,6 +573,30 @@ public function handle(Request $request): array
533
573
}
534
574
```
535
575
576
+
<aname="structured-responses"></a>
577
+
#### Structured Responses
578
+
579
+
Tools can return [structured content](https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content) using the `structured` method. This provides parseable data for AI clients while maintaining backward compatibility with a JSON-encoded text representation:
580
+
581
+
```php
582
+
return Response::structured([
583
+
'temperature' => 22.5,
584
+
'conditions' => 'Partly cloudy',
585
+
'humidity' => 65,
586
+
]);
587
+
```
588
+
589
+
If you need to provide custom text alongside structured content, use the `withStructuredContent` method on the response factory:
0 commit comments