Skip to content

Commit 706eb35

Browse files
Add documentation for MCP meta (#10915)
* Add Docs for MCP meta * Update anchor link in MCP meta-section * formatting * formatting * Update mcp.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 9c7dfad commit 706eb35

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

mcp.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [Resource Dependency Injection](#resource-dependency-injection)
3030
- [Conditional Resource Registration](#conditional-resource-registration)
3131
- [Resource Responses](#resource-responses)
32+
- [Metadata](#metadata)
3233
- [Authentication](#authentication)
3334
- [OAuth 2.1](#oauth)
3435
- [Sanctum](#sanctum)
@@ -1116,6 +1117,63 @@ To indicate an error occurred during resource retrieval, use the `error()` metho
11161117
return Response::error('Unable to fetch weather data for the specified location.');
11171118
```
11181119

1120+
<a name="metadata"></a>
1121+
## Metadata
1122+
1123+
Laravel MCP also supports the `_meta` field as defined in the [MCP specification](https://modelcontextprotocol.io/specification/2025-06-18/basic#meta), which is required by certain MCP clients or integrations. Metadata can be applied to all MCP primitives, including tools, resources, and prompts, as well as their responses.
1124+
1125+
You can attach metadata to individual response content using the `withMeta` method:
1126+
1127+
```php
1128+
use Laravel\Mcp\Request;
1129+
use Laravel\Mcp\Response;
1130+
1131+
/**
1132+
* Handle the tool request.
1133+
*/
1134+
public function handle(Request $request): Response
1135+
{
1136+
return Response::text('The weather is sunny.')
1137+
->withMeta(['source' => 'weather-api', 'cached' => true]);
1138+
}
1139+
```
1140+
1141+
For result-level metadata that applies to the entire response envelope, wrap your responses with `Response::make` and call `withMeta` on the returned response factory instance:
1142+
1143+
```php
1144+
use Laravel\Mcp\Request;
1145+
use Laravel\Mcp\Response;
1146+
use Laravel\Mcp\ResponseFactory;
1147+
1148+
/**
1149+
* Handle the tool request.
1150+
*/
1151+
public function handle(Request $request): ResponseFactory
1152+
{
1153+
return Response::make(
1154+
Response::text('The weather is sunny.')
1155+
)->withMeta(['request_id' => '12345']);
1156+
}
1157+
```
1158+
1159+
To attach metadata to a tool, resource, or prompt itself, define a `$meta` property on the class:
1160+
1161+
```php
1162+
use Laravel\Mcp\Server\Tool;
1163+
1164+
class CurrentWeatherTool extends Tool
1165+
{
1166+
protected string $description = 'Fetches the current weather forecast.';
1167+
1168+
protected ?array $meta = [
1169+
'version' => '2.0',
1170+
'author' => 'Weather Team',
1171+
];
1172+
1173+
// ...
1174+
}
1175+
```
1176+
11191177
<a name="authentication"></a>
11201178
## Authentication
11211179

0 commit comments

Comments
 (0)