get_project_root
Identify the project root and structure type for profiling analysis, returning root path, type, and markers found.
Instructions
Get the detected project root and structure type.
Returns: {root, type, markers_found}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/scalene_mcp/server.py:79-110 (handler)The main tool handler for 'get_project_root' - an async function that returns the detected project root path, project type (python/node/mixed/unknown), and markers found. It calls the helper _get_project_root() and checks for common project markers.
async def get_project_root() -> dict[str, str]: """Get the detected project root and structure type. Returns: {root, type, markers_found} """ root = _get_project_root() # Detect project type project_type = "unknown" markers_found = [] if (root / "pyproject.toml").exists(): project_type = "python" markers_found.append("pyproject.toml") if (root / "setup.py").exists(): project_type = "python" markers_found.append("setup.py") if (root / "package.json").exists(): project_type = "node" if project_type == "unknown" else "mixed" markers_found.append("package.json") if (root / ".git").exists(): markers_found.append(".git") if (root / "Makefile").exists(): markers_found.append("Makefile") if (root / "GNUmakefile").exists(): markers_found.append("GNUmakefile") return { "root": str(root.absolute()), "type": project_type, "markers_found": ", ".join(markers_found) if markers_found else "none", } - src/scalene_mcp/server.py:58-63 (helper)Internal helper _get_project_root() that returns the cached project root Path, calling _detect_project_root() on first access.
def _get_project_root() -> Path: """Get the current project root (auto-detected or explicitly set).""" global _project_root if _project_root is None: _project_root = _detect_project_root() return _project_root - src/scalene_mcp/server.py:37-55 (helper)Internal helper _detect_project_root() that auto-detects the project root by walking up the directory tree looking for markers like .git, pyproject.toml, setup.py, package.json, Makefile.
def _detect_project_root(start_path: Path | None = None) -> Path: """Auto-detect project root by looking for common markers. Checks for: .git, pyproject.toml, setup.py, package.json, Makefile Falls back to current working directory if no markers found. """ search_path = start_path or Path.cwd() if search_path.is_file(): search_path = search_path.parent markers = {".git", "pyproject.toml", "setup.py", "package.json", "Makefile", "GNUmakefile"} # Search up directory tree for current in [search_path, *search_path.parents]: if any((current / marker).exists() for marker in markers): return current # Fallback to cwd return Path.cwd() - src/scalene_mcp/server.py:113-113 (registration)Registration of get_project_root as an MCP tool via server.tool(get_project_root).
server.tool(get_project_root)