|
import os |
|
import asyncio |
|
import httpx |
|
from tavily import TavilyClient |
|
from mcp.server.fastmcp import FastMCP |
|
import nest_asyncio |
|
from dotenv import load_dotenv |
|
|
|
|
|
nest_asyncio.apply() |
|
|
|
|
|
|
|
|
|
|
|
tavily_client = TavilyClient(api_key=TAVILY_API_KEY) |
|
mcp = FastMCP("tavily_search") |
|
|
|
|
|
@mcp.tool() |
|
async def search_autism(query: str) -> dict: |
|
"""Performs a Tavily web search for information about autism.""" |
|
try: |
|
|
|
response = tavily_client.search( |
|
query=query, |
|
max_results=5, |
|
search_depth="advanced", |
|
topic="general", |
|
name="live_search", |
|
description="""Using the latest information from reputable online sources, provide a concise AI-generated overview of the query related to autism spectrum """, |
|
include_answer=True |
|
) |
|
return { |
|
"results": response.get("results", []), |
|
"answer": response.get("answer", "") |
|
} |
|
except Exception as e: |
|
return {"error": f"Search failed: {str(e)}"} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
asyncio.run(main()) |
|
|