-
Notifications
You must be signed in to change notification settings - Fork 722
Added functionality for defining dynamic/runtime tools #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughA dynamic tools feature has been introduced to the MCPServer. This includes a new configuration struct, server option, and logic for listing and handling dynamic tools. The server now supports merging dynamic tools with static and session-specific tools, and dynamically validating and invoking tool calls when enabled. Changes
Possibly related issues
Suggested labels
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Accidently made a duplicate PR, previous PR is #401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
server/server.go (1)
300-324: Robust implementation with proper validation.The function correctly validates configuration and registers tool capabilities. The panic on invalid configuration is appropriate for a setup-time error.
Consider adding a doc comment to explain the purpose and usage of this option:
+// WithDynamicTools configures the server to support dynamic tool registration. +// When enabled, tools can be created and registered at runtime based on the provided functions. +// All three functions (listFunc, handlerFunc, validateFunc) must be non-nil when enabled is true. func WithDynamicTools(
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
server/server.go(5 hunks)
🧰 Additional context used
🧠 Learnings (1)
server/server.go (1)
Learnt from: floatingIce91
PR: mark3labs/mcp-go#401
File: server/server.go:1082-1092
Timestamp: 2025-06-23T11:10:42.940Z
Learning: In Go MCP server, ServerTool.Tool field is only used for tool listing and indexing, not for tool execution or middleware. During handleToolCall, only the Handler field is used, so dynamic tools don't need the Tool field populated.
🔇 Additional comments (4)
server/server.go (4)
49-56: LGTM! Well-structured configuration for dynamic tools.The
dynamicToolsstruct properly encapsulates the configuration with clear function signatures for listing, handling, and validating dynamic tools.
166-166: Field addition follows existing patterns.Good use of pointer type for the optional dynamic tools feature, consistent with the server's design.
982-1018: Clean integration of dynamic tools listing.The implementation correctly merges dynamic tools with existing ones, maintaining proper priority (static/session tools override dynamic ones) and consistent sorting. Error handling is appropriate.
1082-1092: Secure fallback to dynamic tool handler.The implementation correctly validates dynamic tool names before execution and follows the proper lookup order. Creating a
ServerToolwith only theHandlerfield is correct, as confirmed by the retrieved learning.
Description
This PR adds functionality for defining dynamic/runtime tools in MCP Go servers. This allows servers to define and register tools programmatically at runtime rather than only at initialization time, enabling more flexible and dynamic tool management.
Key changes:
Fixes #<issue_number> (if applicable)
Type of Change
Checklist
MCP Spec Compliance
Additional Information
This enhancement provides greater flexibility for MCP servers that need to create tools based on runtime conditions, user input, or dynamic system states. The implementation maintains backward compatibility with existing static tool definitions while adding the new dynamic capabilities.
Examples of use cases:
Summary by CodeRabbit