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
<Warning>For trust & safety and security, clients **MUST** consider
@@ -235,6 +236,76 @@ or data, behind a URI that can be subscribed to or fetched again by the client l
235
236
}
236
237
```
237
238
239
+
### Output Schema
240
+
241
+
The optional `outputSchema` property provides a JSON Schema that describes the expected structure of the tool's output. This schema applies to the `text` property of the TextContent object returned by the tool.
242
+
243
+
When a tool specifies an `outputSchema`:
244
+
245
+
1. Clients **SHOULD** validate that the tool's result:
246
+
- Contains exactly one content item
247
+
- This item is a `TextContent` object
248
+
- The `text` property of this object validates against the schema
249
+
250
+
2. Servers **SHOULD**:
251
+
- Provide responses that conform to their declared schema
252
+
- Use proper JSON or structured formats in their responses when the schema specifies structured data
253
+
254
+
Example tool with output schema:
255
+
256
+
```json
257
+
{
258
+
"name": "search_database",
259
+
"description": "Search a database for records",
260
+
"inputSchema": {
261
+
"type": "object",
262
+
"properties": {
263
+
"query": {
264
+
"type": "string",
265
+
"description": "Search query"
266
+
}
267
+
},
268
+
"required": ["query"]
269
+
},
270
+
"outputSchema": {
271
+
"type": "array",
272
+
"items": {
273
+
"type": "object",
274
+
"properties": {
275
+
"id": { "type": "string" },
276
+
"title": { "type": "string" },
277
+
"url": { "type": "string" }
278
+
},
279
+
"required": ["id", "title"]
280
+
}
281
+
}
282
+
}
283
+
```
284
+
285
+
Example valid response for this tool:
286
+
287
+
```json
288
+
{
289
+
"jsonrpc": "2.0",
290
+
"id": 5,
291
+
"result": {
292
+
"content": [
293
+
{
294
+
"type": "text",
295
+
"text": "[{\"id\":\"doc-1\",\"title\":\"Introduction to MCP\",\"url\":\"https://example.com/docs/1\"},{\"id\":\"doc-2\",\"title\":\"Tool Usage Guide\",\"url\":\"https://example.com/docs/2\"}]"
296
+
}
297
+
]
298
+
}
299
+
}
300
+
```
301
+
302
+
The `outputSchema` helps clients and LLMs understand and properly handle tool outputs by:
303
+
304
+
- Enabling schema validation of responses
305
+
- Providing type information for better integration with programming languages
306
+
- Guiding LLMs to properly parse and utilize the returned data
307
+
- Supporting better documentation and developer experience
Copy file name to clipboardExpand all lines: schema/draft/schema.json
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2049,6 +2049,12 @@
2049
2049
"name": {
2050
2050
"description": "The name of the tool.",
2051
2051
"type": "string"
2052
+
},
2053
+
"outputSchema": {
2054
+
"additionalProperties": true,
2055
+
"description": "A JSON Schema object defining the structure of the tool's output.\n\nIf set, a client SHOULD validate a CallToolResult for this Tool as follows:\n1. check that the length of the result's `content` property == 1\n2. check that this single item is a `TextContent` object\n3. validate this object's `text` property against this schema.\n\nIn other words, for a CallToolResult to be valid with respect to this schema,\nit must first satisfy the precondition that its payload be a single TextContent \nobject.",
0 commit comments