|
12 | 12 | Hooks: tool_pre_invoke, tool_post_invoke |
13 | 13 | """ |
14 | 14 |
|
| 15 | +# Future |
15 | 16 | from __future__ import annotations |
16 | 17 |
|
17 | | -import time |
| 18 | +# Standard |
18 | 19 | from collections import deque |
19 | 20 | from dataclasses import dataclass |
20 | | -from typing import Any, Deque, Dict, Optional |
| 21 | +import time |
| 22 | +from typing import Any, Deque, Dict |
21 | 23 |
|
| 24 | +# Third-Party |
22 | 25 | from pydantic import BaseModel |
23 | 26 |
|
| 27 | +# First-Party |
24 | 28 | from mcpgateway.plugins.framework import ( |
25 | 29 | Plugin, |
26 | 30 | PluginConfig, |
@@ -92,7 +96,6 @@ def __init__(self, config: PluginConfig) -> None: |
92 | 96 | async def tool_pre_invoke(self, payload: ToolPreInvokePayload, context: PluginContext) -> ToolPreInvokeResult: |
93 | 97 | tool = payload.name |
94 | 98 | st = _get_state(tool) |
95 | | - cfg = _cfg_for(self._cfg, tool) |
96 | 99 | now = _now() |
97 | 100 | # Close breaker if cooldown elapsed |
98 | 101 | if st.open_until and now >= st.open_until: |
@@ -147,10 +150,12 @@ async def tool_post_invoke(self, payload: ToolPostInvokePayload, context: Plugin |
147 | 150 |
|
148 | 151 | if should_open and not st.open_until: |
149 | 152 | st.open_until = now + max(1, int(cfg.cooldown_seconds)) |
150 | | - return ToolPostInvokeResult(metadata={ |
151 | | - "circuit_calls_in_window": calls, |
152 | | - "circuit_failures_in_window": len(st.failures), |
153 | | - "circuit_failure_rate": round(failure_rate, 3), |
154 | | - "circuit_consecutive_failures": st.consecutive_failures, |
155 | | - "circuit_open_until": st.open_until or 0.0, |
156 | | - }) |
| 153 | + return ToolPostInvokeResult( |
| 154 | + metadata={ |
| 155 | + "circuit_calls_in_window": calls, |
| 156 | + "circuit_failures_in_window": len(st.failures), |
| 157 | + "circuit_failure_rate": round(failure_rate, 3), |
| 158 | + "circuit_consecutive_failures": st.consecutive_failures, |
| 159 | + "circuit_open_until": st.open_until or 0.0, |
| 160 | + } |
| 161 | + ) |
0 commit comments