feat(tool): add _meta to tool definitions (#534)

This commit is contained in:
Dylan Anthony 2025-11-10 18:27:52 -07:00 committed by GitHub
parent 941300acbe
commit 03040f8b0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 1 deletions

View file

@ -77,6 +77,8 @@ pub struct ToolAttribute {
pub annotations: Option<ToolAnnotationsAttribute>,
/// Optional icons for the tool
pub icons: Option<Expr>,
/// Optional metadata for the tool
pub meta: Option<Expr>,
}
pub struct ResolvedToolAttribute {
@ -87,6 +89,7 @@ pub struct ResolvedToolAttribute {
pub output_schema: Option<Expr>,
pub annotations: Expr,
pub icons: Option<Expr>,
pub meta: Option<Expr>,
}
impl ResolvedToolAttribute {
@ -99,6 +102,7 @@ impl ResolvedToolAttribute {
output_schema,
annotations,
icons,
meta,
} = self;
let description = if let Some(description) = description {
quote! { Some(#description.into()) }
@ -120,6 +124,11 @@ impl ResolvedToolAttribute {
} else {
quote! { None }
};
let meta = if let Some(meta) = meta {
quote! { Some(#meta) }
} else {
quote! { None }
};
let doc_comment = format!("Generated tool metadata function for {name}");
let doc_attr: syn::Attribute = parse_quote!(#[doc = #doc_comment]);
let tokens = quote! {
@ -133,6 +142,7 @@ impl ResolvedToolAttribute {
output_schema: #output_schema,
annotations: #annotations,
icons: #icons,
meta: #meta,
}
}
};
@ -264,6 +274,7 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
annotations: annotations_expr,
title: attribute.title,
icons: attribute.icons,
meta: attribute.meta,
};
let tool_attr_fn = resolved_tool_attr.into_fn(tool_attr_fn_ident)?;
// modify the the input function

View file

@ -6,7 +6,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use super::{Icon, JsonObject};
use super::{Icon, JsonObject, Meta};
/// A tool that can be used by a model.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -32,6 +32,9 @@ pub struct Tool {
/// Optional list of icons for the tool
#[serde(skip_serializing_if = "Option::is_none")]
pub icons: Option<Vec<Icon>>,
/// Optional additional metadata for this tool
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
pub meta: Option<Meta>,
}
/// Additional properties describing a Tool to clients.
@ -150,6 +153,7 @@ impl Tool {
output_schema: None,
annotations: None,
icons: None,
meta: None,
}
}

View file

@ -2292,6 +2292,14 @@
"description": "A tool that can be used by a model.",
"type": "object",
"properties": {
"_meta": {
"description": "Optional additional metadata for this tool",
"type": [
"object",
"null"
],
"additionalProperties": true
},
"annotations": {
"description": "Optional additional tool information.",
"anyOf": [

View file

@ -2292,6 +2292,14 @@
"description": "A tool that can be used by a model.",
"type": "object",
"properties": {
"_meta": {
"description": "Optional additional metadata for this tool",
"type": [
"object",
"null"
],
"additionalProperties": true
},
"annotations": {
"description": "Optional additional tool information.",
"anyOf": [

View file

@ -123,6 +123,7 @@ impl ServerHandler for SamplingDemoServer {
output_schema: None,
annotations: None,
icons: None,
meta: None,
}],
next_cursor: None,
})