geronimo-pericoli commited on
Commit
2d5c108
·
verified ·
1 Parent(s): 766a2fb

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +51 -6
server.py CHANGED
@@ -1,17 +1,62 @@
1
- # server.py
2
  from mcp.server.fastmcp import FastMCP
3
  import os
 
4
 
5
  port = int(os.getenv("PORT", 7860))
6
  mcp = FastMCP("OnBase", port=port)
7
 
8
  @mcp.tool()
9
- def get_document_info(id: int):
10
- return {
11
- "doc_id": id,
12
- "doc_name": "Document Name",
13
- # ... resto de tus campos
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  if __name__ == "__main__":
17
  mcp.run("sse")
 
 
1
  from mcp.server.fastmcp import FastMCP
2
  import os
3
+ import aiohttp # Necesario para las peticiones HTTP asíncronas
4
 
5
  port = int(os.getenv("PORT", 7860))
6
  mcp = FastMCP("OnBase", port=port)
7
 
8
  @mcp.tool()
9
+ async def search_tavily(
10
+ query: str,
11
+ days: int = 7,
12
+ max_results: int = 1,
13
+ include_answer: bool = False
14
+ ) -> dict:
15
+ """Perform a web search using the Tavily API.
16
+
17
+ Args:
18
+ query: Search query string (required)
19
+ days: Restrict search to last N days (default: 7)
20
+ max_results: Maximum results to return (default: 1)
21
+ include_answer: Include direct answer (default: False)
22
+
23
+ Returns:
24
+ dict: Search results from Tavily
25
+ """
26
+ # Obtener la API key de las variables de entorno
27
+ api_key = os.environ.get('TAVILY_API_KEY')
28
+ if not api_key:
29
+ raise ValueError("TAVILY_API_KEY environment variable not set")
30
+
31
+ headers = {
32
+ "Content-Type": "application/json"
33
  }
34
+
35
+ payload = {
36
+ "query": query,
37
+ "search_depth": "basic",
38
+ "max_results": max_results,
39
+ "days": days if days else None,
40
+ "include_answer": include_answer
41
+ }
42
+
43
+ try:
44
+ async with aiohttp.ClientSession() as session:
45
+ async with session.post(
46
+ "https://api.tavily.com/search",
47
+ headers=headers,
48
+ json=payload,
49
+ params={"api_key": api_key} # Alternativa para enviar la key
50
+ ) as response:
51
+ response.raise_for_status()
52
+ return await response.json()
53
+
54
+ except Exception as e:
55
+ return {
56
+ "error": str(e),
57
+ "status": "failed",
58
+ "query": query
59
+ }
60
 
61
  if __name__ == "__main__":
62
  mcp.run("sse")