Skip to content

Commit 831cf00

Browse files
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>
1 parent c120a0c commit 831cf00

File tree

1 file changed

+68
-4
lines changed

1 file changed

+68
-4
lines changed

mcp.md

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Tools](#tools)
1111
- [Creating Tools](#creating-tools)
1212
- [Tool Input Schemas](#tool-input-schemas)
13+
- [Tool Output Schemas](#tool-output-schemas)
1314
- [Validating Tool Arguments](#validating-tool-arguments)
1415
- [Tool Dependency Injection](#tool-dependency-injection)
1516
- [Tool Annotations](#tool-annotations)
@@ -176,7 +177,7 @@ Tools enable your server to expose functionality that AI clients can call. They
176177

177178
namespace App\Mcp\Tools;
178179

179-
use Illuminate\JsonSchema\JsonSchema;
180+
use Illuminate\Contracts\JsonSchema\JsonSchema;
180181
use Laravel\Mcp\Request;
181182
use Laravel\Mcp\Response;
182183
use Laravel\Mcp\Server\Tool;
@@ -203,7 +204,7 @@ class CurrentWeatherTool extends Tool
203204
/**
204205
* Get the tool's input schema.
205206
*
206-
* @return array<string, \Illuminate\JsonSchema\JsonSchema>
207+
* @return array<string, \Illuminate\Contracts\JsonSchema\JsonSchema>
207208
*/
208209
public function schema(JsonSchema $schema): array
209210
{
@@ -290,14 +291,14 @@ class CurrentWeatherTool extends Tool
290291
<a name="tool-input-schemas"></a>
291292
### Tool Input Schemas
292293

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:
294295

295296
```php
296297
<?php
297298

298299
namespace App\Mcp\Tools;
299300

300-
use Illuminate\JsonSchema\JsonSchema;
301+
use Illuminate\Contracts\JsonSchema\JsonSchema;
301302
use Laravel\Mcp\Server\Tool;
302303

303304
class CurrentWeatherTool extends Tool
@@ -323,6 +324,45 @@ class CurrentWeatherTool extends Tool
323324
}
324325
```
325326

327+
<a name="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+
326366
<a name="validating-tool-arguments"></a>
327367
### Validating Tool Arguments
328368

@@ -533,6 +573,30 @@ public function handle(Request $request): array
533573
}
534574
```
535575

576+
<a name="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:
590+
591+
```php
592+
return Response::make(
593+
Response::text('Weather is 22.5°C and sunny')
594+
)->withStructuredContent([
595+
'temperature' => 22.5,
596+
'conditions' => 'Sunny',
597+
]);
598+
```
599+
536600
<a name="streaming-responses"></a>
537601
#### Streaming Responses
538602

0 commit comments

Comments
 (0)