Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/rmcp-macros/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -99,6 +102,7 @@ impl ResolvedToolAttribute {
output_schema,
annotations,
icons,
meta,
} = self;
let description = if let Some(description) = description {
quote! { Some(#description.into()) }
Expand All @@ -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! {
Expand All @@ -133,6 +142,7 @@ impl ResolvedToolAttribute {
output_schema: #output_schema,
annotations: #annotations,
icons: #icons,
meta: #meta,
}
}
};
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion crates/rmcp/src/model/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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.
Expand Down Expand Up @@ -150,6 +153,7 @@ impl Tool {
output_schema: None,
annotations: None,
icons: None,
meta: None,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions examples/servers/src/sampling_stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl ServerHandler for SamplingDemoServer {
output_schema: None,
annotations: None,
icons: None,
meta: None,
}],
next_cursor: None,
})
Expand Down
Loading