To enable multi-user isolation in Open WebUI, create a custom Function that injects the Open WebUI __user__ context into MCP calls. This ensures that each user's conversation history is isolated even when using a shared Gemini Notebook account.
Implementation Steps:
- Navigate to Workspace → Functions → Create in Open WebUI.
- Paste the Python function implementation (see code example).
- Save and enable the function.
Note: The function relies on Open WebUI's ability to automatically inject a __user__ dictionary containing id, email, name, and role into the function call.
import httpx
class Tools:
def __init__(self):
# Adjust to your MCP server URL
self.mcp_url = "http://localhost:8000"
async def query_notebook(
self,
notebook_id: str,
question: str,
__user__: dict = {}
) -> str:
"""Ask a question about a NotebookLM notebook."""
user_id = __user__.get("id", "anonymous")
async with httpx.AsyncClient(timeout=120) as client:
response = await client.post(
f"{self.mcp_url}/mcp",
json={
"tool": "notebook_query",
"arguments": {
"notebook_id": notebook_id,
"query": question,
"user_id": user_id,
}
}
)
result = response.json()
if result.get("status") == "success":
return result.get("answer", "No answer generated")
else:
return f"Error: {result.get('error', 'Unknown error')}"
# Additional methods like list_notebooks, new_conversation, and check_rate_limit
# follow the same pattern of extracting user_id from __user__.