refactor: refactor tool macros and router implementation (#261)

* refactor: refactor tool macros and router implementation

- Updated the `#[tool(tool_box)]` macro to `#[tool_router]` across various modules for consistency.
- Enhanced the `Calculator`, `Counter`, and `GenericService` structs to utilize `ToolRouter` for handling tool calls.
- Introduced `Parameters` struct for better parameter handling in tool functions.
- Added new methods for listing tools and calling tools in server handlers.
- Improved test cases to reflect changes in tool routing and parameter handling.
- Updated documentation and examples to align with the new router structure.

* fix: fix fmt and build error

* fix: fix test failure

* docs: documents for macros, fix ci

* fix: fix ci

* fix: fix wrongly replaced documents

* fix: remove useless file

* fix: change the parameter format for tool_router

* fix: update extract_doc_line to handle existing documentation and clean up unused code in server handler

* doc: update document for macro and examples

* doc: update readme and add contribute guide

* fix: fix type
This commit is contained in:
4t145 2025-06-24 04:01:22 +08:00 • committed by GitHub
commit 1f7f4d3055
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1498 additions and 1147 deletions

13
docs/CONTRIBUTE.MD Normal file
View file

@ -0,0 +1,13 @@
# Discuss first
If you have a idea, make sure it is discussed before you make a PR.
# Fmt And Clippy
You can use [just](https://github.com/casey/just) to help you fix your commit rapidly:
```shell
just fix
```
# How Can I Rewrite My Commit Message?
You can `git reset --soft upstream/main` and `git commit --forge`, this will merge your changes into one commit.
Or you also can use git rebase. But we will still merge them into one commit when it is merged.

View file

@ -97,7 +97,7 @@ pub struct SumRequest {
pub struct Calculator;
// create a static toolbox to store the tool attributes
#[tool(tool_box)]
#[tool_router]
impl Calculator {
// async function
#[tool(description = "Calculate the sum of two numbers")]
@ -122,7 +122,7 @@ impl Calculator {
}
// impl call_tool and list_tool by querying static toolbox
#[tool(tool_box)]
#[tool_handler]
impl ServerHandler for Calculator {
fn get_info(&self) -> ServerInfo {
ServerInfo {