Skip to content

feat(macros): auto-generate get_info and default router#785

Open
DaleSeo wants to merge 2 commits intomainfrom
feat/reduce-server-boilerplate
Open

feat(macros): auto-generate get_info and default router#785
DaleSeo wants to merge 2 commits intomainfrom
feat/reduce-server-boilerplate

Conversation

@DaleSeo
Copy link
Copy Markdown
Member

@DaleSeo DaleSeo commented Apr 2, 2026

Motivation and Context

Close #711

Building a minimal tool-only MCP server now requires just three pieces of boilerplate beyond the actual tool logic. You need a tool_router: ToolRouter<Self> field in the struct, a constructor to initialize it with Self::tool_router(), and a get_info() override to enable the tool's capability since the trait default doesn't enable anything.

This PR updates the three handler macros to automatically generate get_info() with the correct capabilities if the user doesn't provide one. The default router for #[tool_handler] and #[prompt_handler] has changed from field access to calling the associated function. This change removes the need for a stored router field and its initialization boilerplate.

Now, you can write a minimal tool server like this:

struct TimeServer;

#[tool_router]
impl TimeServer {
    #[tool(description = "Get current time")]
    async fn get_time(&self) -> String { "12:00".into() }
}

#[tool_handler]
impl ServerHandler for TimeServer {}

How Has This Been Tested?

New integration tests cover the field-free server pattern, custom name/version/instructions attributes, manual get_info() preservation, and an end-to-end tool call over duplex transport.

Breaking Changes

No breaking changes to the public API. The auto-generated get_info() is only added when the user does not provide one, so existing implementations are unaffected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@DaleSeo DaleSeo self-assigned this Apr 2, 2026
@github-actions github-actions bot added T-test Testing related changes T-macros Macro changes labels Apr 2, 2026
@DaleSeo DaleSeo marked this pull request as ready for review April 2, 2026 00:56
@DaleSeo DaleSeo requested a review from a team as a code owner April 2, 2026 00:56
@github-actions github-actions bot added T-documentation Documentation improvements T-core Core library changes T-examples Example code changes T-handler Handler implementation changes labels Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-documentation Documentation improvements T-examples Example code changes T-handler Handler implementation changes T-macros Macro changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reduce boilerplate: derive/default ServerHandler for simple tool servers

1 participant