feat(macros): auto-generate get_info and default router#785
Open
feat(macros): auto-generate get_info and default router#785
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withSelf::tool_router(), and aget_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:
How Has This Been Tested?
New integration tests cover the field-free server pattern, custom
name/version/instructionsattributes, manualget_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
Checklist
Additional context