Skip to content

Commit 3de4f72

Browse files
authored
fix: Make sure "enabled" is set correctly in resource updates (#1589)
* fix: Make sure "enabled" is set correctly in resource udpates Without this, the update will always fail because creation of the return object will raise a validation error. Branch: FixResourceUpdate Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * fix: Make sure the DB tool has lazily evaluated before copying it Branch: FixResourceUpdate Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> --------- Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 937c1fe commit 3de4f72

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mcpgateway/services/resource_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def _convert_resource_to_read(self, resource: DbResource) -> ResourceRead:
257257
resource_dict["created_at"] = getattr(resource, "created_at", resource_dict.get("created_at"))
258258
resource_dict["updated_at"] = getattr(resource, "updated_at", resource_dict.get("updated_at"))
259259
resource_dict["is_active"] = getattr(resource, "is_active", resource_dict.get("is_active"))
260+
resource_dict["enabled"] = getattr(resource, "enabled", resource_dict.get("enabled"))
260261

261262
# Compute aggregated metrics from the resource's metrics list.
262263
total = len(resource.metrics) if hasattr(resource, "metrics") and resource.metrics is not None else 0

mcpgateway/services/tool_service.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ def _convert_tool_to_read(self, tool: DbTool, include_metrics: bool = True) -> T
366366
Returns:
367367
ToolRead: The Pydantic model representing the tool, including aggregated metrics and new fields.
368368
"""
369+
# NOTE: This serves two purposes:
370+
# 1. It determines whether to decode auth (used later)
371+
# 2. It forces the tool object to lazily evaluate (required before copy)
372+
auth_type_set = tool.auth_type and tool.auth_value
373+
374+
# Copy the dict from the tool
369375
tool_dict = tool.__dict__.copy()
370376
tool_dict.pop("_sa_instance_state", None)
371377

@@ -377,7 +383,7 @@ def _convert_tool_to_read(self, tool: DbTool, include_metrics: bool = True) -> T
377383
tool_dict["annotations"] = tool.annotations or {}
378384

379385
# Only decode auth if auth_type is set
380-
if tool.auth_type and tool.auth_value:
386+
if auth_type_set:
381387
decoded_auth_value = decode_auth(tool.auth_value)
382388
if tool.auth_type == "basic":
383389
decoded_bytes = base64.b64decode(decoded_auth_value["Authorization"].split("Basic ")[1])

0 commit comments

Comments
 (0)