Skip to content

Commit 9876ab9

Browse files
committed
add CallToolResult.structuredContent
1 parent 5c1949e commit 9876ab9

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

docs/specification/draft/server/tools.mdx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ A tool definition includes:
181181
- `name`: Unique identifier for the tool
182182
- `description`: Human-readable description of functionality
183183
- `inputSchema`: JSON Schema defining expected parameters
184-
- `outputSchema`: Optional JSON Schema defining the expected output structure
184+
- `outputSchema`: Optional JSON Schema defining expected output structure
185185
- `annotations`: optional properties describing tool behavior
186186

187187
<Warning>For trust & safety and security, clients **MUST** consider
@@ -238,18 +238,13 @@ or data, behind a URI that can be subscribed to or fetched again by the client l
238238

239239
### Output Schema
240240

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.
241+
The optional `outputSchema` property provides a JSON Schema that describes the expected structure of the `structuredContent` property of a CallToolResult.
242242

243243
When a tool specifies an `outputSchema`:
244244

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
245+
1. Clients **MUST** validate that the tool result contains a `structuredContent` field whose contents validate against the declared `outputSchema`.
249246

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
247+
2. Servers **MUST** provide tool results that conform to their declared `outputSchema`s.
253248

254249
Example tool with output schema:
255250

@@ -289,21 +284,19 @@ Example valid response for this tool:
289284
"jsonrpc": "2.0",
290285
"id": 5,
291286
"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-
]
287+
"structuredContent": {
288+
"type": "text",
289+
"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\"}]"
290+
}
298291
}
299292
}
300293
```
301294

302-
The `outputSchema` helps clients and LLMs understand and properly handle tool outputs by:
295+
The `outputSchema` helps clients and LLMs understand and properly handle structured tool outputs by:
303296

304-
- Enabling schema validation of responses
297+
- Enabling strict schema validation of responses
305298
- Providing type information for better integration with programming languages
306-
- Guiding LLMs to properly parse and utilize the returned data
299+
- Guiding clients and LLMs to properly parse and utilize the returned data
307300
- Supporting better documentation and developer experience
308301

309302
## Error Handling

schema/draft/schema.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"type": "object"
110110
},
111111
"content": {
112+
"description": "A list of content objects that represent the result of the tool call.",
112113
"items": {
113114
"anyOf": [
114115
{
@@ -130,11 +131,12 @@
130131
"isError": {
131132
"description": "Whether the tool call ended in an error.\n\nIf not set, this is assumed to be false (the call was successful).",
132133
"type": "boolean"
134+
},
135+
"structuredContent": {
136+
"description": "If the Tool defines an outputSchema, this field MUST contain a serialized JSON object that matches the schema.",
137+
"type": "string"
133138
}
134139
},
135-
"required": [
136-
"content"
137-
],
138140
"type": "object"
139141
},
140142
"CancelledNotification": {
@@ -2052,7 +2054,7 @@
20522054
},
20532055
"outputSchema": {
20542056
"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.",
2057+
"description": "A JSON Schema object defining the structure of the tool's output.\n\nIf set, a CallToolResult for this Tool MUST contain a structuredContent field whose contents validate against this schema.",
20562058
"properties": {},
20572059
"type": "object"
20582060
}

schema/draft/schema.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,19 @@ export interface ListToolsResult extends PaginatedResult {
696696
* should be reported as an MCP error response.
697697
*/
698698
export interface CallToolResult extends Result {
699-
content: (TextContent | ImageContent | AudioContent | EmbeddedResource)[];
699+
/**
700+
* A list of content objects that represent the result of the tool call.
701+
*
702+
* If the Tool does not define an outputSchema, this field MUST be present in the result.
703+
*/
704+
content?: (TextContent | ImageContent | AudioContent | EmbeddedResource)[];
705+
706+
/**
707+
* A string containing structured tool output.
708+
*
709+
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a serialized JSON object that matches the schema.
710+
*/
711+
structuredContent?: string;
700712

701713
/**
702714
* Whether the tool call ended in an error.
@@ -804,16 +816,10 @@ export interface Tool {
804816
};
805817

806818
/**
807-
* A JSON Schema object defining the structure of the tool's output.
808-
*
809-
* If set, a client SHOULD validate a CallToolResult for this Tool as follows:
810-
* 1. check that the length of the result's `content` property == 1
811-
* 2. check that this single item is a `TextContent` object
812-
* 3. validate this object's `text` property against this schema.
819+
* An optional JSON Schema object defining the structure of the tool's output.
813820
*
814-
* In other words, for a CallToolResult to be valid with respect to this schema,
815-
* it must first satisfy the precondition that its payload be a single TextContent
816-
* object.
821+
* If set, a CallToolResult for this Tool MUST contain a structuredContent field whose contents validate against this schema.
822+
* If not set, a CallToolResult for this Tool MUST contain a content field.
817823
*/
818824
outputSchema?: object;
819825

0 commit comments

Comments
 (0)