-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Type generics for CallToolResult - Require 'structuredContent' if 'outputSchema' defined. #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KKonstantinov
wants to merge
9
commits into
modelcontextprotocol:main
Choose a base branch
from
KKonstantinov:feature/tool-output-type-generics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
85510c2
type generics for CallToolResult - type require structuredContent ret…
KKonstantinov 7023152
Merge branch 'main' into feature/tool-output-type-generics
KKonstantinov 0094b67
Merge branch 'main' into feature/tool-output-type-generics
KKonstantinov eef9e7e
Merge branch 'main' into feature/tool-output-type-generics
KKonstantinov 6123acc
Merge branch 'main' into feature/tool-output-type-generics
KKonstantinov 58d6fbe
Merge branch 'main' into feature/tool-output-type-generics
ochafik 62abfee
Apply @cliffhall's suggestions to mcpServerOutputSchema.ts
ochafik 47f569e
Merge branch 'main' into feature/tool-output-type-generics
KKonstantinov dbd9945
call tool result reuse type, add tsdoc comments
KKonstantinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { z, ZodTypeAny } from "zod"; | ||
import { z, ZodRawShape, ZodTypeAny } from "zod"; | ||
import { AuthInfo } from "./server/auth/types.js"; | ||
|
||
export const LATEST_PROTOCOL_VERSION = "2025-06-18"; | ||
|
@@ -1000,25 +1000,14 @@ export const ListToolsResultSchema = PaginatedResultSchema.extend({ | |
tools: z.array(ToolSchema), | ||
}); | ||
|
||
/** | ||
* The server's response to a tool call. | ||
*/ | ||
export const CallToolResultSchema = ResultSchema.extend({ | ||
export const CallToolResultUnstructuredSchema = ResultSchema.extend({ | ||
/** | ||
* A list of content objects that represent the result of the tool call. | ||
* | ||
* If the Tool does not define an outputSchema, this field MUST be present in the result. | ||
* For backwards compatibility, this field is always present, but it may be empty. | ||
*/ | ||
content: z.array(ContentBlockSchema).default([]), | ||
|
||
/** | ||
* An object containing structured tool output. | ||
* | ||
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema. | ||
*/ | ||
structuredContent: z.object({}).passthrough().optional(), | ||
|
||
/** | ||
* Whether the tool call ended in an error. | ||
* | ||
|
@@ -1036,6 +1025,17 @@ export const CallToolResultSchema = ResultSchema.extend({ | |
isError: z.optional(z.boolean()), | ||
}); | ||
|
||
export const CallToolResultStructuredSchema = CallToolResultUnstructuredSchema.extend({ | ||
/** | ||
* An object containing structured tool output. | ||
* | ||
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema. | ||
*/ | ||
structuredContent: z.object({}).passthrough().optional(), | ||
}); | ||
|
||
export const CallToolResultSchema = z.union([CallToolResultUnstructuredSchema, CallToolResultStructuredSchema]); | ||
|
||
/** | ||
* CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07. | ||
*/ | ||
|
@@ -1645,6 +1645,10 @@ export type Tool = Infer<typeof ToolSchema>; | |
export type ListToolsRequest = Infer<typeof ListToolsRequestSchema>; | ||
export type ListToolsResult = Infer<typeof ListToolsResultSchema>; | ||
export type CallToolResult = Infer<typeof CallToolResultSchema>; | ||
export type CallToolResultUnstructured = Infer<typeof CallToolResultUnstructuredSchema>; | ||
export type CallToolResultStructured<OArgs extends ZodRawShape> = Infer<typeof CallToolResultStructuredSchema> & { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you keep the unabbreviated name OutputArgs used elsewhere for consistency? (although arguably these should be InputType, OutputType, the args concept is redundant w/ input and at odds w/ outputs) |
||
structuredContent: z.infer<z.ZodObject<OArgs>>; | ||
} | ||
export type CompatibilityCallToolResult = Infer<typeof CompatibilityCallToolResultSchema>; | ||
export type CallToolRequest = Infer<typeof CallToolRequestSchema>; | ||
export type ToolListChangedNotification = Infer<typeof ToolListChangedNotificationSchema>; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we'd never reach this never given the bounds on OutputArgs?