mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-02 21:59:02 -05:00
[PR #23458] feat: Forward MCP initialize instructions to system prompt and add admin toggle
#130873
Reference in New Issue
Block a user
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23458
Author: @jmleksan
Created: 4/6/2026
Status: 🔄 Open
Base:
dev← Head:feat/MCP-instructions📝 Commits (2)
3064a73Implement MCP server instructions handling: append instructions to system prompt in chat payload and add configuration option in AddToolServerModal.4f12b14fix review notes📊 Changes
3 files changed (+67 additions, -5 deletions)
View changed files
📝
backend/open_webui/utils/mcp/client.py(+8 -1)📝
backend/open_webui/utils/middleware.py(+19 -0)📝
src/lib/components/AddToolServerModal.svelte(+40 -4)📄 Description
Pull Request Checklist
Note to first-time contributors: Please open a discussion post in Discussions to discuss your idea/fix with the community before creating a pull request, and describe your changes before submitting a pull request.
This is to ensure large feature PRs are discussed with the community first, before starting work on it. If the community does not want this feature or it is not relevant for Open WebUI as a project, it can be identified in the discussion before working on the feature and submitting the PR.
Before submitting, make sure you've checked the following:
devbranch. PRs targetingmainwill be immediately closed.devto ensure no unrelated commits (e.g. frommain) are included. Push updates to the existing PR branch instead of closing and reopening.Changelog Entry
Description
When an admin-configured MCP tool server is used in a chat, Open WebUI now captures optional
instructionsfrom the MCPinitializeresponse (InitializeResult.instructions) and appends them to the system message in the chat payload (same pattern as other system-prompt injections). This lets MCP servers document how models should use their tools without duplicating everything in per-tool descriptions.Per-connection opt-out is available via
config.forward_mcp_instructions(default true when omitted). The admin Add/Edit Connection modal (MCP) exposes this under Advanced as “Include MCP server instructions” with a tooltip explaining behavior; import/export JSON includes the flag for MCP connections.Added
initializeinstructionsinto the chat system prompt when the server is connected for a request and forwarding is enabled.forward_mcp_instructions(boolean; default true).AddToolServerModal.svelte(label + switch + tooltip); wired through save/load/import/export for MCP connections.Changed
MCPClientstoresserver_instructionsfrom the post-initializeresult and clears it on disconnect.Security
instructionsstring; disabling forwarding (forward_mcp_instructions: false) avoids injecting server-provided text into the model context.Breaking Changes
forward_mcp_instructionsis omitted (treated as true).Additional Information
backend/open_webui/utils/mcp/client.py(readInitializeResult.instructions),backend/open_webui/utils/middleware.py(append viaadd_or_update_system_messagewhen enabled),src/lib/components/AddToolServerModal.svelte(UI +config.forward_mcp_instructions).mcpSDK types that already includeInitializeResult.instructions.forward_mcp_instructionsand the UI toggle would help operators; link the docs PR here when opened.Screenshots or Videos
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.