openwebui-open-terminal/open_terminal/mcp_server.py
hussein 2e1005b60a fix: pass API key as Bearer token in MCP server httpx client
FastMCP.from_fastapi() uses an internal httpx client to call the
FastAPI routes. Without auth headers, every tool call (run_command,
read_file, etc.) hits the verify_api_key guard and returns 401.

Fixes tool calls returning: 'HTTP error 401: Unauthorized - Invalid API key'
2026-04-04 02:02:10 +02:00

15 lines
No EOL
353 B
Python

"""MCP server — exposes every FastAPI endpoint as an MCP tool."""
from fastmcp import FastMCP
from open_terminal.main import app
from open_terminal.env import API_KEY
mcp = FastMCP.from_fastapi(
app=app,
name="Open Terminal",
httpx_client_kwargs={
"headers": {
"Authorization": f"Bearer {API_KEY}",
}
},
)