get_job_trace
Retrieve GitLab CI/CD job execution logs with options to limit lines, view tail output, and access raw log data for debugging and monitoring purposes.
Instructions
Get job trace with options for partial logs, tail mode, and line limits
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes | Job ID | |
| lines_limit | No | Maximum number of lines to return (default: 1000) | |
| project_id | Yes | Project ID or path | |
| raw | No | Return raw log without formatting | |
| tail | No | Get the last N lines instead of first N lines |
Implementation Reference
- src/handlers/jobs.ts:44-127 (handler)Core handler function that fetches job trace from GitLab API, applies line limits and tail options, formats the output with metadata, and handles errors.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/server.ts:325-328 (registration)Dispatch registration in the MCP server switch statement that routes 'get_job_trace' calls to the JobHandlers.getJobTrace method.case "get_job_trace": return await this.jobHandlers.getJobTrace( args as unknown as GetJobTraceParams );
- src/tools/jobs.ts:53-85 (registration)Tool registration definition including name, description, and input schema, exported as part of jobTools array.{ 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/types.ts:399-405 (schema)TypeScript interface defining the input parameters for the get_job_trace tool, used in handler and server.export interface GetJobTraceParams { project_id: string; job_id: number; lines_limit?: number; tail?: boolean; raw?: boolean; }