Option C Tools
Loading...
Searching...
No Matches
oct.mcp.config Namespace Reference

Classes

class  McpConfig

Functions

None _dbg (*args, **kwargs)
McpConfig load_config (Path|None path=None)
McpConfig _apply_json (McpConfig base, dict data)

Variables

int _CONFIG_MAX_BYTES = 64 * 1024
Path _DEFAULT_CONFIG_PATH = Path.home() / ".oct-mcp" / "config.json"
tuple VALID_MCP_PROFILES = ("default", "strict", "airgapped")
int _RATE_LIMIT_MIN = 1
int _RATE_LIMIT_MAX = 1000
int _TIMEOUT_MIN = 5
int _TIMEOUT_MAX = 300
int _TIMEOUT_TEST_MAX = 600
int _MAX_OUTPUT_MIN = 1024
int _MAX_OUTPUT_MAX = 10 * 1024 * 1024
int _MAX_JOBS_MIN = 1
int _MAX_JOBS_MAX = 16
int _MEMORY_LIMIT_MIN = 0
int _MEMORY_LIMIT_MAX = 8192
int _METRICS_PORT_MIN = 1
int _METRICS_PORT_MAX = 65535
tuple VALID_SANDBOX_BACKENDS = ("auto", "native", "bubblewrap", "sandbox_exec")

Detailed Description

Purpose
-------
Configuration loader for the ``oct-mcp`` server. Reads
``~/.oct-mcp/config.json`` (user-level trusted config), merges with
environment variable overrides, and exposes a :class:`McpConfig`
dataclass consumed by every layer of the six-layer pipeline.

Responsibilities
----------------
- Define the canonical :class:`McpConfig` schema with safe defaults.
- Implement :func:`load_config` which locates, validates, and returns a
  populated ``McpConfig``.
- Honour ``OCT_MCP_SAFE_MODE`` and ``OCT_TRUST_REPO_CONFIG`` env vars.
- Never read or trust project-level config (``debug_config.json``,
  ``.octrc.json``) unless ``trust_repo_config`` is explicitly enabled.
- Apply a 64 KB file-size guard (matching OI-414) to the user config.

Diagnostics
-----------
Domain: MCP
Levels:
    L1 — errors: config file read failures, schema errors
    L2 — lifecycle: config loaded, safe-mode active
    L4 — deep trace: resolved field values

Contracts
---------
- This module does not import ``click``, the MCP SDK, or any other
  ``oct.mcp.*`` module (no cycles).
- :func:`load_config` always returns a fully-populated ``McpConfig``
  even if the file is missing — defaults are safe.
- Config values coming from JSON are validated and clamped so callers
  never receive out-of-range integers.

Function Documentation

◆ _apply_json()

McpConfig oct.mcp.config._apply_json ( McpConfig base,
dict data )
protected
Return a new :class:`McpConfig` with fields from *data* merged in.

Only known fields are applied; unknown keys are silently ignored
(the config file is user-controlled but we don't crash on new keys).
Field values are clamped to the valid ranges defined by the module
constants. Booleans must be actual JSON booleans, not strings.

Definition at line 248 of file config.py.

Here is the caller graph for this function:

◆ _dbg()

None oct.mcp.config._dbg ( * args,
** kwargs )
protected

Definition at line 51 of file config.py.

Here is the caller graph for this function:

◆ load_config()

McpConfig oct.mcp.config.load_config ( Path | None path = None)
Load and return a :class:`McpConfig`.

Resolution order:

1. Read ``~/.oct-mcp/config.json`` (or *path* if supplied).
2. Validate and clamp JSON field values.
3. Apply environment variable overrides:
   - ``OCT_MCP_SAFE_MODE=1``  → ``safe_mode = True``
   - ``OCT_TRUST_REPO_CONFIG=1`` → ``trust_repo_config = True``
   - ``OCT_MCP_PROFILE=<name>`` → ``profile = <name>``
4. Return a fully-populated ``McpConfig``.

Never raises. Any read or parse failure falls back to the default
config and logs an error at level 1.

Definition at line 180 of file config.py.

Here is the call graph for this function:

Variable Documentation

◆ _CONFIG_MAX_BYTES

int oct.mcp.config._CONFIG_MAX_BYTES = 64 * 1024
protected

Definition at line 64 of file config.py.

◆ _DEFAULT_CONFIG_PATH

Path oct.mcp.config._DEFAULT_CONFIG_PATH = Path.home() / ".oct-mcp" / "config.json"
protected

Definition at line 67 of file config.py.

◆ _MAX_JOBS_MAX

int oct.mcp.config._MAX_JOBS_MAX = 16
protected

Definition at line 81 of file config.py.

◆ _MAX_JOBS_MIN

int oct.mcp.config._MAX_JOBS_MIN = 1
protected

Definition at line 80 of file config.py.

◆ _MAX_OUTPUT_MAX

int oct.mcp.config._MAX_OUTPUT_MAX = 10 * 1024 * 1024
protected

Definition at line 79 of file config.py.

◆ _MAX_OUTPUT_MIN

int oct.mcp.config._MAX_OUTPUT_MIN = 1024
protected

Definition at line 78 of file config.py.

◆ _MEMORY_LIMIT_MAX

int oct.mcp.config._MEMORY_LIMIT_MAX = 8192
protected

Definition at line 83 of file config.py.

◆ _MEMORY_LIMIT_MIN

int oct.mcp.config._MEMORY_LIMIT_MIN = 0
protected

Definition at line 82 of file config.py.

◆ _METRICS_PORT_MAX

int oct.mcp.config._METRICS_PORT_MAX = 65535
protected

Definition at line 85 of file config.py.

◆ _METRICS_PORT_MIN

int oct.mcp.config._METRICS_PORT_MIN = 1
protected

Definition at line 84 of file config.py.

◆ _RATE_LIMIT_MAX

int oct.mcp.config._RATE_LIMIT_MAX = 1000
protected

Definition at line 74 of file config.py.

◆ _RATE_LIMIT_MIN

int oct.mcp.config._RATE_LIMIT_MIN = 1
protected

Definition at line 73 of file config.py.

◆ _TIMEOUT_MAX

int oct.mcp.config._TIMEOUT_MAX = 300
protected

Definition at line 76 of file config.py.

◆ _TIMEOUT_MIN

int oct.mcp.config._TIMEOUT_MIN = 5
protected

Definition at line 75 of file config.py.

◆ _TIMEOUT_TEST_MAX

int oct.mcp.config._TIMEOUT_TEST_MAX = 600
protected

Definition at line 77 of file config.py.

◆ VALID_MCP_PROFILES

tuple oct.mcp.config.VALID_MCP_PROFILES = ("default", "strict", "airgapped")

Definition at line 70 of file config.py.

◆ VALID_SANDBOX_BACKENDS

tuple oct.mcp.config.VALID_SANDBOX_BACKENDS = ("auto", "native", "bubblewrap", "sandbox_exec")

Definition at line 88 of file config.py.