Skip to content

Commit 03040f8

Browse files
authored
feat(tool): add _meta to tool definitions (#534)
1 parent 941300a commit 03040f8

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

crates/rmcp-macros/src/tool.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ pub struct ToolAttribute {
7777
pub annotations: Option<ToolAnnotationsAttribute>,
7878
/// Optional icons for the tool
7979
pub icons: Option<Expr>,
80+
/// Optional metadata for the tool
81+
pub meta: Option<Expr>,
8082
}
8183

8284
pub struct ResolvedToolAttribute {
@@ -87,6 +89,7 @@ pub struct ResolvedToolAttribute {
8789
pub output_schema: Option<Expr>,
8890
pub annotations: Expr,
8991
pub icons: Option<Expr>,
92+
pub meta: Option<Expr>,
9093
}
9194

9295
impl ResolvedToolAttribute {
@@ -99,6 +102,7 @@ impl ResolvedToolAttribute {
99102
output_schema,
100103
annotations,
101104
icons,
105+
meta,
102106
} = self;
103107
let description = if let Some(description) = description {
104108
quote! { Some(#description.into()) }
@@ -120,6 +124,11 @@ impl ResolvedToolAttribute {
120124
} else {
121125
quote! { None }
122126
};
127+
let meta = if let Some(meta) = meta {
128+
quote! { Some(#meta) }
129+
} else {
130+
quote! { None }
131+
};
123132
let doc_comment = format!("Generated tool metadata function for {name}");
124133
let doc_attr: syn::Attribute = parse_quote!(#[doc = #doc_comment]);
125134
let tokens = quote! {
@@ -133,6 +142,7 @@ impl ResolvedToolAttribute {
133142
output_schema: #output_schema,
134143
annotations: #annotations,
135144
icons: #icons,
145+
meta: #meta,
136146
}
137147
}
138148
};
@@ -264,6 +274,7 @@ pub fn tool(attr: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
264274
annotations: annotations_expr,
265275
title: attribute.title,
266276
icons: attribute.icons,
277+
meta: attribute.meta,
267278
};
268279
let tool_attr_fn = resolved_tool_attr.into_fn(tool_attr_fn_ident)?;
269280
// modify the the input function

crates/rmcp/src/model/tool.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
77
use serde_json::Value;
88

9-
use super::{Icon, JsonObject};
9+
use super::{Icon, JsonObject, Meta};
1010

1111
/// A tool that can be used by a model.
1212
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@@ -32,6 +32,9 @@ pub struct Tool {
3232
/// Optional list of icons for the tool
3333
#[serde(skip_serializing_if = "Option::is_none")]
3434
pub icons: Option<Vec<Icon>>,
35+
/// Optional additional metadata for this tool
36+
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
37+
pub meta: Option<Meta>,
3538
}
3639

3740
/// Additional properties describing a Tool to clients.
@@ -150,6 +153,7 @@ impl Tool {
150153
output_schema: None,
151154
annotations: None,
152155
icons: None,
156+
meta: None,
153157
}
154158
}
155159

crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,14 @@
22922292
"description": "A tool that can be used by a model.",
22932293
"type": "object",
22942294
"properties": {
2295+
"_meta": {
2296+
"description": "Optional additional metadata for this tool",
2297+
"type": [
2298+
"object",
2299+
"null"
2300+
],
2301+
"additionalProperties": true
2302+
},
22952303
"annotations": {
22962304
"description": "Optional additional tool information.",
22972305
"anyOf": [

crates/rmcp/tests/test_message_schema/server_json_rpc_message_schema_current.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,14 @@
22922292
"description": "A tool that can be used by a model.",
22932293
"type": "object",
22942294
"properties": {
2295+
"_meta": {
2296+
"description": "Optional additional metadata for this tool",
2297+
"type": [
2298+
"object",
2299+
"null"
2300+
],
2301+
"additionalProperties": true
2302+
},
22952303
"annotations": {
22962304
"description": "Optional additional tool information.",
22972305
"anyOf": [

examples/servers/src/sampling_stdio.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl ServerHandler for SamplingDemoServer {
123123
output_schema: None,
124124
annotations: None,
125125
icons: None,
126+
meta: None,
126127
}],
127128
next_cursor: None,
128129
})

0 commit comments

Comments
 (0)