Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/scrapegraph_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
from smithery.decorators import smithery
from starlette.requests import Request
from starlette.responses import JSONResponse, RedirectResponse
from starlette.types import ASGIApp, Receive, Scope, Send

# Configure logging
logging.basicConfig(
Expand Down Expand Up @@ -111,18 +112,18 @@ class BrowserRedirectMiddleware:
``/health`` endpoint are left untouched.
"""

def __init__(self, app, docs_url: str = DOCS_URL) -> None:
def __init__(self, app: ASGIApp, docs_url: str = DOCS_URL) -> None:
self.app = app
self.docs_url = docs_url

async def __call__(self, scope, receive, send) -> None:
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if scope["type"] == "http" and self._is_browser_navigation(scope):
response = RedirectResponse(self.docs_url, status_code=302)
await response(scope, receive, send)
return
await self.app(scope, receive, send)

def _is_browser_navigation(self, scope) -> bool:
def _is_browser_navigation(self, scope: Scope) -> bool:
if scope["method"] not in ("GET", "HEAD"):
return False
if scope["path"].rstrip("/") != "":
Expand Down Expand Up @@ -219,6 +220,7 @@ def __init__(self, api_key: str, base_url: Optional[str] = None) -> None:
"SGAI-APIKEY": api_key,
"Content-Type": "application/json",
"accept": "application/json",
"User-Agent": f"scrapegraph-mcp/{MCP_SERVER_VERSION}",
"X-SDK-Version": f"scrapegraph-mcp@{MCP_SERVER_VERSION}",
}
self.client = httpx.Client(timeout=httpx.Timeout(_api_timeout_s()))
Expand Down
Loading