-
Notifications
You must be signed in to change notification settings - Fork 700
Add duplicate tool warning log and test logger for MCPServer #439
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?
Add duplicate tool warning log and test logger for MCPServer #439
Conversation
""" WalkthroughThe changes introduce a logger to the MCPServer, allowing it to log an informational message when a tool with a duplicate name is added and overwritten. A new test ensures this logging occurs, and a test logger utility is added for capturing log output. Minor improvements are made to race condition testing. Changes
Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
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 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
✨ 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: 0
🧹 Nitpick comments (2)
testutil/testlogger.go (1)
12-18
: Consider adding constructor function for better usability.While the current implementation works, consider adding a constructor function to improve usability and ensure proper initialization:
+// NewTestLogger creates a new TestLogger with an initialized buffer +func NewTestLogger() *TestLogger { + return &TestLogger{Buf: &bytes.Buffer{}} +} + func (l *TestLogger) Infof(format string, v ...any) { fmt.Fprintf(l.Buf, "INFO: "+format, v...) }This would prevent potential nil pointer dereferences if Buf is not properly initialized.
server/server_race_test.go (1)
60-60
: Excellent improvement for reducing name collisions.Adding
rand.Int()
to the tool name generation significantly reduces the likelihood of collisions during concurrent operations, making the race condition tests more robust.Consider seeding the random number generator for better randomness:
+import ( + "math/rand" + "time" +) + +func init() { + rand.Seed(time.Now().UnixNano()) +}However, this is optional since the current approach is sufficient for test purposes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
server/server.go
(5 hunks)server/server_race_test.go
(2 hunks)server/server_test.go
(4 hunks)testutil/testlogger.go
(1 hunks)
🔇 Additional comments (11)
testutil/testlogger.go (1)
8-10
: LGTM: Clean test logger implementation.The TestLogger struct is well-designed for its purpose of capturing log output during tests.
server/server_race_test.go (1)
6-6
: Good addition for improved test robustness.Adding the
math/rand
import supports the enhanced tool name generation.server/server.go (5)
14-14
: Good import addition for logging functionality.The util import provides access to the Logger interface and DefaultLogger implementation.
164-164
: Well-placed logger field in MCPServer struct.Adding the logger field to the MCPServer struct enables configurable logging throughout the server lifecycle.
286-290
: Excellent implementation of logger configuration option.The
WithMCPLogger
function follows the established functional options pattern and provides a clean way to inject custom loggers for testing or structured logging.
319-319
: Safe default logger initialization.Initializing with
util.DefaultLogger()
ensures the server always has a functional logger, preventing nil pointer issues.
486-488
: Appropriate logging for duplicate tool detection.The informational log message when overwriting duplicate tools improves observability without being overly verbose. The placement within the existing mutex protection ensures thread safety.
server/server_test.go (4)
4-4
: Good imports for enhanced testing capabilities.The
bytes
andtestutil
imports support the new test logger functionality for verifying log output.Also applies to: 16-16
347-380
: Comprehensive test case for duplicate tool handling.This test case effectively validates both the functional behavior (tool overwriting) and the expected notifications. The test structure is well-organized and follows the established pattern in the file.
386-390
: Excellent integration of test logger.The setup properly initializes the TestLogger and configures the server to use it via
WithMCPLogger
, enabling verification of logging behavior in tests.
418-421
: Effective log output verification.The conditional check ensures that log output verification only runs for the relevant test case, and the assertion properly validates that the expected warning message is logged when duplicate tools are added.
…nt log cluttering
2ae750a
to
0811b7a
Compare
Description
Hi, Changes in this PR,
Fixes #390
Type of Change
Checklist
MCP Spec Compliance
Additional Information
This PR enhances server observability by logging when a tool is added with a name that already exists, avoiding silent overwrites.
Added a pluggable logger to MCPServer (with a safe default implementation) and a test logger for verifying log output in unit tests.
No protocol-level changes were made, so no client impact.
Summary by CodeRabbit
New Features
Bug Fixes
Tests