fix: mcp command always sends empty Authorization header, causing 401 on all tool calls#116
Open
Varshith-JV-1410 wants to merge 1 commit intoopen-webui:mainfrom
Conversation
The `mcp` CLI command had no `--api-key` option and never set `OPEN_TERMINAL_API_KEY` in the environment before importing `mcp_server`. Because `env.py` captures `API_KEY` at module-import time, the header was always `Bearer ` (empty), causing every internal FastAPI call to return 401. Fix: add `--api-key` / `OPEN_TERMINAL_API_KEY` option to the `mcp` command (mirroring the `run` command) and resolve it through the full chain (CLI flag -> env var -> `_FILE` Docker secret -> config file), setting `os.environ["OPEN_TERMINAL_API_KEY"]` before the deferred import of `mcp_server` so `env.py` picks up the correct value. Also add MCP server usage to README.md and exclude AGENTS.md from git.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Bug 1 from #115: the
mcpcommand always sent an emptyAuthorization: Bearerheader, causing every internal FastAPI tool call to return 401.Root Cause
env.pycapturesAPI_KEYat module-import time. ThemcpCLI command had no--api-keyoption and never setOPEN_TERMINAL_API_KEYin the environment before importingmcp_server, soAPI_KEYwas always"".The
runcommand works correctly because it explicitly setsos.environ["OPEN_TERMINAL_API_KEY"]before anything reads it. Themcpcommand had no equivalent step.Fix
--api-key/OPEN_TERMINAL_API_KEYClick option to themcpcommand, mirroring theruncommand._FILEDocker secret → config file.os.environ["OPEN_TERMINAL_API_KEY"]before the deferredfrom open_terminal.mcp_server import mcpsoenv.pycaptures the correct value at import time.Testing
Verified locally on Windows:
All MCP tool calls succeed with exit code 0.
Authorization: Bearer 12345678confirmed in the httpx client headers.Also works via env var and config file.
Other changes
README.md: added MCP Server section documentingstdioandstreamable-httpusage..gitignore: excludeAGENTS.md.Closes #115 (Bug 1)