Skip to content

fix: mcp stdio transport crashes with unexpected 'host' keyword argument#120

Open
Heliopause0916 wants to merge 3 commits intoopen-webui:mainfrom
Heliopause0916:fix/mcp-empty-auth-header-issue-115
Open

fix: mcp stdio transport crashes with unexpected 'host' keyword argument#120
Heliopause0916 wants to merge 3 commits intoopen-webui:mainfrom
Heliopause0916:fix/mcp-empty-auth-header-issue-115

Conversation

@Heliopause0916
Copy link
Copy Markdown

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:

TypeError: TransportMixin.run_stdio_async() got an unexpected keyword argument 'host'

Root cause: The mcp_server.run() call unconditionally passes host and port arguments regardless of the transport type. FastMCP's stdio transport does not accept these parameters.

# Before: Always passes host/port
mcp_server.run(transport=transport, host=host, port=port)

Solution

Conditionally pass host and port only for non-stdio transports:

# Only resolve host/port for non-stdio transport modes
if transport != "stdio":
    host = host or cfg.get("host", "0.0.0.0")
    port = port if port is not None else cfg.get("port", 8000)

# ... (API key resolution logic) ...

# Conditionally call run() with appropriate parameters
if transport == "stdio":
    mcp_server.run(transport="stdio")
else:
    mcp_server.run(transport=transport, host=host, port=port)

Testing

Verified on Windows:

# stdio transport - now works correctly
open-terminal mcp --transport stdio --api-key test123

# streamable-http transport - still works as expected  
open-terminal mcp --transport streamable-http --host 0.0.0.0 --port 9000 --api-key test123

Related

0xOb5k-J and others added 2 commits April 23, 2026 15:01
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.
@Heliopause0916 Heliopause0916 changed the title fix: mcp stdio transport crashes with unexpected 'host' keyword argument (issue #115) fix: mcp stdio transport crashes with unexpected 'host' keyword argument May 5, 2026
@Heliopause0916 Heliopause0916 marked this pull request as ready for review May 5, 2026 16:20
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
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