mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #21090] [CLOSED] feat(tools): optionally forward OpenWebUI user and chat headers to tool servers #25924
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21090
Author: @notfolder
Created: 2/1/2026
Status: ❌ Closed
Base:
dev← Head:feature/dev-add-user-info-mcp-call📝 Commits (9)
fe6783cMerge pull request #19030 from open-webui/devfc05e0aMerge pull request #19405 from open-webui/deve3faec6Merge pull request #19416 from open-webui/dev9899293Merge pull request #19448 from open-webui/dev140605eMerge pull request #19462 from open-webui/dev6f1486fMerge pull request #19466 from open-webui/devd95f533Merge pull request #19729 from open-webui/deva7271530.6.43 (#20093)905caf9feat: add user info headers support in mcp tool calling.📊 Changes
2 files changed (+18 additions, -0 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+9 -0)📝
backend/open_webui/utils/tools.py(+9 -0)📄 Description
Description
This pull request adds an optional mechanism to forward Open WebUI user and chat context as HTTP headers when invoking external tool servers.
Currently, Open WebUI forwards user-related headers (e.g. user ID, chat ID) when proxying requests to OpenAI-compatible LLM endpoints, but the same contextual information is not available to external Tool / OpenAPI servers.
This makes it difficult for tool servers to implement per-user authorization, auditing, rate limiting, or request tracing.
This change introduces a strictly opt-in, backward-compatible enhancement that allows operators to forward selected Open WebUI context headers to tool servers via an environment variable.
⸻
Added
• Optional forwarding of the following HTTP headers when executing tools:
• X-OpenWebUI-User-Id
• X-OpenWebUI-Chat-Id
• New environment variable to explicitly enable this behavior:
• ENABLE_FORWARD_USER_INFO_HEADERS_TO_TOOLS
⸻
Changed
• Updated tool execution HTTP request construction in:
• backend/open_webui/utils/middleware.py
• backend/open_webui/utils/tools.py
• The tool execution flow now conditionally injects user/chat headers only when explicitly enabled.
⸻
Fixed
• N/A
⸻
Security
• This feature is disabled by default.
• User-related headers are forwarded only when the operator explicitly enables the environment variable.
• No behavior change occurs for existing installations unless the feature is enabled.
• This mirrors the existing security model used for OpenAI-compatible proxy requests.
⸻
Breaking Changes
• None.
This change is fully backward-compatible and opt-in.
⸻
Additional Information
• This implementation intentionally mirrors the existing behavior controlled by ENABLE_FORWARD_USER_INFO_HEADERS used in the OpenAI proxy path, ensuring conceptual and operational consistency.
• The change is limited to the tool execution layer and does not affect:
• Tool CRUD APIs
• Frontend behavior
• Existing tool definitions
• Manual testing was performed using a local tool server that logs incoming HTTP headers to verify correct forwarding behavior when enabled and no change when disabled.
Related context:
• Tool servers often require user/chat context for access control and observability.
• This change enables such use cases without imposing new defaults.
⸻
Screenshots or Videos
• Not applicable (backend-only change; verified via HTTP request inspection).
⸻
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the
Contributor License Agreement (CLA),
and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.