|
Option C Tools
|
Classes | |
| class | RedactorResult |
| class | Redactor |
Functions | |
| None | _dbg (*args, **kwargs) |
| str | _redact_git_url (str text) |
Variables | |
| frozenset | _SECRET_NAME_PATTERNS |
| re | _ANSI_ESCAPE_RE |
| re | _ASSIGNMENT_LINE_RE |
| tuple | _SYSTEM_PATH_PREFIXES_POSIX |
Purpose
-------
Output Redactor (Layer 5) for the ``oct-mcp`` six-layer pipeline.
Applies a five-step sanitisation pipeline to every tool output before
it is returned to the MCP client.
Responsibilities
----------------
- Step 1: Apply ``redaction_patterns`` from ``debug_config.json``
(loaded at server startup; falls back to empty list if unavailable).
- Step 2: Apply ``_SECRET_NAME_PATTERNS`` line filtering — any output
line that looks like a ``KEY=value`` assignment whose key matches a
secret pattern is replaced with ``[REDACTED]``.
- Step 3: Anonymise absolute paths:
``$HOME/...`` → ``[HOME]/...``
``/usr/``, ``/bin/``, ``/opt/``, etc. → ``[SYSTEM]/...``
``<project_root>/...`` → ``[PROJECT]/...``
Drive-letter paths on Windows follow the same rules.
- Step 4: Strip ANSI escape sequences.
- Step 5: Truncate output that exceeds ``max_output_bytes``, appending
a ``[OUTPUT TRUNCATED AT <N> BYTES]`` marker.
Also applies git-URL credential redaction (``_redact_git_url``) as
a supplementary step after step 2 to catch any credentials that
survived the key-pattern filter.
Diagnostics
-----------
Domain: MCP
Levels:
L2 — lifecycle: redactor instantiation
L3 — per-call redaction counts
L4 — deep trace: individual substitutions
Contracts
---------
- This module does not import ``click`` or the MCP SDK.
- :meth:`Redactor.apply_all` is pure: the same input always produces the
same output given the same configuration.
- :meth:`Redactor.apply_all` never raises.
- ``redactions_applied`` in :class:`RedactorResult` counts *all*
individual substitutions made across all steps.
|
protected |
|
protected |
|
protected |
Definition at line 91 of file redactor.py.
|
protected |
Definition at line 103 of file redactor.py.
|
protected |
Definition at line 69 of file redactor.py.
|
protected |
Definition at line 108 of file redactor.py.