Skip to main content
Glama

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
NameRequiredDescriptionDefault
containerYes
log_dirNo/tmp/debugpy-logs
tailNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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.",
            ],
        }
  • 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()]
  • 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()
  • 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)
  • 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")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/will-garrett/debugpy-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server