Add Stack Exchange ZIMs and wire Kiwix search into MCP server
- kiwix_download.sh: add Ask Ubuntu, Super User, Unix & Linux SE, Server Fault - mcp_server.py: add kiwix_search tool — models can now query all offline ZIMs - local-ai-setup.sh: pass KIWIX_URL env to MCP container, add kiwix dependency https://claude.ai/code/session_012gDnantBmFTWZGCiKyjazx
This commit is contained in:
@@ -16,6 +16,7 @@ GITEA_URL = os.getenv("GITEA_URL", "http://gitea:3000")
|
||||
GITEA_TOKEN = os.getenv("GITEA_TOKEN", "")
|
||||
GITHUB_TOKEN= os.getenv("GITHUB_TOKEN","")
|
||||
RAG_URL = os.getenv("RAG_URL", "http://rag-server:8001")
|
||||
KIWIX_URL = os.getenv("KIWIX_URL", "http://kiwix:80")
|
||||
|
||||
mcp = FastMCP("local-dev-tools")
|
||||
|
||||
@@ -180,6 +181,27 @@ def github_api(method: str, endpoint: str, body: str = "") -> str:
|
||||
except Exception:
|
||||
return r.text
|
||||
|
||||
# ── Kiwix search ──────────────────────────────────────────────────────────────
|
||||
import re as _re
|
||||
|
||||
@mcp.tool()
|
||||
def kiwix_search(query: str, books: str = "") -> str:
|
||||
"""Search offline ZIM content via Kiwix (Wikipedia, Stack Overflow, etc).
|
||||
books: optional comma-separated book names to filter, e.g. 'stackoverflow.com_en_all'.
|
||||
Leave empty to search all ZIMs."""
|
||||
params = {"pattern": query, "lang": ""}
|
||||
if books:
|
||||
params["books"] = books
|
||||
try:
|
||||
r = httpx.get(f"{KIWIX_URL}/search", params=params, timeout=15)
|
||||
# strip HTML tags to get plain text
|
||||
text = _re.sub(r"<[^>]+>", " ", r.text)
|
||||
text = _re.sub(r"&[a-zA-Z]+;", " ", text)
|
||||
text = _re.sub(r"\s{2,}", "\n", text).strip()
|
||||
return text[:6000] or "(no results)"
|
||||
except Exception as e:
|
||||
return f"[kiwix error] {e}"
|
||||
|
||||
# ── RAG ingest ────────────────────────────────────────────────────────────────
|
||||
@mcp.tool()
|
||||
def ingest_repo(url: str, name: str = "", branch: str = "main") -> str:
|
||||
|
||||
Reference in New Issue
Block a user