[PR #116] fix: mcp command always sends empty Authorization header, causing 401 on all tool calls #126

Open
opened 2026-10-18 21:11:01 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-terminal/pull/116
Author: @Varshith-JV-1410
Created: 4/23/2026
Status: 🔄 Open

Base: main ← Head: fix/mcp-empty-auth-header-issue-115


📝 Commits (2)

  • 89f666d fix: mcp command sends empty Authorization header (#115)
  • 8fa2930 docs: add MCP server section to README

📊 Changes

4 files changed (+54 additions, -1 deletions)

View changed files

📝 .gitignore (+3 -0)
➖ .python-version (+0 -1)
📝 README.md (+31 -0)
📝 open_terminal/cli.py (+20 -0)

📄 Description

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.

Closes #115 (Bug 1)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-terminal/pull/116 **Author:** [@Varshith-JV-1410](https://github.com/Varshith-JV-1410) **Created:** 4/23/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/mcp-empty-auth-header-issue-115` --- ### 📝 Commits (2) - [`89f666d`](https://github.com/open-webui/open-terminal/commit/89f666d15d46bb99de2d8a27e174784d4b78a2b5) fix: mcp command sends empty Authorization header (#115) - [`8fa2930`](https://github.com/open-webui/open-terminal/commit/8fa2930a0b868882c04eebed7d1c8c34bc30e8d9) docs: add MCP server section to README ### 📊 Changes **4 files changed** (+54 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+3 -0) ➖ `.python-version` (+0 -1) 📝 `README.md` (+31 -0) 📝 `open_terminal/cli.py` (+20 -0) </details> ### 📄 Description ## 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. Closes #115 (Bug 1) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
open-webui/open-terminal#126
No description provided.