Skip to content

Commit ef72f8a

Browse files
committed
Enforce parity between tool results and sampling messages
1 parent 6a4dc0f commit ef72f8a

File tree

3 files changed

+109
-39
lines changed

3 files changed

+109
-39
lines changed

docs/specification/draft/client/sampling.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,22 @@ Sampling messages can contain:
167167
}
168168
```
169169

170+
#### Embedded Resources
171+
172+
[Resources](/specification/draft/server/resources) **MAY** be embedded, to provide additional context
173+
or data, behind a URI that can be subscribed to or fetched again by the client later:
174+
175+
```json
176+
{
177+
"type": "resource",
178+
"resource": {
179+
"uri": "resource://example",
180+
"mimeType": "text/plain",
181+
"text": "Resource content"
182+
}
183+
}
184+
```
185+
170186
### Model Preferences
171187

172188
Model selection in MCP requires careful abstraction since servers and clients may use

schema/draft/schema.json

Lines changed: 46 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/draft/schema.ts

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -685,31 +685,66 @@ export interface ListToolsResult extends PaginatedResult {
685685

686686
/**
687687
* The server's response to a tool call.
688+
*
689+
* Any errors that originate from the tool SHOULD be reported inside the result
690+
* object, with `isError` set to true, _not_ as an MCP protocol-level error
691+
* response. Otherwise, the LLM would not be able to see that an error occurred
692+
* and self-correct.
693+
*
694+
* However, any errors in _finding_ the tool, an error indicating that the
695+
* server does not support tool calls, or any other exceptional conditions,
696+
* should be reported as an MCP error response.
697+
*/
698+
export type CallToolResult =
699+
| CallToolUnstructuredResult
700+
| CallToolStructuredResult;
701+
702+
/**
703+
* Tool result for tools that do not declare an outputSchema.
688704
*/
689-
export interface CallToolResult extends Result {
705+
export interface CallToolUnstructuredResult extends Result {
690706
/**
691-
* A list of content objects that represent the unstructured result of the tool call.
707+
* A list of content objects that represent the result of the tool call.
708+
*
709+
* If the Tool does not define an outputSchema, this field MUST be present in the result.
692710
*/
693711
content: ContentBlock[];
694712

695713
/**
696-
* An optional JSON object that represents the structured result of the tool call.
714+
* Structured output must not be provided in an unstructured tool result.
697715
*/
698-
structuredContent?: { [key: string]: unknown };
716+
structuredContent: never;
699717

700718
/**
701719
* Whether the tool call ended in an error.
702720
*
703721
* If not set, this is assumed to be false (the call was successful).
722+
*/
723+
isError?: boolean;
724+
}
725+
726+
/**
727+
* Tool result for tools that do declare an outputSchema.
728+
*/
729+
export interface CallToolStructuredResult extends Result {
730+
/**
731+
* An object containing structured tool output.
704732
*
705-
* Any errors that originate from the tool SHOULD be reported inside the result
706-
* object, with `isError` set to true, _not_ as an MCP protocol-level error
707-
* response. Otherwise, the LLM would not be able to see that an error occurred
708-
* and self-correct.
733+
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
734+
*/
735+
structuredContent: { [key: string]: unknown };
736+
737+
/**
738+
* If the Tool defines an outputSchema, this field MAY be present in the result.
739+
* Tools should use this field to provide compatibility with older clients that do not support structured content.
740+
* Clients that support structured content should ignore this field.
741+
*/
742+
content?: ContentBlock[];
743+
744+
/**
745+
* Whether the tool call ended in an error.
709746
*
710-
* However, any errors in _finding_ the tool, an error indicating that the
711-
* server does not support tool calls, or any other exceptional conditions,
712-
* should be reported as an MCP error response.
747+
* If not set, this is assumed to be false (the call was successful).
713748
*/
714749
isError?: boolean;
715750
}
@@ -933,7 +968,7 @@ export interface CreateMessageResult extends Result, SamplingMessage {
933968
*/
934969
export interface SamplingMessage {
935970
role: Role;
936-
content: TextContent | ImageContent | AudioContent;
971+
content: ContentBlock;
937972
}
938973

939974
/**

0 commit comments

Comments
 (0)