feat(macros): auto-generate get_info and default router (#785)
* feat(macros): auto-generate get_info and default router * docs: simplify examples and docs with new defaults * feat(macros): add tool_router(server_handler) to elide separate #[tool_handler] impl * docs: add Tools section to README and simplify calculator examples with server_handler
This commit is contained in:
parent
5891b45162
commit
be321a4abe
1 changed files with 742 additions and 233 deletions
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
use rmcp::{
|
||||
ServerHandler,
|
||||
handler::server::{
|
||||
router::tool::ToolRouter,
|
||||
wrapper::{Json, Parameters},
|
||||
},
|
||||
model::{ServerCapabilities, ServerInfo},
|
||||
handler::server::wrapper::{Json, Parameters},
|
||||
schemars, tool, tool_handler, tool_router,
|
||||
};
|
||||
|
||||
|
|
@ -26,17 +22,7 @@ pub struct SubRequest {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Calculator {
|
||||
tool_router: ToolRouter<Self>,
|
||||
}
|
||||
|
||||
impl Calculator {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
tool_router: Self::tool_router(),
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct Calculator;
|
||||
|
||||
#[tool_router]
|
||||
impl Calculator {
|
||||
|
|
@ -50,10 +36,5 @@ impl Calculator {
|
|||
Json(a - b)
|
||||
}
|
||||
}
|
||||
#[tool_handler]
|
||||
impl ServerHandler for Calculator {
|
||||
fn get_info(&self) -> ServerInfo {
|
||||
ServerInfo::new(ServerCapabilities::builder().enable_tools().build())
|
||||
.with_instructions("A simple calculator")
|
||||
}
|
||||
}
|
||||
#[tool_handler(instructions = "A simple calculator")]
|
||||
impl ServerHandler for Calculator {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue