From aaffa47e2cb1232b4a84c666e5b5ba24a2cfded8 Mon Sep 17 00:00:00 2001 From: Mihai Criveti Date: Fri, 12 Dec 2025 20:47:41 +0000 Subject: [PATCH] fix: propagate app_user_email when global context already exists When invoke_tool receives an existing plugin_global_context from middleware, the user email was not being propagated to the global context. This caused plugins to receive user: null in their GlobalContext. This fix ensures the user email is always propagated to the global context when available, enabling security plugins to properly track which user made each request. Closes #1550 Supersedes #1551 Co-authored-by: Ilia Manolov Signed-off-by: Mihai Criveti --- mcpgateway/services/tool_service.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mcpgateway/services/tool_service.py b/mcpgateway/services/tool_service.py index 5616e0ff4..3f10890d9 100644 --- a/mcpgateway/services/tool_service.py +++ b/mcpgateway/services/tool_service.py @@ -1466,6 +1466,9 @@ async def invoke_tool( gateway_id = getattr(tool, "gateway_id", None) if gateway_id and isinstance(gateway_id, str): global_context.server_id = gateway_id + # Propagate user email to global context for plugin access + if app_user_email and isinstance(app_user_email, str): + global_context.user = app_user_email else: # Create new context (fallback when middleware didn't run) # Use correlation ID from context if available, otherwise generate new one