Skip to content

Commit 1e13c09

Browse files
authored
Merge pull request #21 from ScrapeGraphAI/feat/user-agent-header
feat: send User-Agent header on API requests
2 parents ec9faf2 + a1ef44e commit 1e13c09

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/scrapegraph_mcp/server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
from smithery.decorators import smithery
8484
from starlette.requests import Request
8585
from starlette.responses import JSONResponse, RedirectResponse
86+
from starlette.types import ASGIApp, Receive, Scope, Send
8687

8788
# Configure logging
8889
logging.basicConfig(
@@ -111,18 +112,18 @@ class BrowserRedirectMiddleware:
111112
``/health`` endpoint are left untouched.
112113
"""
113114

114-
def __init__(self, app, docs_url: str = DOCS_URL) -> None:
115+
def __init__(self, app: ASGIApp, docs_url: str = DOCS_URL) -> None:
115116
self.app = app
116117
self.docs_url = docs_url
117118

118-
async def __call__(self, scope, receive, send) -> None:
119+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
119120
if scope["type"] == "http" and self._is_browser_navigation(scope):
120121
response = RedirectResponse(self.docs_url, status_code=302)
121122
await response(scope, receive, send)
122123
return
123124
await self.app(scope, receive, send)
124125

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

0 commit comments

Comments
 (0)