feat(reports): update output directory configuration and enhance path resolution logic
This commit is contained in:
parent
e262e7f42e
commit
f2557455b7
@ -71,4 +71,4 @@ FEDEX_API_SECRET=your_api_secret
|
|||||||
FEDEX_ACCOUNT_NUMBER=your_account_number
|
FEDEX_ACCOUNT_NUMBER=your_account_number
|
||||||
|
|
||||||
# ─── Reporting ────────────────────────────────────────────────────────────────
|
# ─── Reporting ────────────────────────────────────────────────────────────────
|
||||||
REPORT_OUTPUT_DIR=./reports
|
REPORT_OUTPUT_DIR=./output-reports
|
||||||
|
|||||||
@ -13,9 +13,18 @@ from mcp.server.fastmcp import FastMCP
|
|||||||
|
|
||||||
logger = logging.getLogger("nexus-mcp.reports")
|
logger = logging.getLogger("nexus-mcp.reports")
|
||||||
|
|
||||||
# Repo root = nexus-mcp/src/shards/ → up 3 = nexus-mcp/ → up 4 = workspace root
|
# Workspace root = nexus-mcp/src/shards/ -> up 4
|
||||||
_REPO_ROOT = Path(__file__).resolve().parents[3]
|
_WORKSPACE_ROOT = Path(__file__).resolve().parents[3]
|
||||||
_DEFAULT_OUTPUT_DIR = _REPO_ROOT / "documentation" / "output-reports"
|
_DEFAULT_OUTPUT_DIR = _WORKSPACE_ROOT / "output-reports"
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve_output_dir(raw_output_dir: Optional[Path]) -> Path:
|
||||||
|
"""Resolve output path; relative paths are anchored at workspace root."""
|
||||||
|
if raw_output_dir is None:
|
||||||
|
return _DEFAULT_OUTPUT_DIR
|
||||||
|
if raw_output_dir.is_absolute():
|
||||||
|
return raw_output_dir.resolve()
|
||||||
|
return (_WORKSPACE_ROOT / raw_output_dir).resolve()
|
||||||
|
|
||||||
|
|
||||||
def _slugify(text: str) -> str:
|
def _slugify(text: str) -> str:
|
||||||
@ -34,7 +43,7 @@ def register(mcp: FastMCP) -> None:
|
|||||||
import os
|
import os
|
||||||
if os.getenv("REPORT_OUTPUT_DIR"):
|
if os.getenv("REPORT_OUTPUT_DIR"):
|
||||||
from config import ReportConfig
|
from config import ReportConfig
|
||||||
_output_dir = Path(ReportConfig().output_dir).resolve()
|
_output_dir = _resolve_output_dir(Path(ReportConfig().output_dir))
|
||||||
else:
|
else:
|
||||||
_output_dir = _DEFAULT_OUTPUT_DIR
|
_output_dir = _DEFAULT_OUTPUT_DIR
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -79,7 +88,7 @@ def register(mcp: FastMCP) -> None:
|
|||||||
|
|
||||||
# Safety guard: keep all writes inside the permitted output tree
|
# Safety guard: keep all writes inside the permitted output tree
|
||||||
try:
|
try:
|
||||||
abs_path.relative_to(_output_dir.parents[0])
|
abs_path.relative_to(_output_dir)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return {
|
return {
|
||||||
"status": "error",
|
"status": "error",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user