|
7 | 7 |
|
8 | 8 | Environment variables: |
9 | 9 |
|
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`). |
11 | 13 | - `OIDC_CONFIG_URL`: Keycloak OIDC discovery URL (enables auth with all three OIDC vars) |
12 | 14 | - `OIDC_CLIENT_ID`: OIDC client identifier |
13 | 15 | - `OIDC_CLIENT_SECRET`: OIDC client secret |
|
16 | 18 | from __future__ import annotations |
17 | 19 |
|
18 | 20 | import logging |
| 21 | +import os |
| 22 | +from urllib.parse import urlparse |
19 | 23 |
|
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 | +) |
21 | 30 |
|
22 | 31 |
|
23 | 32 | logger = logging.getLogger(__name__) |
|
26 | 35 | def main() -> None: |
27 | 36 | """Start the Airbyte MCP server with HTTP transport.""" |
28 | 37 | 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 | + |
29 | 48 | logger.info( |
30 | | - "Starting Airbyte MCP HTTP server on %s:%d", |
| 49 | + "Starting Airbyte MCP HTTP server on %s:%d (mcp_path=%r)", |
31 | 50 | DEFAULT_HTTP_HOST, |
32 | 51 | DEFAULT_HTTP_PORT, |
| 52 | + mcp_path, |
33 | 53 | ) |
34 | 54 |
|
35 | 55 | app.run( |
36 | 56 | transport="streamable-http", |
37 | 57 | host=DEFAULT_HTTP_HOST, |
38 | 58 | port=DEFAULT_HTTP_PORT, |
| 59 | + path=mcp_path, |
39 | 60 | stateless_http=True, |
40 | 61 | ) |
41 | 62 |
|
|
0 commit comments