Security Guardrails & Diagnostics
Configure path containment, .dit extension validation, sterile stdout framing, and stderr debug logging for ochreml mcp.
Because an MCP server executes filesystem-backed ML workflows on behalf of an LLM, ochreml._mcp enforces strict containment and protocol hygiene by default.
Path Containment (--root / OCHREML_MCP_ROOT)
Every file-accepting tool (ochreml_dataset_profile, ochreml_inspect_dit, ochreml_verify_dit, ochreml_train, ochreml_predict, ochreml_eval, ochreml_compare) resolves paths through OchreMCPServer._resolve_contained().
Root Resolution Precedence
At startup, OchreMCPServer resolves the allowed workspace root in this exact order:
- CLI flag:
ochreml mcp --root /path/to/workspace - Environment variable:
OCHREML_MCP_ROOT=/path/to/workspace - Fallback: current working directory (
os.getcwd())
The root path is canonicalized immediately via Path(raw_root).resolve().
How Traversal Is Blocked
For every incoming path argument:
- Empty or non-string paths are rejected with
ValueError. - Relative paths are joined against
self.root(self.root / candidate). - The candidate is canonicalized with
.resolve(), which collapses..segments and resolves symlinks. resolved.relative_to(self.root)is checked. If the canonical path escapesself.root, the server raisesPermissionError:
Access denied: path '../../etc/passwd' escapes allowed MCP root '/path/to/workspace' ( >_< )Inside tools/call, this error is returned cleanly as a JSON-RPC tool error payload ("isError": true) rather than crashing the server process.
Example: Pinning Root via Environment Variable
If your MCP client prefers environment variables over CLI flags:
{
"mcpServers": {
"ochreml": {
"command": "ochreml",
"args": ["mcp"],
"env": {
"OCHREML_MCP_ROOT": "/srv/ml/sandbox"
}
}
}
}Avoid launching ochreml mcp from $HOME or / without --root or OCHREML_MCP_ROOT. Always scope the root to a dedicated project or dataset directory.
.dit Extension Validation
All model-file arguments pass require_dit=True into _resolve_contained(), which invokes ochreml._validate_dit_path() after containment checks pass.
The following tool parameters strictly require a .dit extension (case-insensitive):
| Tool | .dit-Validated Parameter |
|---|---|
ochreml_inspect_dit | path |
ochreml_verify_dit | path |
ochreml_train | out_path |
ochreml_predict | model_path |
ochreml_eval | model_path |
ochreml_compare | out_path (when provided) |
Any path not ending in .dit is rejected before reading or writing:
Invalid file extension for '/path/to/workspace/model.pkl'. Model files must use the '.dit' extension ( >_< )This prevents an agent from overwriting arbitrary non-model files (such as .py, .json, or .env files) during ochreml_train or ochreml_compare, and ensures ochreml_inspect_dit / ochreml_verify_dit only target OchreML model artifacts.
Sterile stdout Framing
MCP over stdio treats every line written to stdout as a JSON-RPC 2.0 frame. Any stray print(), progress bar, or warning on stdout corrupts the transport stream and disconnects the client.
ochreml mcp enforces sterile stdout:
run_stdio_server()writes only single-line compact JSON (json.dumps(resp, separators=(",", ":"), default=str) + "\n") followed bysys.stdout.flush().- Core operations in
ochreml._opsreturn structured Python dictionaries and never print tostdout. - Hardware backends (CPU, CUDA,
wgpu, TPU) remain silent on normal runs.
Diagnostics with OCHREML_DEBUG=1
When troubleshooting client connections, tool failures, or backend probing, enable OCHREML_DEBUG=1. All diagnostic messages are routed exclusively to sys.stderr with an [ochreml mcp] prefix so stdout remains untouched:
OCHREML_DEBUG=1 ochreml mcp --root /path/to/workspaceExample stderr output during a session:
[ochreml mcp] Started OchreML MCP server (root=/path/to/workspace)
[ochreml mcp] Received notification: notifications/initialized
[ochreml mcp] Tool 'ochreml_train' failed: Target column 'label' not found in dataset columns ['x0', 'x1', 'y'] ( >_< )
[ochreml mcp] EOF on stdin, shutting down OchreML MCP serverIn JSON client configs (Claude Desktop, Cursor, Windsurf, Antigravity), set it inside "env":
{
"mcpServers": {
"ochreml": {
"command": "ochreml",
"args": ["mcp", "--root", "/path/to/workspace"],
"env": {
"OCHREML_DEBUG": "1"
}
}
}
}