feat!: introduce McpObserver for telemetry and message monitoring#136
Merged
Conversation
…at/issue-133-telemetry-support
Merged
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.
📌 Summary
This PR introduces a new McpObserver trait to the SDK, providing a hook mechanism to intercept incoming and outgoing MCP messages. This allows developers to easily apply telemetry, structured logging, debugging, or custom monitoring solutions across their servers and clients without modifying core business logic.
🔍 Related Issues
✨ Changes Made
message_observerconfiguration directly intoMcpClientOptionsandHyperServerOptions(ServerOptions).hello-world-mcp-server-stdioandsimple-mcp-client-streamable-httpexamples to utilize the new observers.Message Observer (Telemetry & Monitoring)section to the base and crates README files.🛠️ Testing Steps
cargo test --package rust-mcp-sdk --test test_observerhello-world-mcp-server-stdioexample and monitor logs using https://app.beeceptor.com/console/rustmcp to see outgoing/incoming server telemetry.💡 Additional Notes
Operations within on_receive and on_send of the McpObserver trair are on the critical message path. So implementations should either be very fast or spawn an asynchronous, non-blocking task for heavy operations (like HTTP requests) to prevent backpressure.