get_job_trace
Retrieve GitLab CI/CD job logs with options for partial output, tail viewing, and line limits to monitor pipeline execution.
Instructions
Get job trace with options for partial logs, tail mode, and line limits
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | Project ID or path | |
| job_id | Yes | Job ID | |
| lines_limit | No | Maximum number of lines to return (default: 1000) | |
| tail | No | Get the last N lines instead of first N lines | |
| raw | No | Return raw log without formatting |
Implementation Reference
- src/handlers/jobs.ts:44-127 (handler)Main handler function that fetches job trace from GitLab API, processes it (line limits, tail, raw mode), formats response with metadata.async getJobTrace(args: GetJobTraceParams) { try { const logContent = await this.client.get(`/projects/${encodeURIComponent(args.project_id)}/jobs/${args.job_id}/trace`); const linesLimit = args.lines_limit || 1000; if (typeof logContent === 'string' && logContent) { const lines = logContent.split('\n'); const totalLines = lines.length; // Apply line limiting let processedLines: string[]; if (args.tail) { // Get last N lines processedLines = lines.slice(-linesLimit); } else { // Get first N lines processedLines = lines.slice(0, linesLimit); } const processedContent = processedLines.join('\n'); // Prepare response with metadata let responseText: string; if (args.raw) { responseText = processedContent; } else { const metadata = [ `π Job Trace Summary`, `ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ`, `π Total lines: ${totalLines}`, `π Showing: ${processedLines.length} lines ${args.tail ? '(last)' : '(first)'}`, `π Project: ${args.project_id}`, `π Job ID: ${args.job_id}`, ``, `π Log Content:`, `ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ`, processedContent ]; if (totalLines > linesLimit) { metadata.push('', `β οΈ Log truncated. Total lines: ${totalLines}, Showing: ${processedLines.length}`); if (args.tail) { metadata.push(`π‘ Use tail:false to see the beginning of the log`); } else { metadata.push(`π‘ Use tail:true to see the end of the log`); } } responseText = metadata.join('\n'); } return { content: [ { type: 'text', text: responseText, }, ], }; } else { return { content: [ { type: 'text', text: `No log content available for job ${args.job_id} in project ${args.project_id}`, }, ], }; } } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; return { content: [ { type: 'text', text: `Failed to retrieve job trace: ${errorMessage}`, }, ], isError: true, }; } }
- src/tools/jobs.ts:53-85 (schema)MCP tool definition including input JSON schema for validation and description.{ name: 'get_job_trace', description: 'Get job trace with options for partial logs, tail mode, and line limits', inputSchema: { type: 'object', properties: { project_id: { type: 'string', description: 'Project ID or path', }, job_id: { type: 'number', description: 'Job ID', }, lines_limit: { type: 'number', description: 'Maximum number of lines to return (default: 1000)', default: 1000, }, tail: { type: 'boolean', description: 'Get the last N lines instead of first N lines', default: false, }, raw: { type: 'boolean', description: 'Return raw log without formatting', default: false, }, }, required: ['project_id', 'job_id'], }, },
- src/server.ts:325-328 (registration)Server dispatch logic that maps tool name to the jobHandlers.getJobTrace method.case "get_job_trace": return await this.jobHandlers.getJobTrace( args as unknown as GetJobTraceParams );
- src/types.ts:399-405 (schema)TypeScript interface for input parameters used in handler signature.export interface GetJobTraceParams { project_id: string; job_id: number; lines_limit?: number; tail?: boolean; raw?: boolean; }