Update README and app.py: change title to 'Web Search MCP', enhance rate limit to 360 requests/hour, and improve logging for rate limit and content extraction.
Browse files
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: π
|
4 |
colorFrom: red
|
5 |
colorTo: green
|
@@ -7,6 +7,7 @@ sdk: gradio
|
|
7 |
sdk_version: 5.36.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
# Web Search MCP Server
|
|
|
1 |
---
|
2 |
+
title: Web Search MCP
|
3 |
emoji: π
|
4 |
colorFrom: red
|
5 |
colorTo: green
|
|
|
7 |
sdk_version: 5.36.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
short_description: Search and extract web content for LLM ingestion
|
11 |
---
|
12 |
|
13 |
# Web Search MCP Server
|
app.py
CHANGED
@@ -37,7 +37,7 @@ HEADERS = {"X-API-KEY": SERPER_API_KEY, "Content-Type": "application/json"}
|
|
37 |
# Rate limiting
|
38 |
storage = MemoryStorage()
|
39 |
limiter = MovingWindowRateLimiter(storage)
|
40 |
-
rate_limit = parse("
|
41 |
|
42 |
|
43 |
async def search_web(
|
@@ -97,8 +97,8 @@ async def search_web(
|
|
97 |
try:
|
98 |
# Check rate limit
|
99 |
if not await limiter.hit(rate_limit, "global"):
|
100 |
-
print(f"
|
101 |
-
return "Error: Rate limit exceeded. Please try again later (limit:
|
102 |
|
103 |
# Select endpoint based on search type
|
104 |
endpoint = (
|
@@ -149,6 +149,9 @@ async def search_web(
|
|
149 |
continue
|
150 |
|
151 |
successful_extractions += 1
|
|
|
|
|
|
|
152 |
|
153 |
# Format the chunk based on search type
|
154 |
if search_type == "news":
|
@@ -190,6 +193,9 @@ async def search_web(
|
|
190 |
result = "\n---\n".join(chunks)
|
191 |
summary = f"Successfully extracted content from {successful_extractions} out of {len(results)} {search_type} results for query: '{query}'\n\n---\n\n"
|
192 |
|
|
|
|
|
|
|
193 |
return summary + result
|
194 |
|
195 |
except Exception as e:
|
|
|
37 |
# Rate limiting
|
38 |
storage = MemoryStorage()
|
39 |
limiter = MovingWindowRateLimiter(storage)
|
40 |
+
rate_limit = parse("360/hour")
|
41 |
|
42 |
|
43 |
async def search_web(
|
|
|
97 |
try:
|
98 |
# Check rate limit
|
99 |
if not await limiter.hit(rate_limit, "global"):
|
100 |
+
print(f"[{datetime.now().isoformat()}] Rate limit exceeded")
|
101 |
+
return "Error: Rate limit exceeded. Please try again later (limit: 500 requests per hour)."
|
102 |
|
103 |
# Select endpoint based on search type
|
104 |
endpoint = (
|
|
|
149 |
continue
|
150 |
|
151 |
successful_extractions += 1
|
152 |
+
print(
|
153 |
+
f"[{datetime.now().isoformat()}] Successfully extracted content from {meta['link']}"
|
154 |
+
)
|
155 |
|
156 |
# Format the chunk based on search type
|
157 |
if search_type == "news":
|
|
|
193 |
result = "\n---\n".join(chunks)
|
194 |
summary = f"Successfully extracted content from {successful_extractions} out of {len(results)} {search_type} results for query: '{query}'\n\n---\n\n"
|
195 |
|
196 |
+
print(
|
197 |
+
f"[{datetime.now().isoformat()}] Extraction complete: {successful_extractions}/{len(results)} successful for query '{query}'"
|
198 |
+
)
|
199 |
return summary + result
|
200 |
|
201 |
except Exception as e:
|