oct.mcp.policy_loader module#

Purpose#

Centralised policy loader for the oct-mcp server (Phase 5C, M-C7).

Loads policy override JSON from a local filesystem path or an HTTPS URL at server startup. The loaded overrides are applied on top of the base McpConfig before the policy engine is instantiated, enabling enterprise deployments to distribute a shared security policy from a central location.

Configuration#

Set policy_source in ~/.oct-mcp/config.json:

{
    "policy_source": "https://internal.company.com/oct-policy.json"
}

Or provide a local path:

{
    "policy_source": "/etc/oct/policy.json"
}

Policy JSON schema (all fields optional):

{
    "profile": "strict",
    "rate_limit_per_minute": 20,
    "timeout_default_seconds": 30,
    "max_output_bytes": 524288,
    "dry_run_default_for_writes": true
}

Only the keys listed in _ALLOWED_OVERRIDE_KEYS are honoured. Unknown keys are silently dropped. Type mismatches are silently ignored.

Security#

  • HTTPS URLs only. HTTP URLs are rejected to prevent cleartext policy transmission.

  • File size capped at 64 KB (same as config.json).

  • Schema is an allowlist — no arbitrary key injection possible.

  • Any failure (network error, parse error, schema violation) falls back to built-in defaults silently without crashing the server.

Diagnostics#

Domain: MCP Levels:

L1 — errors: load failures, schema violations L2 — lifecycle: policy loaded, overrides applied L4 — deep trace: resolved field values

Contracts#

oct.mcp.policy_loader.apply_policy_overrides(config: object, overrides: dict) object[source]#

Return a new McpConfig with overrides applied.

Parameters:
Returns:

  • A new McpConfig with the override values merged in. Returns

  • *config unchanged if overrides is empty or an error occurs.*

oct.mcp.policy_loader.load_policy_source(source: str, timeout_s: int = 5) dict[source]#

Load policy override JSON from source.

Parameters:
  • source – A local filesystem path or an https:// URL. http:// URLs are rejected. Local paths may be absolute or relative.

  • timeout_s – Network timeout in seconds for HTTPS requests (default 5).

Returns:

  • A dict containing only the keys in _ALLOWED_OVERRIDE_KEYS

  • with validated values. Returns {} on any failure.