this directory have the tool that used to get docs
هذا الالتزام موجود في:
28
tools/get_docs.py
Normal file
28
tools/get_docs.py
Normal file
@@ -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
|
المرجع في مشكلة جديدة
حظر مستخدم