Skip to content

Commit 8b89e34

Browse files
fix(mcp): derive MCP endpoint path dynamically from MCP_SERVER_URL (#1051)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 866f86d commit 8b89e34

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

airbyte/mcp/http_main.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
88
Environment variables:
99
10-
- `MCP_SERVER_URL`: Public base URL (for OIDC redirect callbacks)
10+
- `MCP_SERVER_URL`: Public base URL. Used for OIDC redirect callbacks and to
11+
derive the MCP endpoint mount path (serves at `/` when the URL has a path
12+
prefix, otherwise defaults to `/mcp`).
1113
- `OIDC_CONFIG_URL`: Keycloak OIDC discovery URL (enables auth with all three OIDC vars)
1214
- `OIDC_CLIENT_ID`: OIDC client identifier
1315
- `OIDC_CLIENT_SECRET`: OIDC client secret
@@ -16,8 +18,15 @@
1618
from __future__ import annotations
1719

1820
import logging
21+
import os
22+
from urllib.parse import urlparse
1923

20-
from airbyte.mcp.server import DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT, app
24+
from airbyte.mcp.server import (
25+
DEFAULT_HTTP_HOST,
26+
DEFAULT_HTTP_PORT,
27+
MCP_SERVER_URL_ENV,
28+
app,
29+
)
2130

2231

2332
logger = logging.getLogger(__name__)
@@ -26,16 +35,28 @@
2635
def main() -> None:
2736
"""Start the Airbyte MCP server with HTTP transport."""
2837
logging.basicConfig(level=logging.INFO)
38+
39+
# When deployed behind a path-stripping LB (MCP_SERVER_URL has a path
40+
# component like /cloud-mcp), serve the MCP endpoint at root so the
41+
# public URL is just the base path. Otherwise keep the FastMCP default.
42+
server_url = os.getenv(
43+
MCP_SERVER_URL_ENV,
44+
f"http://localhost:{DEFAULT_HTTP_PORT}",
45+
)
46+
mcp_path = "/" if urlparse(server_url).path.strip("/") else "/mcp"
47+
2948
logger.info(
30-
"Starting Airbyte MCP HTTP server on %s:%d",
49+
"Starting Airbyte MCP HTTP server on %s:%d (mcp_path=%r)",
3150
DEFAULT_HTTP_HOST,
3251
DEFAULT_HTTP_PORT,
52+
mcp_path,
3353
)
3454

3555
app.run(
3656
transport="streamable-http",
3757
host=DEFAULT_HTTP_HOST,
3858
port=DEFAULT_HTTP_PORT,
59+
path=mcp_path,
3960
stateless_http=True,
4061
)
4162

0 commit comments

Comments
 (0)