oct.mcp.metrics module#
Purpose#
Optional Prometheus instrumentation for the oct-mcp server (Phase 5C).
Exposes five metrics:
oct_mcp_tool_calls_total— Counter; labelstool,decision.oct_mcp_tool_duration_seconds— Histogram; labeltool.oct_mcp_rate_limit_hits_total— Counter; labeltool.oct_mcp_redactions_total— Counter; labeltool.oct_mcp_validation_failures_total— Counter; labeltool.
All public methods are no-ops when prometheus_client is not
installed, so the rest of the pipeline never needs to guard with
if metrics is not None.
Enabling metrics#
Install the optional extra:
pip install 'oct[metrics]'
Then start the server with --metrics-port:
python -m oct.mcp --project-root /path/to/project --metrics-port 9090
Diagnostics#
Domain: MCP Levels:
L1 — errors: metrics server startup failures L2 — lifecycle: metrics server started
Contracts#
This module never raises for the caller — all methods swallow errors and degrade gracefully.
When
prometheus_clientis absent,PROMETHEUS_AVAILABLEisFalseandMcpMetricsis a lightweight no-op stub.The metrics HTTP server is started in a daemon background thread so it does not prevent process exit.
McpMetricsaccepts an optionalregistryparameter (CollectorRegistry). The default is the module-levelprometheus_client.REGISTRYso production/metricsworks without any caller change. Tests and multi-tenant callers pass a privateCollectorRegistry()to avoidDuplicated timeseriescollisions across instances.
- class oct.mcp.metrics.McpMetrics(registry: CollectorRegistry | None = None)[source]#
Bases:
objectPrometheus instrumentation for the oct-mcp pipeline.
All record methods are no-ops when
prometheus_clientis absent. Instantiate once per server session and pass intoServerState.- record_call(tool: str, decision: str, duration_s: float, redactions: int) None[source]#
Record a completed (or denied) tool call.
- Parameters:
tool – MCP tool name, e.g.
"oct_lint".decision – Pipeline decision:
"allowed","denied", or"requires_confirmation".duration_s – Wall-clock duration in seconds.
redactions – Number of redaction substitutions applied to the output.