-
Notifications
You must be signed in to change notification settings - Fork 271
Add support for Tool.outputSchema
and CallToolResult.structuredContent
#316
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
JMLX42
wants to merge
25
commits into
modelcontextprotocol:main
Choose a base branch
from
lx-industries:feature/output-schema
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
25 commits
Select commit
Hold shift + click to select a range
c2f65cc
feat: add output_schema field to Tool struct
JMLX42 5d24acc
feat: add structured_content field to CallToolResult
JMLX42 efdb55f
feat: implement validation for mutually exclusive content/structuredC…
JMLX42 c3a9ba7
feat: add output_schema support to #[tool] macro
JMLX42 6cad6c5
feat: implement IntoCallToolResult for structured content
JMLX42 366d0af
fix: update simple-chat-client example for optional content field
JMLX42 b16fd38
fix: update examples and tests for optional content field
JMLX42 d82056f
feat: implement basic schema validation in conversion logic
JMLX42 b174b63
feat: add structured output support for tools
JMLX42 cb28342
fix: correct structured output doctest to use Parameters wrapper
JMLX42 1b03666
feat: replace Structured<T> with Json<T> for structured output
JMLX42 3ed064d
feat: add output_schema() method to IntoCallToolResult trait
JMLX42 70bf2b1
feat: update macro to detect Json<T> wrapper for output schemas
JMLX42 43a72da
feat: add builder methods to Tool struct for setting schemas
JMLX42 4001d65
fix: address clippy warnings
JMLX42 cff51c4
style: apply cargo fmt
JMLX42 33b4d59
chore: fix formatting
JMLX42 1274857
chore: fix rustdoc redundant link warning
JMLX42 a1ef39e
refactor: validate_against_schema
JMLX42 f752f66
Merge branch 'modelcontextprotocol:main' into feature/output-schema
JMLX42 767d3ae
feat: enforce structured_content usage when output_schema is defined
JMLX42 cf52be9
chore: remove TODO.md
JMLX42 43f08bf
refactor: simplify output schema extraction logic in tool macro
JMLX42 5109fcb
chore: run cargo fmt
JMLX42 906812e
fix: enforce structured_content usage when output_schema is defined
JMLX42 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,28 +1,22 @@ | ||
use serde::Serialize; | ||
use std::borrow::Cow; | ||
|
||
use crate::model::IntoContents; | ||
use schemars::JsonSchema; | ||
|
||
/// Json wrapper | ||
/// Json wrapper for structured output | ||
/// | ||
/// This is used to tell the SDK to serialize the inner value into json | ||
/// When used with tools, this wrapper indicates that the value should be | ||
/// serialized as structured JSON content with an associated schema. | ||
/// The framework will place the JSON in the `structured_content` field | ||
/// of the tool result rather than the regular `content` field. | ||
pub struct Json<T>(pub T); | ||
|
||
impl<T> IntoContents for Json<T> | ||
where | ||
T: Serialize, | ||
{ | ||
fn into_contents(self) -> Vec<crate::model::Content> { | ||
let result = crate::model::Content::json(self.0); | ||
debug_assert!( | ||
result.is_ok(), | ||
"Json wrapped content should be able to serialized into json" | ||
); | ||
match result { | ||
Ok(content) => vec![content], | ||
Err(e) => { | ||
tracing::error!("failed to convert json content: {e}"); | ||
vec![] | ||
} | ||
} | ||
// Implement JsonSchema for Json<T> to delegate to T's schema | ||
impl<T: JsonSchema> JsonSchema for Json<T> { | ||
fn schema_name() -> Cow<'static, str> { | ||
T::schema_name() | ||
} | ||
|
||
fn json_schema(generator: &mut schemars::SchemaGenerator) -> schemars::Schema { | ||
T::json_schema(generator) | ||
} | ||
} |
Oops, something went wrong.
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.
Is the complexity of the circle here a bit high?
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.
Simplify this please.
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.
@4t145 done in 70bf2b1
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.
It seems that there are no modifications here
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.
@jokemanfire my bad! Sorry.
Done in 43f08bf