Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add pagination support to get_pull_request_files tool #561

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anant-rustagi
Copy link

@anant-rustagi anant-rustagi commented Jun 21, 2025

Add pagination support to get_pull_request_files tool

Fixes #527

Problem

The get_pull_request_files tool currently retrieves only the first 30 files with diffs of any PR that contains more than 30 files. This is a limitation because large PRs with many files cannot be fully analyzed.

Solution

Added pagination support to the get_pull_request_files tool by:

  • Adding WithPagination() to the tool definition
  • Using OptionalPaginationParams(request) to handle page and perPage parameters
  • Passing pagination parameters to the GitHub API ListFiles call
  • Following the same pattern used by other paginated tools in the codebase

Changes Made

1. Core Implementation (pkg/github/pullrequests.go)

// Added WithPagination() to tool definition
WithPagination(),

// Added pagination parameter handling
pagination, err := OptionalPaginationParams(request)
if err != nil {
    return mcp.NewToolResultError(err.Error()), nil
}

// Updated GitHub API call to use pagination
opts := &github.ListOptions{
    PerPage: pagination.perPage,
    Page:    pagination.page,
}

2. Test Updates (pkg/github/pullrequests_test.go)

  • Added verification that pagination parameters (page, perPage) are present in tool schema
  • Added test case for successful files fetch with pagination parameters
  • Updated tool schema snapshot to reflect new parameters

3. Schema Snapshot (pkg/github/__toolsnaps__/get_pull_request_files.snap)

  • Automatically updated to include new pagination parameters
  • Ensures schema changes are tracked and validated

Testing Done

1. Unit Tests

# All tests pass
go test ./pkg/github -v

Test Results:

  • Test_GetPullRequestFiles - All test cases pass including new pagination test
  • ✅ Schema verification - Confirms page and perPage parameters are present
  • ✅ Pagination functionality - Verifies tool works with pagination parameters

2. Integration Testing

# Verified tool schema includes pagination parameters
GITHUB_PERSONAL_ACCESS_TOKEN=xxx ./mcpcurl --stdio-server-cmd="./github-mcp-server stdio --toolsets pull_requests" schema

Schema Verification:

{
  "name": "get_pull_request_files",
  "inputSchema": {
    "properties": {
      "owner": {"description": "Repository owner", "type": "string"},
      "page": {"description": "Page number for pagination (min 1)", "minimum": 1, "type": "number"},
      "perPage": {"description": "Results per page for pagination (min 1, max 100)", "maximum": 100, "minimum": 1, "type": "number"},
      "pullNumber": {"description": "Pull request number", "type": "number"},
      "repo": {"description": "Repository name", "type": "string"}
    },
    "required": ["owner", "repo", "pullNumber"]
  }
}

3. GitHub API Verification

# Verified GitHub API supports pagination for PR files
curl -H "Authorization: token xxx" "https://api.github.com/repos/github/github-mcp-server/pulls/521/files?per_page=2&page=1"

API Response: Successfully returned paginated results with 2 files per page.

4. Build Verification

# Server builds successfully with changes
go build -o github-mcp-server cmd/github-mcp-server/main.go

Usage Examples

Default behavior (no pagination parameters):

{
  "owner": "github",
  "repo": "github-mcp-server", 
  "pullNumber": 123
}

With pagination:

{
  "owner": "github",
  "repo": "github-mcp-server",
  "pullNumber": 123,
  "page": 2,
  "perPage": 10
}

Backward Compatibility

  • Fully backward compatible - Existing calls without pagination parameters work exactly as before
  • Optional parameters - page and perPage are optional with sensible defaults
  • Same response format - Returns the same JSON structure as before

Impact

  • Large PRs: Can now analyze PRs with more than 30 files
  • Performance: Users can control the number of files retrieved per request
  • Flexibility: Supports both default behavior and custom pagination

Files Changed

  • pkg/github/pullrequests.go - Core implementation
  • pkg/github/pullrequests_test.go - Test updates
  • pkg/github/__toolsnaps__/get_pull_request_files.snap - Schema snapshot

- Add WithPagination() to tool definition
- Use OptionalPaginationParams to handle page and perPage parameters
- Pass pagination parameters to GitHub API ListFiles call
- Update tests to include pagination scenarios
- Update tool schema snapshot

Fixes github#527
@anant-rustagi anant-rustagi requested a review from a team as a code owner June 21, 2025 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pagination support to the get_pull_request_files tool.
1 participant