daemon_status
Monitor Gradle daemon health and resource usage by checking current daemon status and information for troubleshooting and optimization.
Instructions
Get status of Gradle daemon(s).
Returns current daemon status including running daemons and their info. Useful for monitoring daemon health and resource usage.
Returns: DaemonStatusResult with running status, list of daemon info, and optional error.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/gradle_mcp/server.py:435-493 (handler)The main MCP tool handler for 'daemon_status', decorated with @mcp.tool() for automatic registration. It fetches raw status from GradleWrapper, parses the output to extract daemon PIDs, statuses, and constructs the DaemonStatusResult.@mcp.tool() async def daemon_status(ctx: Context | None = None) -> DaemonStatusResult: """Get status of Gradle daemon(s). Returns current daemon status including running daemons and their info. Useful for monitoring daemon health and resource usage. Returns: DaemonStatusResult with running status, list of daemon info, and optional error. """ try: if ctx: await ctx.info("Getting Gradle daemon status") gradle = _get_gradle_wrapper(ctx) result = await gradle.daemon_status() if ctx: if result["success"]: await ctx.info("Retrieved daemon status successfully") else: await ctx.error("Failed to get daemon status", extra={"error": result.get("error")}) # Parse daemon output to extract daemon info daemons: list[dict] = [] running = False output = result.get("output", "") if result["success"] and output: # Parse lines looking for daemon entries # Format: " 12345 IDLE 8.5" for line in output.split("\n"): line = line.strip() # Skip header and empty lines if not line or line.startswith("PID") or line.startswith("-"): continue # Try to parse daemon status line parts = line.split() if len(parts) >= 2 and parts[0].isdigit(): daemon_info = { "pid": parts[0], "status": parts[1] if len(parts) > 1 else "UNKNOWN", } if len(parts) > 2: daemon_info["info"] = " ".join(parts[2:]) daemons.append(daemon_info) running = True return DaemonStatusResult( running=running, daemons=daemons, error=result.get("error"), ) except Exception as e: return DaemonStatusResult( running=False, daemons=[], error=str(e), )
- src/gradle_mcp/server.py:124-129 (schema)Pydantic BaseModel defining the return type/schema for the daemon_status tool response, including running status, list of daemon details, and optional error.class DaemonStatusResult(BaseModel): """Result of daemon status query.""" running: bool daemons: list[dict] # List of daemon info error: str | None = None
- src/gradle_mcp/gradle.py:1245-1277 (helper)Low-level helper method in GradleWrapper class that executes './gradlew --status' to retrieve raw daemon status output, which is then parsed by the MCP handler.async def daemon_status(self) -> dict: """Get status of Gradle daemons. Returns: dict with 'success' bool, 'output' str (daemon status info), and optional 'error' str. """ cmd = [str(self.wrapper_script), "--status"] logger.info(f"Executing: {' '.join(cmd)}") try: process = await asyncio.create_subprocess_exec( *cmd, cwd=str(self.project_root), stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, env=self._build_execution_environment(), ) stdout, stderr = await process.communicate() stdout_str = stdout.decode() if stdout else "" stderr_str = stderr.decode() if stderr else "" if process.returncode == 0: logger.info("Daemon status retrieved successfully") return {"success": True, "output": stdout_str, "error": None} else: error_message = stderr_str or stdout_str or "Failed to get daemon status" logger.error(f"Daemon status failed: {error_message}") return {"success": False, "output": stdout_str, "error": error_message} except Exception as e: logger.error(f"Daemon status failed with exception: {e}") return {"success": False, "output": "", "error": str(e)}