Read standalone report artifacts in the get_artifact_file MCP tool

What does this MR do and why?

Reports from artifacts:reports are stored as their own files, not inside the artifacts archive, so get_artifact_file could not read them and returned "not found" for paths like junit.xml.

This adds an optional file_type parameter, defaulting to archive, that reads a report artifact by type the same way the REST artifacts download endpoint does (artifact_for_type, same accepted values). The existing byte window, size cap and binary check apply. When artifact_path names a report the job uploaded as its own file, the not-found error now points at file_type.

Gzipped reports are read as a stream through the byte window, so only the window is held in memory. The runner writes one gzip member per file that artifacts:reports matched, so the reader walks every member the way GzipStream#each_blob does. The size is counted from the stream rather than read from the gzip trailer, which only describes the last member. The count stops one window past the offset cap, the furthest byte a window can reach, and reports a floor with an "at least" hint beyond it, so memory stays at the window plus one chunk and the work per call is bounded. A stored file that cannot be opened is reported as unreadable rather than raising.

References

Closes #632278 (closed)

Screenshots or screen recordings

Reading a junit report on a job that has no archive, with file_type: "junit":

{"path":"junit.xml","job_id":339,"metadata":{"total_bytes":1494,"returned":{"start":0,"end":1494},"truncated":false},"content":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuite name=\"rspec\" tests=\"4\" skipped=\"0\" failures=\"2\" errors=\"0\" ... </testsuite>\n"}

Asking for junit.xml by artifact_path on the same job:

Job 339 has no artifacts archive. The job has a junit report artifact with that name; call again with {"file_type": "junit"}.

How to set up and validate locally

  1. Run the spec:
bin/rspec spec/services/mcp/tools/jobs/get_artifact_file_service_spec.rb
  1. In a Rails console, call the tool against a job that has a report artifact:
job = Ci::JobArtifact.junit.last.job
user = job.project.first_owner
# MCP tools check the token's scopes since 43bc6ea0; any PAT of the user will do
token = user.personal_access_tokens.active.first || PersonalAccessToken.create!(user: user, name: 'mcp', scopes: [:api], expires_at: 1.day.from_now)

service = Mcp::Tools::Jobs::GetArtifactFileService.new(name: 'get_artifact_file', version: '0.1.0')
service.set_cred(current_user: user, access_token: token)

# Reads the junit report, inflated
service.execute(params: { name: 'get_artifact_file',
  arguments: { project_id: job.project.full_path, job_id: job.id, file_type: 'junit' } })

# Points at file_type when the path names a report (new instance: the service memoizes its arguments)
service = Mcp::Tools::Jobs::GetArtifactFileService.new(name: 'get_artifact_file', version: '0.1.0')
service.set_cred(current_user: user, access_token: token)
service.execute(params: { name: 'get_artifact_file',
  arguments: { project_id: job.project.full_path, job_id: job.id, artifact_path: 'junit.xml' } })

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

/assign-reviewer @bastirehm

Edited by Aditya Parida

Merge request reports

Loading
Loading