Skip to content

Commit 8eb28cd

Browse files
committed
linting
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
1 parent d3feca6 commit 8eb28cd

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

mcpgateway/services/server_service.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def _convert_server_to_read(self, server: DbServer) -> ServerRead:
221221
"""
222222
server_dict = server.__dict__.copy()
223223
server_dict.pop("_sa_instance_state", None)
224-
224+
225225
# Compute aggregated metrics from server.metrics in a single pass; default to 0/None when no records exist.
226226
total = 0
227227
successful = 0
@@ -230,27 +230,27 @@ def _convert_server_to_read(self, server: DbServer) -> ServerRead:
230230
max_rt = None
231231
sum_rt = 0.0
232232
last_time = None
233-
233+
234234
if hasattr(server, "metrics") and server.metrics:
235235
for m in server.metrics:
236236
total += 1
237237
if m.is_success:
238238
successful += 1
239239
else:
240240
failed += 1
241-
241+
242242
# Track min/max response times
243243
if min_rt is None or m.response_time < min_rt:
244244
min_rt = m.response_time
245245
if max_rt is None or m.response_time > max_rt:
246246
max_rt = m.response_time
247-
247+
248248
sum_rt += m.response_time
249-
249+
250250
# Track last execution time
251251
if last_time is None or m.timestamp > last_time:
252252
last_time = m.timestamp
253-
253+
254254
failure_rate = (failed / total) if total > 0 else 0.0
255255
avg_rt = (sum_rt / total) if total > 0 else None
256256

@@ -593,17 +593,14 @@ async def list_servers(self, db: Session, include_inactive: bool = False, tags:
593593
query = query.where(json_contains_expr(db, DbServer.tags, tags, match_any=True))
594594

595595
servers = db.execute(query).scalars().all()
596-
596+
597597
# Fetch all team names
598598
team_ids = [s.team_id for s in servers if s.team_id]
599599
team_map = {}
600600
if team_ids:
601-
teams = db.execute(
602-
select(DbEmailTeam.id, DbEmailTeam.name)
603-
.where(DbEmailTeam.id.in_(team_ids), DbEmailTeam.is_active.is_(True))
604-
).all()
601+
teams = db.execute(select(DbEmailTeam.id, DbEmailTeam.name).where(DbEmailTeam.id.in_(team_ids), DbEmailTeam.is_active.is_(True))).all()
605602
team_map = {team.id: team.name for team in teams}
606-
603+
607604
result = []
608605
for s in servers:
609606
s.team = team_map.get(s.team_id) if s.team_id else None
@@ -676,17 +673,14 @@ async def list_servers_for_user(
676673
query = query.offset(skip).limit(limit)
677674

678675
servers = db.execute(query).scalars().all()
679-
680-
# Fetch all team names
676+
677+
# Fetch all team names
681678
server_team_ids = [s.team_id for s in servers if s.team_id]
682679
team_map = {}
683680
if server_team_ids:
684-
teams = db.execute(
685-
select(DbEmailTeam.id, DbEmailTeam.name)
686-
.where(DbEmailTeam.id.in_(server_team_ids), DbEmailTeam.is_active.is_(True))
687-
).all()
681+
teams = db.execute(select(DbEmailTeam.id, DbEmailTeam.name).where(DbEmailTeam.id.in_(server_team_ids), DbEmailTeam.is_active.is_(True))).all()
688682
team_map = {team.id: team.name for team in teams}
689-
683+
690684
result = []
691685
for s in servers:
692686
s.team = team_map.get(s.team_id) if s.team_id else None

mcpgateway/services/tool_service.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ async def shutdown(self) -> None:
287287
await self._event_service.shutdown()
288288
logger.info("Tool service shutdown complete")
289289

290-
291290
async def get_top_tools(self, db: Session, limit: Optional[int] = 5) -> List[TopPerformer]:
292291
"""Retrieve the top-performing tools based on execution count.
293292
@@ -309,21 +308,13 @@ async def get_top_tools(self, db: Session, limit: Optional[int] = 5) -> List[Top
309308
- last_execution: Timestamp of the last execution, or None if no metrics.
310309
"""
311310

312-
success_rate = case(
313-
(
314-
func.count(ToolMetric.id) > 0,
315-
func.sum(
316-
case((ToolMetric.is_success.is_(True), 1), else_=0)
317-
).cast(Float) * 100 / func.count(ToolMetric.id)
318-
),
319-
else_=None
320-
)
311+
success_rate = case((func.count(ToolMetric.id) > 0, func.sum(case((ToolMetric.is_success.is_(True), 1), else_=0)).cast(Float) * 100 / func.count(ToolMetric.id)), else_=None) # pylint: disable=not-callable
321312

322313
query = (
323314
select(
324315
DbTool.id,
325316
DbTool.name,
326-
func.count(ToolMetric.id).label("execution_count"),
317+
func.count(ToolMetric.id).label("execution_count"), # pylint: disable=not-callable
327318
func.avg(ToolMetric.response_time).label("avg_response_time"),
328319
success_rate.label("success_rate"),
329320
func.max(ToolMetric.timestamp).label("last_execution"),
@@ -390,7 +381,7 @@ def _convert_tool_to_read(self, tool: DbTool, include_metrics: bool = True) -> T
390381
"token": "********" if decoded_auth_value["Authorization"] else None,
391382
}
392383
elif tool.auth_type == "authheaders":
393-
# Get first key
384+
# Get first key
394385
first_key = next(iter(decoded_auth_value))
395386
tool_dict["auth"] = {
396387
"auth_type": "authheaders",
@@ -414,7 +405,6 @@ def _convert_tool_to_read(self, tool: DbTool, include_metrics: bool = True) -> T
414405
tool_dict["team"] = getattr(tool, "team", None)
415406
return ToolRead.model_validate(tool_dict)
416407

417-
418408
async def _record_tool_metric(self, db: Session, tool: DbTool, start_time: float, success: bool, error_message: Optional[str]) -> None:
419409
"""
420410
Records a metric for a tool invocation.
@@ -958,14 +948,14 @@ async def list_tools_for_user(
958948
# query = query.offset(skip).limit(limit)
959949

960950
tools = db.execute(query).scalars().all()
961-
951+
962952
# Batch fetch team names for all tools at once
963953
tool_team_ids = {getattr(t, "team_id", None) for t in tools if getattr(t, "team_id", None)}
964954
team_name_map = {}
965955
if tool_team_ids:
966956
teams = db.query(EmailTeam.id, EmailTeam.name).filter(EmailTeam.id.in_(tool_team_ids), EmailTeam.is_active.is_(True)).all()
967957
team_name_map = {team.id: team.name for team in teams}
968-
958+
969959
result = []
970960
for t in tools:
971961
team_name = team_name_map.get(getattr(t, "team_id", None))

0 commit comments

Comments
 (0)