Skip to content

getJobs hangs on large Jenkins instances - pagination applied after full enumeration #148

@sergeykad

Description

@sergeykad

Describe the bug

The getJobs tool hangs indefinitely on Jenkins instances with many jobs, even when using small limit values like 10.

Root Cause

The current implementation in DefaultMcpServer.java materializes ALL jobs before applying pagination:

return parent.getItemsStream()
    .sorted(Comparator.comparing(Item::getName))
    .skip(skip)
    .limit(limit)
    .toList();

The .sorted() operation forces the entire stream to be loaded into memory before skip and limit can be applied. On large Jenkins instances, this causes:

  • Excessive memory usage
  • CPU spike during sorting
  • Timeout before results can be returned

Expected behavior

The getJobs tool should return results within a reasonable time regardless of total job count, since the user only requested a small page of results.

Environment

  • Jenkins version: 2.516.1
  • MCP Server Plugin version: 0.149.ve5cd2f59de01
  • Approximate number of jobs: thousands
  • MCP Client: Claude Code CLI

Reproduction steps

  1. Have a Jenkins instance with thousands of jobs
  2. Call getJobs with limit: 10
  3. Observe the call hangs/times out

Suggested fix

Use Jenkins API pagination - Jenkins REST API supports tree=jobs[name]{0,10} style queries that paginate server-side.

Workaround

Users can use parentFullName parameter to scope to a specific folder with fewer jobs, or use getJob with known job names directly.

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions