Inline tool schemas
This commit is contained in:
parent
f028ca4d1a
commit
738296345e
1 changed files with 7 additions and 3 deletions
|
@ -83,14 +83,18 @@ impl McpServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_tool<T: McpServerTool + Clone + 'static>(&mut self, tool: T) {
|
pub fn add_tool<T: McpServerTool + Clone + 'static>(&mut self, tool: T) {
|
||||||
let output_schema = schemars::schema_for!(T::Output);
|
let mut settings = schemars::generate::SchemaSettings::draft07();
|
||||||
let unit_schema = schemars::schema_for!(());
|
settings.inline_subschemas = true;
|
||||||
|
let mut generator = settings.into_generator();
|
||||||
|
|
||||||
|
let output_schema = generator.root_schema_for::<T::Output>();
|
||||||
|
let unit_schema = generator.root_schema_for::<T::Output>();
|
||||||
|
|
||||||
let registered_tool = RegisteredTool {
|
let registered_tool = RegisteredTool {
|
||||||
tool: Tool {
|
tool: Tool {
|
||||||
name: T::NAME.into(),
|
name: T::NAME.into(),
|
||||||
description: Some(tool.description().into()),
|
description: Some(tool.description().into()),
|
||||||
input_schema: schemars::schema_for!(T::Input).into(),
|
input_schema: generator.root_schema_for::<T::Input>().into(),
|
||||||
output_schema: if output_schema == unit_schema {
|
output_schema: if output_schema == unit_schema {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue