fix(clippy): add doc comment for generated tool attr fn (#439)
This change makes the `tool` macro's output safe for the `missing_docs` lint, by emitting a doc comment for the generated `[tool]_tool_attr` function. This doc comment is emitted regardless of whether the tool function is public, for simplicity. We are building an MCP server using `rmcp` and discovered that the current crate was not compatible with the `#![deny(missing_docs)]` lint which we use everywhere. Tested by modifying the `test_tool_macros.rs` test to use `#![deny(missing_docs)]` and adding doc comments to all pub fns and structs in that file. None. Fixes #438. Co-authored-by: RobJellinghaus <rjellinghaus@live.com>
This commit is contained in:
parent
4ee2add899
commit
ddef4ce529
1 changed files with 26 additions and 7 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use darling::{FromMeta, ast::NestedMeta};
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{ToTokens, format_ident, quote};
|
||||
use syn::{Expr, Ident, ImplItemFn, ReturnType};
|
||||
use syn::{Expr, Ident, ImplItemFn, ReturnType, parse_quote};
|
||||
|
||||
use crate::common::{extract_doc_line, none_expr};
|
||||
|
||||
|
|
@ -120,7 +120,10 @@ impl ResolvedToolAttribute {
|
|||
} 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! {
|
||||
#doc_attr
|
||||
pub fn #fn_ident() -> rmcp::model::Tool {
|
||||
rmcp::model::Tool {
|
||||
name: #name.into(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue