From ce8cd063802bd2575299a5ce94eeaa66332f4166 Mon Sep 17 00:00:00 2001 From: Sirajmx Date: Thu, 23 Apr 2026 15:50:00 +0530 Subject: [PATCH 1/3] mcp fix --- src/ad_seller/interfaces/mcp_server.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ad_seller/interfaces/mcp_server.py b/src/ad_seller/interfaces/mcp_server.py index 6395d7f..bceb1ee 100644 --- a/src/ad_seller/interfaces/mcp_server.py +++ b/src/ad_seller/interfaces/mcp_server.py @@ -39,6 +39,9 @@ "and interact with buyer agents. On first connection, check setup status " "and offer the guided setup wizard if configuration is incomplete." ), + # When mounted at /mcp in FastAPI, streamable_http_path="/" makes the + # endpoint resolve to /mcp (not /mcp/mcp which is the default behaviour). + streamable_http_path="/", ) From 5f293f010345aa05598c197f116652fe94a847cb Mon Sep 17 00:00:00 2001 From: Sirajmx Date: Thu, 23 Apr 2026 16:28:00 +0530 Subject: [PATCH 2/3] mcp host fix --- src/ad_seller/interfaces/mcp_server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ad_seller/interfaces/mcp_server.py b/src/ad_seller/interfaces/mcp_server.py index bceb1ee..30daa4e 100644 --- a/src/ad_seller/interfaces/mcp_server.py +++ b/src/ad_seller/interfaces/mcp_server.py @@ -39,9 +39,13 @@ "and interact with buyer agents. On first connection, check setup status " "and offer the guided setup wizard if configuration is incomplete." ), - # When mounted at /mcp in FastAPI, streamable_http_path="/" makes the - # endpoint resolve to /mcp (not /mcp/mcp which is the default behaviour). + # streamable_http_path="/" so that when mounted at /mcp in FastAPI the + # endpoint resolves to /mcp (not /mcp/mcp which is the default). streamable_http_path="/", + # host="0.0.0.0" disables the auto DNS-rebinding protection that FastMCP + # applies when host is 127.0.0.1/localhost. That protection blocks requests + # from Cloud Run (Host header is the public *.run.app domain) with 421. + host="0.0.0.0", ) From 597f33759a8a70b36d63e2ae2e09ca5d05ff4c47 Mon Sep 17 00:00:00 2001 From: Sirajmx Date: Thu, 23 Apr 2026 16:45:19 +0530 Subject: [PATCH 3/3] cors and trust proxy header middleware --- src/ad_seller/interfaces/api/main.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/ad_seller/interfaces/api/main.py b/src/ad_seller/interfaces/api/main.py index 26a9aec..eb57e78 100644 --- a/src/ad_seller/interfaces/api/main.py +++ b/src/ad_seller/interfaces/api/main.py @@ -17,7 +17,9 @@ from typing import Any, Optional from fastapi import Depends, FastAPI, HTTPException +from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel +from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware logger = logging.getLogger(__name__) @@ -31,6 +33,7 @@ version="1.0.0", contact={"name": "IAB Tech Lab", "url": "https://iabtechlab.com"}, license_info={"name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0"}, + root_path_in_servers=False, openapi_tags=[ {"name": "Core", "description": "Health check and API root"}, {"name": "Products", "description": "Product catalog browsing"}, @@ -65,6 +68,21 @@ # Lifecycle: start/stop background services # ============================================================================= +# Trust X-Forwarded-Proto / X-Forwarded-For from Cloud Run so that Starlette +# generates https:// redirects instead of http:// ones behind the TLS proxy. +app.add_middleware(ProxyHeadersMiddleware, trusted_hosts="*") + +# Allow all browser-based clients — buyer UIs, claude.ai, SSP dashboards, etc. +# The MCP Streamable HTTP protocol requires CORS for browser-originated requests. +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"], + allow_headers=["*"], + allow_credentials=False, + expose_headers=["*"], +) + _mcp_server_ref = None