Option C Tools
Loading...
Searching...
No Matches
oct.mcp.metrics.McpMetrics Class Reference

Public Member Functions

None __init__ (self, "CollectorRegistry | None" registry=None)
None start_server (self, int port)
None record_call (self, str tool, str decision, float duration_s, int redactions)
None record_rate_limit_hit (self, str tool)
None record_validation_failure (self, str tool)

Protected Attributes

 _registry = registry if registry is not None else REGISTRY
Counter _tool_calls
Histogram _tool_duration
Counter _rate_limit_hits
Counter _redactions
Counter _validation_failures

Detailed Description

Prometheus instrumentation for the oct-mcp pipeline.

All record methods are no-ops when ``prometheus_client`` is absent.
Instantiate once per server session and pass into :class:`ServerState`.

Definition at line 84 of file metrics.py.

Constructor & Destructor Documentation

◆ __init__()

None oct.mcp.metrics.McpMetrics.__init__ ( self,
"CollectorRegistry | None" registry = None )
Build the metric vectors.

Parameters
----------
registry
    Prometheus :class:`CollectorRegistry` to register metrics on.
    ``None`` (default) uses the module-level global ``REGISTRY``,
    which is what ``prometheus_client.start_http_server()`` exposes
    on ``/metrics`` by default. Pass a private
    ``CollectorRegistry()`` for tests or multi-tenant scenarios
    that need isolation from other ``McpMetrics`` instances.

Definition at line 91 of file metrics.py.

Member Function Documentation

◆ record_call()

None oct.mcp.metrics.McpMetrics.record_call ( self,
str tool,
str decision,
float duration_s,
int redactions )
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.

Definition at line 177 of file metrics.py.

◆ record_rate_limit_hit()

None oct.mcp.metrics.McpMetrics.record_rate_limit_hit ( self,
str tool )
Increment the rate-limit rejection counter for *tool*.

Definition at line 208 of file metrics.py.

◆ record_validation_failure()

None oct.mcp.metrics.McpMetrics.record_validation_failure ( self,
str tool )
Increment the validation-failure counter for *tool*.

Definition at line 217 of file metrics.py.

◆ start_server()

None oct.mcp.metrics.McpMetrics.start_server ( self,
int port )
Start the Prometheus ``/metrics`` HTTP server on *port*.

Runs in a **daemon** background thread so it does not block the
MCP event loop. Silently no-ops when ``prometheus_client`` is
absent.

Parameters
----------
port
    TCP port to bind. Must be in the range 1–65535.

Definition at line 147 of file metrics.py.

Here is the call graph for this function:

Member Data Documentation

◆ _rate_limit_hits

Counter oct.mcp.metrics.McpMetrics._rate_limit_hits
protected
Initial value:
= Counter(
"oct_mcp_rate_limit_hits_total",
"Tool calls rejected by the rate limiter",
["tool"],
registry=self._registry,
)

Definition at line 124 of file metrics.py.

◆ _redactions

Counter oct.mcp.metrics.McpMetrics._redactions
protected
Initial value:
= Counter(
"oct_mcp_redactions_total",
"Redaction substitutions applied to tool output",
["tool"],
registry=self._registry,
)

Definition at line 130 of file metrics.py.

◆ _registry

oct.mcp.metrics.McpMetrics._registry = registry if registry is not None else REGISTRY
protected

Definition at line 110 of file metrics.py.

◆ _tool_calls

Counter oct.mcp.metrics.McpMetrics._tool_calls
protected
Initial value:
= Counter(
"oct_mcp_tool_calls_total",
"Total MCP tool calls processed by oct-mcp",
["tool", "decision"],
registry=self._registry,
)

Definition at line 112 of file metrics.py.

◆ _tool_duration

Histogram oct.mcp.metrics.McpMetrics._tool_duration
protected
Initial value:
= Histogram(
"oct_mcp_tool_duration_seconds",
"Wall-clock time from tool call receipt to response (seconds)",
["tool"],
registry=self._registry,
)

Definition at line 118 of file metrics.py.

◆ _validation_failures

Counter oct.mcp.metrics.McpMetrics._validation_failures
protected
Initial value:
= Counter(
"oct_mcp_validation_failures_total",
"Tool calls rejected by input validation",
["tool"],
registry=self._registry,
)

Definition at line 136 of file metrics.py.


The documentation for this class was generated from the following file: