-
Notifications
You must be signed in to change notification settings - Fork 6
Add logging decorator for tool invocations #162
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 logging decorator, Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant ToolFunction
participant Logger
Client->>Server: Call MCP tool (e.g., get_address_by_ens_name)
Server->>ToolFunction: Invoke tool (decorated with @log_tool_invocation)
ToolFunction->>Logger: Log tool name and args (excluding ctx)
ToolFunction-->>Server: Return result
Server-->>Client: Return tool response
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes detected. All modifications directly relate to the objectives in the linked issue, focusing on logging, decorator application, documentation, and testing. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ 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.
Pull Request Overview
This PR introduces a @log_tool_invocation
decorator to automatically log tool calls, applies it across all MCP tool functions, configures the root logger, adds a unit test for the decorator, and updates documentation and coding rules.
- Implemented
log_tool_invocation
intools.common
- Decorated all existing tools with
@log_tool_invocation
and configured logging inserver.py
- Added a unit test for the decorator and updated docs/rules to mandate its use
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
tests/tools/test_log_tool_invocation.py | Added tests for the log_tool_invocation decorator |
blockscout_mcp_server/tools/transaction_tools.py | Imported and applied @log_tool_invocation to transaction tools |
blockscout_mcp_server/tools/search_tools.py | Imported and applied @log_tool_invocation to search tools |
blockscout_mcp_server/tools/get_instructions.py | Imported and applied @log_tool_invocation to instructions tool |
blockscout_mcp_server/tools/ens_tools.py | Imported and applied @log_tool_invocation to ENS tools |
blockscout_mcp_server/tools/contract_tools.py | Imported and applied @log_tool_invocation to contract tools |
blockscout_mcp_server/tools/common.py | Implemented the log_tool_invocation decorator |
blockscout_mcp_server/tools/chains_tools.py | Imported and applied @log_tool_invocation to chains tools |
blockscout_mcp_server/tools/block_tools.py | Imported and applied @log_tool_invocation to block tools |
blockscout_mcp_server/tools/address_tools.py | Imported and applied @log_tool_invocation to address tools |
blockscout_mcp_server/server.py | Configured root logger with basicConfig |
AGENTS.md | Updated docs to mention the new logging decorator |
.cursor/rules/110-new-mcp-tool.mdc | Added guideline to decorate tools with @log_tool_invocation |
.cursor/AGENTS.md | Updated agent guidance to require the new decorator |
Comments suppressed due to low confidence (2)
.cursor/rules/110-new-mcp-tool.mdc:100
- [nitpick] The indentation of this bullet is inconsistent with the surrounding list items; align it (e.g., 5 spaces) for consistent Markdown formatting.
- Decorate each tool function with `@log_tool_invocation` from `tools.common`
tests/tools/test_log_tool_invocation.py:10
- Add tests for scenarios with default or missing parameters (beyond
ctx
) to ensure the decorator correctly binds and logs default argument values.
async def test_log_tool_invocation_decorator(caplog: pytest.LogCaptureFixture, mock_ctx: Context) -> None:
Summary
log_tool_invocation
decoratorserver.py
@log_tool_invocation
Closes #161
https://chatgpt.com/codex/tasks/task_b_6878330535e08323904e49c0150ebfe3
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests
Chores