diff --git a/index.ts b/index.ts index 5132f7b..c6921bb 100644 --- a/index.ts +++ b/index.ts @@ -518,7 +518,7 @@ const allTools = [ }, { name: "get_pipeline_job_output", - description: "Get the output/trace of a GitLab pipeline job number", + description: "Get the output/trace of a GitLab pipeline job with optional pagination to limit context window usage", inputSchema: zodToJsonSchema(GetPipelineJobOutputSchema), }, { @@ -2606,9 +2606,11 @@ async function getPipelineJob(projectId: string, jobId: number): Promise} The job output/trace */ -async function getPipelineJobOutput(projectId: string, jobId: number): Promise { +async function getPipelineJobOutput(projectId: string, jobId: number, limit?: number, offset?: number): Promise { projectId = decodeURIComponent(projectId); // Decode project ID const url = new URL( `${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/jobs/${jobId}/trace` @@ -2627,7 +2629,35 @@ async function getPipelineJobOutput(projectId: string, jobId: number): Promise 0 || endIndex < lines.length) { + const totalLines = lines.length; + const shownLines = selectedLines.length; + const skippedFromStart = startIndex; + const skippedFromEnd = startOffset; + + return `[Log truncated: showing ${shownLines} of ${totalLines} lines, skipped ${skippedFromStart} from start, ${skippedFromEnd} from end]\n\n${result}`; + } + + return result; + } + + return fullTrace; } /** @@ -3722,8 +3752,8 @@ server.setRequestHandler(CallToolRequestSchema, async request => { } case "get_pipeline_job_output": { - const { project_id, job_id } = GetPipelineJobOutputSchema.parse(request.params.arguments); - const jobOutput = await getPipelineJobOutput(project_id, job_id); + const { project_id, job_id, limit, offset } = GetPipelineJobOutputSchema.parse(request.params.arguments); + const jobOutput = await getPipelineJobOutput(project_id, job_id, limit, offset); return { content: [ { diff --git a/schemas.ts b/schemas.ts index fd5a132..4bcbd65 100644 --- a/schemas.ts +++ b/schemas.ts @@ -191,6 +191,8 @@ export const CancelPipelineSchema = z.object({ export const GetPipelineJobOutputSchema = z.object({ project_id: z.string().describe("Project ID or URL-encoded path"), job_id: z.number().describe("The ID of the job"), + limit: z.number().optional().describe("Maximum number of lines to return from the end of the log (default: 1000)"), + offset: z.number().optional().describe("Number of lines to skip from the end of the log (default: 0)"), }); // User schemas