From 2526d7f45afb7fa778bd4d48d3c9dd15cd5f4456 Mon Sep 17 00:00:00 2001 From: MohamedAlawakey Date: Tue, 30 Sep 2025 01:18:34 +0300 Subject: [PATCH] this directory have the tool that used to get docs --- tools/get_docs.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tools/get_docs.py diff --git a/tools/get_docs.py b/tools/get_docs.py new file mode 100644 index 0000000..c9efb4c --- /dev/null +++ b/tools/get_docs.py @@ -0,0 +1,28 @@ +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