Skip to content

Commit ec9faf2

Browse files
VinciGit00claude
andcommitted
fix: redirect browser visits to the base domain, not /mcp
BrowserRedirectMiddleware now matches human GET/HEAD navigations to the base path (/) instead of /mcp, so the live MCP streamable-HTTP endpoint (/mcp) and /health are left untouched while someone opening the bare domain in a browser is 302'd to the docs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 86344a2 commit ec9faf2

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

.agent/system/project_architecture.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,13 @@ scrapegraph-mcp
570570
served at `/mcp`; health check at `/health`. Used by the Render deployment at
571571
`mcp.scrapegraphai.com`.
572572

573-
**Browser redirect (`/mcp`):**
573+
**Browser redirect (base domain `/`):**
574574
- `/mcp` is the live MCP streamable-HTTP endpoint (JSON-RPC `POST`, SSE `GET`
575-
with `Accept: text/event-stream`).
575+
with `Accept: text/event-stream`) and is left untouched.
576576
- `BrowserRedirectMiddleware` (in `server.py`, HTTP mode only) redirects **only**
577-
human browser navigations — `GET`/`HEAD` on `/mcp` (or `/mcp/`) with
578-
`Accept: text/html` — to the docs (`302`). Real MCP traffic is untouched.
577+
human browser navigations to the base domain — `GET`/`HEAD` on `/` with
578+
`Accept: text/html` — to the docs (`302`). Real MCP traffic (`/mcp`) and the
579+
`/health` endpoint are untouched.
579580
- Target is `https://docs.scrapegraphai.com/services/mcp-server/introduction`,
580581
overridable via the `MCP_DOCS_URL` env var.
581582

src/scrapegraph_mcp/server.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,21 @@
9494
# Matches scrapegraph-py v2 (env.py): https://v2-api.scrapegraphai.com/api
9595
DEFAULT_API_BASE_URL = "https://v2-api.scrapegraphai.com/api"
9696

97-
# Where to send humans who open the /mcp endpoint in a browser.
97+
# Where to send humans who open the base domain in a browser.
9898
DOCS_URL = os.getenv(
9999
"MCP_DOCS_URL",
100100
"https://docs.scrapegraphai.com/services/mcp-server/introduction",
101101
)
102102

103103

104104
class BrowserRedirectMiddleware:
105-
"""Redirect browser visits to the MCP endpoint to the docs.
105+
"""Redirect browser visits to the base domain to the docs.
106106
107-
The ``/mcp`` path is the real MCP streamable-HTTP endpoint: clients POST
108-
JSON-RPC there and open ``GET`` streams with ``Accept: text/event-stream``.
109-
A person pasting ``https://mcp.scrapegraphai.com/mcp`` into a browser sends
110-
``GET`` with ``Accept: text/html`` instead — that (and only that) is
111-
redirected to the documentation so real MCP traffic is left untouched.
107+
The ``/mcp`` path is the real MCP streamable-HTTP endpoint and is left
108+
untouched. A person pasting the base URL ``https://mcp.scrapegraphai.com/``
109+
into a browser sends ``GET`` with ``Accept: text/html`` — that (and only
110+
that) is redirected to the documentation so real MCP traffic and the
111+
``/health`` endpoint are left untouched.
112112
"""
113113

114114
def __init__(self, app, docs_url: str = DOCS_URL) -> None:
@@ -125,7 +125,7 @@ async def __call__(self, scope, receive, send) -> None:
125125
def _is_browser_navigation(self, scope) -> bool:
126126
if scope["method"] not in ("GET", "HEAD"):
127127
return False
128-
if scope["path"].rstrip("/") != "/mcp":
128+
if scope["path"].rstrip("/") != "":
129129
return False
130130
accept = ""
131131
for name, value in scope.get("headers", []):

0 commit comments

Comments
 (0)