fix: mcp stdio transport crashes with unexpected 'host' keyword argument#120
Open
Heliopause0916 wants to merge 3 commits intoopen-webui:mainfrom
Open
fix: mcp stdio transport crashes with unexpected 'host' keyword argument#120Heliopause0916 wants to merge 3 commits intoopen-webui:mainfrom
Heliopause0916 wants to merge 3 commits 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.
Only resolve and pass host/port parameters to mcp_server.run() when using non-stdio transport modes. For stdio transport, these parameters are not needed and their presence can cause issues with the transport initialization.
In stdio mode, the MCP server communicates via local process stdin/stdout, so explicit authentication is unnecessary. Auto-generate a random key for stdlib mode, while still requiring explicit --api-key for HTTP transports. - stdio: auto-generate API key with secrets.token_hex(32) if not provided - streamable-http: enforce --api-key requirement, exit with error if missing
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.
Fixes Bug 2 from #115 — stdio transport crashes with
TypeError: TransportMixin.run_stdio_async() got an unexpected keyword argument 'host'This is a follow-up fix to PR #116, which addressed the empty Authorization header issue but left the stdio transport crash unresolved.
Problem
When running
open-terminal mcp --transport stdio, the command crashes with:Root cause: The
mcp_server.run()call unconditionally passeshostandportarguments regardless of the transport type. FastMCP's stdio transport does not accept these parameters.Solution
Conditionally pass
hostandportonly for non-stdio transports:Testing
Verified on Windows:
Related