-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
48 lines (38 loc) · 1.47 KB
/
server.py
File metadata and controls
48 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""MCP server for DuckDuckGo web searches, compatible with AgentCore Runtime."""
from mcp.server.fastmcp import FastMCP
from ddgs import DDGS
mcp = FastMCP(
"ddgs-search",
instructions=(
"Web search using DuckDuckGo. Use ddgs_search for general queries "
"and ddgs_news for recent news."
),
host="0.0.0.0",
port=8000,
stateless_http=True,
)
@mcp.tool()
def ddgs_search(query: str, max_results: int = 10, region: str = "wt-wt") -> list[dict]:
"""Search the web using DuckDuckGo.
Args:
query: Search query string
max_results: Maximum number of results (default 10)
region: Region code (default "wt-wt" for worldwide). Examples: "us-en", "uk-en", "de-de"
"""
with DDGS() as ddgs:
results = list(ddgs.text(query, max_results=max_results, region=region))
return results
@mcp.tool()
def ddgs_news(query: str, max_results: int = 10, region: str = "wt-wt", timelimit: str | None = None) -> list[dict]:
"""Search recent news using DuckDuckGo.
Args:
query: News search query
max_results: Maximum number of results (default 10)
region: Region code (default "wt-wt" for worldwide)
timelimit: Time limit - "d" (day), "w" (week), "m" (month), or None for all
"""
with DDGS() as ddgs:
results = list(ddgs.news(query, max_results=max_results, region=region, timelimit=timelimit))
return results
if __name__ == "__main__":
mcp.run(transport="streamable-http")