debugpy_debugpy_logs
Retrieve debugpy logs from Docker containers to analyze Python debugging sessions, inspect process behavior, and identify issues in containerized applications.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container | Yes | ||
| log_dir | No | /tmp/debugpy-logs | |
| tail | No |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/debugpy_mcp/server.py:536-550 (handler)The main handler function for the 'debugpy_debugpy_logs' tool. Decorated with @mcp.tool() to register it as an MCP tool. Takes container name, log_dir (defaulting to DEFAULT_DEBUGPY_LOG_DIR), and tail count. Returns a dict with ok status, file list, log contents, and helpful notes.
@mcp.tool() def debugpy_debugpy_logs(container: str, log_dir: str = DEFAULT_DEBUGPY_LOG_DIR, tail: int = 200) -> dict[str, Any]: files = list_debugpy_log_files(container, log_dir) contents = read_debugpy_logs(container, log_dir, tail) return { "ok": True, "container": container, "log_dir": log_dir, "files": files, "logs": contents, "notes": [ "These are debugpy-generated logs if attach used --log-to.", "An empty file list usually means attach has not run with logging enabled yet.", ], } - src/debugpy_mcp/server.py:329-333 (helper)Helper function that lists debugpy log files in the container. Uses docker_exec to run 'find' command to locate log files in the specified directory.
def list_debugpy_log_files(container: str, log_dir: str) -> list[str]: proc = docker_exec(container, f"find {shlex.quote(log_dir)} -maxdepth 1 -type f 2>/dev/null | sort", timeout=15, check=False) if proc.returncode != 0: return [] return [line.strip() for line in proc.stdout.splitlines() if line.strip()] - src/debugpy_mcp/server.py:336-344 (helper)Helper function that reads and concatenates debugpy log file contents. Uses docker_exec to run a shell command that tails each log file with a header separator.
def read_debugpy_logs(container: str, log_dir: str, tail: int) -> str: cmd = ( f"if [ -d {shlex.quote(log_dir)} ]; then " f"for f in $(find {shlex.quote(log_dir)} -maxdepth 1 -type f | sort); do " f"echo '===== '"'$f'"' ====='; tail -n {tail} \"$f\"; echo; done; " f"fi" ) proc = docker_exec(container, cmd, timeout=30, check=False) return (proc.stdout or proc.stderr).strip() - src/debugpy_mcp/server.py:126-127 (helper)Core helper function that executes shell commands inside a Docker container using 'docker exec'. Used by list_debugpy_log_files and read_debugpy_logs.
def docker_exec(container: str, shell_cmd: str, *, timeout: int = DEFAULT_TIMEOUT, check: bool = True) -> subprocess.CompletedProcess[str]: return run(["docker", "exec", container, DEFAULT_SHELL, "-lc", shell_cmd], timeout=timeout, check=check) - src/debugpy_mcp/server.py:113-113 (schema)Constant defining the default debugpy log directory path, configurable via DEBUGPY_MCP_DEBUGPY_LOG_DIR environment variable, defaults to '/tmp/debugpy-logs'.
DEFAULT_DEBUGPY_LOG_DIR = os.getenv("DEBUGPY_MCP_DEBUGPY_LOG_DIR", "/tmp/debugpy-logs")