Skip to content

MetricsToolCallInterceptor

Rasuvaeff\Yii3McpTelemetryBridge\MetricsToolCallInterceptor

ClassRasuvaeff\Yii3McpTelemetryBridgeSource

Counts every MCP tools/call into mcp_tool_calls_total{tool,outcome} and samples its duration into mcp_tool_call_duration_seconds{tool}. Duration is the wall time of the wrapped chain measured with hrtime(); outcomes are distinguished by the counter's outcome label, not by a separate duration series, to keep histogram cardinality low.

The outcome label follows the core's shared CallOutcome vocabulary: success, rejected (a client-visible refusal — rate limit, RBAC, budget) or error (an unexpected failure) — so alert thresholds on error rate are not polluted by expected rejections. A tool exception is recorded and rethrown unchanged, so the MCP error envelope the agent sees is byte-identical with and without this bridge.

Methods

intercept()

php
intercept(Interceptor\ToolCallContext $context, callable $next): mixed