-
Notifications
You must be signed in to change notification settings - Fork 597
Add dynamic tools support to MCP server #401
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis change adds support for dynamic tools in the MCPServer by introducing a new internal structure and server option. The server can now list, validate, and handle dynamic tools at runtime, merging them with static and session-specific tools. Tool listing and invocation logic is updated to incorporate dynamic tools when enabled. Changes
Possibly related issues
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 (
|
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: 3
🧹 Nitpick comments (1)
server/server.go (1)
969-1005
: Map merge is OK, but ordering work can be simplifiedThe current merge:
- Builds a
map[string]mcp.Tool
- Converts it back to slice
- Sorts
Since
tools
is already sorted, an alternative is to:
- Append dynamic tools to the slice
- Use
slices.CompactFunc
+slices.SortFunc
onceThis removes the extra allocations of the map and second slice, benefiting large tool sets. Not blocking but worth considering if
dynamicTools.listFunc
can return hundreds/thousands of entries.
- Add required validateFunc parameter for tool validation - Add tool capabilities registration for dynamic tools - Add startup validation with panic for nil functions - Simplify runtime checks (no redundant nil checks) - Address bot feedback on parameter validation and capabilities
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
server/server.go
(5 hunks)
🔇 Additional comments (4)
server/server.go (4)
49-55
: Well-designed struct for dynamic tools configuration.The
dynamicTools
struct is cleanly designed with appropriate fields for managing dynamic tool functionality. The addition ofvalidateFunc
is particularly good as it allows proper validation before handling tool calls.
166-166
: Good integration of dynamic tools into server struct.The pointer field allows for optional dynamic tools functionality with proper nil checking.
300-324
: Excellent implementation addressing previous review feedback.This function properly implements the validation and capability registration requested in previous reviews:
- Validates that all functions are non-nil when enabled=true
- Calls
implicitlyRegisterToolCapabilities()
to ensure clients know tools exist- Uses panic for fail-fast behavior during misconfiguration
The implementation correctly addresses the concerns raised in past review comments.
982-1018
: Correct implementation of dynamic tool listing with proper priority.The dynamic tools integration is well-implemented:
- Dynamic tools have lowest priority (added first, then overridden by static/session tools)
- Proper error handling for the list function
- Maintains consistent sorting behavior
- Clean merge logic using map-based approach
Description
Adds support for dynamic tools in MCP server, allowing tools to be generated at runtime based on context and request parameters. This enables servers to provide flexible, context-aware tooling that can adapt to different scenarios without requiring static tool definitions.
Solves issue #402
Type of Change
Checklist
Additional Information
Priority Order:
Thread Safety:
Design Decisions:
Summary by CodeRabbit
New Features
Enhancements