Skip to content

Commit a2c56d2

Browse files
authored
add proxy. (#1266)
1 parent 4bf7ce9 commit a2c56d2

File tree

1 file changed

+14
-2
lines changed
  • mcp_servers/duckduckgo_atlas/src/duckduckgo_mcp_server

1 file changed

+14
-2
lines changed

mcp_servers/duckduckgo_atlas/src/duckduckgo_mcp_server/server.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828

2929
logger = logging.getLogger(__name__)
3030

31+
32+
def _get_proxy_url() -> Optional[str]:
33+
"""Build proxy URL from PROXY_USERNAME and PROXY_PASSWORD env vars."""
34+
username = os.environ.get("PROXY_USERNAME")
35+
password = os.environ.get("PROXY_PASSWORD")
36+
if username and password:
37+
return f"http://{username}:{password}@p.webshare.io:80/"
38+
return None
39+
40+
3141
# DuckDuckGo does not require authentication, but we follow the auth extraction
3242
# pattern for consistency with other MCP servers.
3343

@@ -109,7 +119,8 @@ async def search(
109119

110120
await ctx.info(f"Searching DuckDuckGo for: {query}")
111121

112-
async with httpx.AsyncClient() as client:
122+
proxy = _get_proxy_url()
123+
async with httpx.AsyncClient(proxy=proxy) as client:
113124
response = await client.post(
114125
self.BASE_URL, data=data, headers=self.HEADERS, timeout=30.0
115126
)
@@ -174,7 +185,8 @@ async def fetch_and_parse(self, url: str, ctx: Context) -> str:
174185
try:
175186
await ctx.info(f"Fetching content from: {url}")
176187

177-
async with httpx.AsyncClient() as client:
188+
proxy = _get_proxy_url()
189+
async with httpx.AsyncClient(proxy=proxy) as client:
178190
response = await client.get(
179191
url,
180192
headers={

0 commit comments

Comments
 (0)