Skip to content

Commit b4f5ed9

Browse files
author
Olivier Gintrand
committed
fix: tools_include/exclude filter not applied immediately on gateway edit
Bug 1 — Timing: update_gateway() applied the OLD tools_include filter (from DB) instead of the NEW one (from the edit form) because _apply_tool_filters was called at L2381 but gateway.tools_include was only updated at L2515. New tools matching the updated filter were never imported, and tools deselected by the old filter were deleted as stale. Fix: read effective_include/exclude from gateway_update (falling back to gateway's existing value) BEFORE calling _apply_tool_filters. Bug 2 — Clearing: setting tools_include to None when the form field was empty made the service skip the update (is not None check), so a filter could never be removed once set. Fix: admin handler defaults to [] (empty list) instead of None for cleared fields; service converts [] to None (clear) while preserving None as 'not provided' (keep existing).
1 parent 5c661ab commit b4f5ed9

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

mcpgateway/admin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12370,8 +12370,9 @@ async def admin_edit_gateway(
1237012370
passthrough_headers = None
1237112371

1237212372
# Handle tools_include filter
12373+
# Use [] (empty list) to signal "user cleared the filter" vs None (not provided)
1237312374
tools_include_str = str(form.get("tools_include", ""))
12374-
tools_include: Optional[List[str]] = None
12375+
tools_include: Optional[List[str]] = []
1237512376
if tools_include_str and tools_include_str.strip():
1237612377
try:
1237712378
tools_include = orjson.loads(tools_include_str)
@@ -12380,7 +12381,7 @@ async def admin_edit_gateway(
1238012381

1238112382
# Handle tools_exclude filter
1238212383
tools_exclude_str = str(form.get("tools_exclude", ""))
12383-
tools_exclude: Optional[List[str]] = None
12384+
tools_exclude: Optional[List[str]] = []
1238412385
if tools_exclude_str and tools_exclude_str.strip():
1238512386
try:
1238612387
tools_exclude = orjson.loads(tools_exclude_str)

mcpgateway/services/gateway_service.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,8 +2377,11 @@ async def update_gateway(
23772377
client_key=update_client_key,
23782378
)
23792379

2380-
# Apply tool include/exclude filters (fnmatch glob patterns)
2381-
tools = _apply_tool_filters(tools, gateway.tools_include, gateway.tools_exclude)
2380+
# Apply NEW tool filters so this edit takes effect immediately
2381+
# (must read from gateway_update BEFORE persisting to gateway)
2382+
effective_include = gateway_update.tools_include if gateway_update.tools_include is not None else gateway.tools_include
2383+
effective_exclude = gateway_update.tools_exclude if gateway_update.tools_exclude is not None else gateway.tools_exclude
2384+
tools = _apply_tool_filters(tools, effective_include, effective_exclude)
23822385

23832386
new_tool_names = [tool.name for tool in tools]
23842387
new_resource_uris = [resource.uri for resource in resources]
@@ -2512,10 +2515,12 @@ async def update_gateway(
25122515
gateway.gateway_mode = gateway_update.gateway_mode
25132516

25142517
# Update tool filters if provided
2518+
# An empty list [] means "user cleared the filter" → store None
2519+
# None means "not provided in this update" → keep existing value
25152520
if hasattr(gateway_update, "tools_include") and gateway_update.tools_include is not None:
2516-
gateway.tools_include = gateway_update.tools_include
2521+
gateway.tools_include = gateway_update.tools_include if gateway_update.tools_include else None
25172522
if hasattr(gateway_update, "tools_exclude") and gateway_update.tools_exclude is not None:
2518-
gateway.tools_exclude = gateway_update.tools_exclude
2523+
gateway.tools_exclude = gateway_update.tools_exclude if gateway_update.tools_exclude else None
25192524

25202525
# Update metadata fields
25212526
gateway.updated_at = datetime.now(timezone.utc)

0 commit comments

Comments
 (0)