from services.search import search_web from services.scrape import fetch_url from config import DOCX_URLS # MCP tool: get_docs def register_tools(mcp): @mcp.tool() async def get_docs(query: str, library: str): """ Search the latest docs for a given query and library. Supports: langchain, openai, llama-index """ # Check if library is supported if library not in DOCX_URLS: raise ValueError(f"Library {library} not supported by this tool") # Build site-specific query (search only in chosen docs site) query = f"site:{DOCX_URLS[library]} {query}" results = await search_web(query) if len(results["organic"]) == 0: return "No results found" # Fetch and combine text from all found links text = "" for result in results["organic"]: text += await fetch_url(result["link"]) return text