Skip to content

Implement pagination page size for log tools #127

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

akolotov
Copy link
Collaborator

@akolotov akolotov commented Jul 4, 2025

Summary

  • configure logs_page_size
  • document BLOCKSCOUT_LOGS_PAGE_SIZE and set Docker default
  • add helper create_items_pagination
  • paginate address and transaction logs using helper
  • update unit and integration tests for new pagination behavior

Closes #125


https://chatgpt.com/codex/tasks/task_b_686857f2de7c8323a5599016898c8ac9

Summary by CodeRabbit

  • New Features

    • Added support for configuring the number of log items returned per page via a new environment variable.
  • Refactor

    • Centralized and standardized pagination logic for address and transaction log retrieval, improving consistency and maintainability.
  • Tests

    • Enhanced and expanded test coverage for pagination, including custom page size scenarios and new helper function tests.
    • Updated integration tests to enforce a maximum of 10 log items per page.

Copy link

coderabbitai bot commented Jul 4, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change introduces a configurable page size for log-related tools, defaulting to 10, by updating configuration files and refactoring the get_address_logs and get_transaction_logs tools to use a centralized pagination helper. Unit and integration tests are updated and expanded to validate the new pagination behavior and configuration.

Changes

File(s) Change Summary
.env.example, Dockerfile Added BLOCKSCOUT_LOGS_PAGE_SIZE environment variable with default value 10 and documentation.
blockscout_mcp_server/config.py Added logs_page_size config parameter (default 10) to ServerConfig.
blockscout_mcp_server/tools/common.py Added create_items_pagination helper function for paginating lists and generating next call info.
blockscout_mcp_server/tools/address_tools.py, blockscout_mcp_server/tools/transaction_tools.py Refactored log tools to use create_items_pagination and logs_page_size for consistent pagination.
tests/integration/test_address_tools_integration.py, tests/integration/test_transaction_tools_integration.py Updated integration tests to assert response size is ≤10.
tests/tools/test_address_logs.py, tests/tools/test_transaction_tools_3.py Added/updated unit tests for log tools, including custom page size and pagination logic.
tests/tools/test_common.py Added unit tests for create_items_pagination helper function.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Tool (get_address_logs/get_transaction_logs)
    participant PaginationHelper (create_items_pagination)
    participant Config

    Client->>Tool: Request logs (with params)
    Tool->>Config: Get logs_page_size
    Tool->>Tool: Fetch full list of logs from API
    Tool->>PaginationHelper: Paginate logs (items, logs_page_size, ...)
    PaginationHelper-->>Tool: Sliced items, PaginationInfo
    Tool-->>Client: Return sliced items and PaginationInfo
Loading

Assessment against linked issues

Objective Addressed Explanation
Add logs_page_size config variable to config.py (default 10) [#125]
Update Dockerfile and .env.example with BLOCKSCOUT_LOGS_PAGE_SIZE env variable [#125]
Refactor get_address_logs and get_transaction_logs to use config page size and cursor logic [#125]
Update/add unit and integration tests for new pagination and config, including custom page size [#125]

Poem

A hop and a skip, the logs now fit,
Ten at a time—no more, no split!
With config so bright, and tests in the night,
Our pagination’s just right.
🐇✨
— A CodeRabbit delight!


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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@akolotov
Copy link
Collaborator Author

akolotov commented Jul 4, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Jul 4, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@akolotov akolotov requested a review from Copilot July 4, 2025 23:04
Copilot

This comment was marked as outdated.

@akolotov akolotov requested a review from Copilot July 4, 2025 23:24
Copy link

@Copilot Copilot AI left a 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 adds configurable pagination for log retrieval tools by introducing a new logs_page_size setting, centralizing pagination logic, and updating related tests and documentation.

  • Adds logs_page_size to configuration, Dockerfile, and .env.example
  • Implements create_items_pagination helper and integrates it into address and transaction log tools
  • Updates unit and integration tests to cover pagination behavior and custom page sizes

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
blockscout_mcp_server/config.py Added logs_page_size configuration parameter
Dockerfile Set BLOCKSCOUT_LOGS_PAGE_SIZE default
.env.example Documented BLOCKSCOUT_LOGS_PAGE_SIZE
blockscout_mcp_server/tools/common.py Implemented new create_items_pagination helper
blockscout_mcp_server/tools/transaction_tools.py Integrated pagination helper in transaction logs tool
blockscout_mcp_server/tools/address_tools.py Integrated pagination helper in address logs tool
tests/tools/test_common.py Added tests for create_items_pagination
tests/tools/test_transaction_tools_3.py Updated tests to mock and verify pagination logic
tests/tools/test_address_logs.py Updated tests to mock and verify pagination logic
tests/integration/test_transaction_tools_integration.py Enforced page-size limit in integration test
tests/integration/test_address_tools_integration.py Enforced page-size limit in integration test
Comments suppressed due to low confidence (3)

tests/tools/test_transaction_tools_3.py:247

  • [nitpick] The variable name hash shadows the built-in hash() function; consider renaming it to tx_hash or similar for clarity.
        result = await get_transaction_logs(chain_id=chain_id, transaction_hash=hash, ctx=mock_ctx)

tests/tools/test_transaction_tools_3.py:475

  • Consider adding assertions on mock_create_pagination.call_args.kwargs['next_call_base_params'] and tool_name to fully validate that pagination parameters are passed correctly.
        assert mock_create_pagination.call_args.kwargs["page_size"] == 5

tests/tools/test_address_logs.py:169

  • It would be beneficial to assert that create_items_pagination was called with the correct next_call_base_params (including chain_id and address) to ensure the helper is invoked with intended arguments.
        assert mock_create_pagination.call_args.kwargs["page_size"] == 5

@akolotov akolotov merged commit 157ef08 into codex/refactor-nft_tokens_by_address-pagination-logic Jul 8, 2025
8 checks passed
@akolotov akolotov deleted the codex/refactor-log-tools-for-response-size-reduction branch July 8, 2025 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant