Skip to content

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
Varshith-JV-1410:fix/mcp-empty-auth-header-issue-115
Open

fix: mcp command always sends empty Authorization header, causing 401 on all tool calls#116
Varshith-JV-1410 wants to merge 1 commit intoopen-webui:mainfrom
Varshith-JV-1410:fix/mcp-empty-auth-header-issue-115

Conversation

@Varshith-JV-1410
Copy link
Copy Markdown

Summary

Fixes Bug 1 from #115: the mcp command always sent an empty Authorization: Bearer header, causing every internal FastAPI tool call to return 401.

Root Cause

env.py captures API_KEY at module-import time. The mcp CLI command had no --api-key option and never set OPEN_TERMINAL_API_KEY in the environment before importing mcp_server, so API_KEY was always "".

The run command works correctly because it explicitly sets os.environ["OPEN_TERMINAL_API_KEY"] before anything reads it. The mcp command had no equivalent step.

Fix

  • Added --api-key / OPEN_TERMINAL_API_KEY Click option to the mcp command, mirroring the run command.
  • Resolves the key through the full priority chain: CLI flag → env var → _FILE Docker secret → config file.
  • Sets os.environ["OPEN_TERMINAL_API_KEY"] before the deferred from open_terminal.mcp_server import mcp so env.py captures the correct value at import time.

Testing

Verified locally on Windows:

open-terminal mcp --transport streamable-http --host 0.0.0.0 --port 9000 --api-key 12345678

All MCP tool calls succeed with exit code 0. Authorization: Bearer 12345678 confirmed in the httpx client headers.

Also works via env var and config file.

Other changes

  • README.md: added MCP Server section documenting stdio and streamable-http usage.
  • .gitignore: exclude AGENTS.md.

Closes #115 (Bug 1)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

open-terminal mcp always sends empty Authorization header, causing 401 on all tool calls — plus stdio transport crashes with unexpected host kwarg

1 participant