get_job_output
Retrieve the complete stdout and stderr output from a background job by providing its job ID. This tool enables monitoring and analysis of command execution results.
Instructions
Get the complete stdout and stderr output of a job.
Args: job_id: The UUID of the job to get output from
Returns: ProcessOutput containing the complete stdout and stderr content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | Yes | Job ID to get output from |
Implementation Reference
- src/mcp_background_job/server.py:73-94 (handler)MCP tool handler for 'get_job_output', decorated with @mcp.tool(). Validates input with Pydantic Field, delegates to JobManager service, handles errors with ToolError.@mcp.tool() async def get_job_output( job_id: str = Field(..., description="Job ID to get output from"), ) -> ProcessOutput: """Get the complete stdout and stderr output of a job. Args: job_id: The UUID of the job to get output from Returns: ProcessOutput containing the complete stdout and stderr content """ try: job_manager = get_job_manager() job_output = await job_manager.get_job_output(job_id) return job_output except KeyError: raise ToolError(f"Job {job_id} not found") except Exception as e: logger.error(f"Error getting job output for {job_id}: {e}") raise ToolError(f"Failed to get job output: {str(e)}")
- Pydantic BaseModel defining the output schema for the tool, with stdout and stderr fields.class ProcessOutput(BaseModel): """Structured stdout/stderr output from a process.""" stdout: str = Field(..., description="Standard output content") stderr: str = Field(..., description="Standard error content")
- JobManager method implementing the core logic to fetch complete process output via ProcessWrapper for the specified job.async def get_job_output(self, job_id: str) -> ProcessOutput: """Get full stdout/stderr output. Args: job_id: Job identifier Returns: ProcessOutput with complete stdout and stderr Raises: KeyError: If job_id doesn't exist """ if job_id not in self._jobs: raise KeyError(f"Job {job_id} not found") process_wrapper = self._processes.get(job_id) if process_wrapper is None: return ProcessOutput(stdout="", stderr="") return process_wrapper.get_output()