|
|
#!/usr/bin/env python3 |
|
|
""" |
|
|
Quick test script for MCP server tools. |
|
|
Run: python test_tools.py |
|
|
""" |
|
|
|
|
|
import asyncio |
|
|
import json |
|
|
from pprint import pprint |
|
|
|
|
|
from mcp_server import tools |
|
|
|
|
|
|
|
|
async def main(): |
|
|
print("🔍 Testing MCP server tools...\n") |
|
|
|
|
|
# 1. Ping (simulated, since it's just "ok") |
|
|
print("1️⃣ ping → ok") |
|
|
print(" ✅", "ok\n") |
|
|
|
|
|
# 2. Search documents with a trivial AQL (read-only) |
|
|
try: |
|
|
aql = "FOR d IN riksdagen LIMIT 1 RETURN d" |
|
|
print("2️⃣ search_documents...") |
|
|
result = await asyncio.to_thread(tools.search_documents, aql) |
|
|
print(" ✅ rows:", result["row_count"]) |
|
|
except Exception as e: |
|
|
print(" ❌ search_documents failed:", e) |
|
|
print() |
|
|
|
|
|
# 3. Run AQL query directly |
|
|
try: |
|
|
aql = "FOR d IN riksdagen LIMIT 1 RETURN d" |
|
|
print("3️⃣ run_aql_query...") |
|
|
rows = await asyncio.to_thread(tools.run_aql_query, aql) |
|
|
print(" ✅ got", len(rows), "rows") |
|
|
except Exception as e: |
|
|
print(" ❌ run_aql_query failed:", e) |
|
|
print() |
|
|
|
|
|
# 4. Vector search (Chroma) |
|
|
try: |
|
|
print("4️⃣ vector_search_talks...") |
|
|
hits = await asyncio.to_thread(tools.vector_search, "klimatpolitik", 3) |
|
|
print(f" ✅ got {len(hits)} hits") |
|
|
if hits: |
|
|
print(" →", hits[0]) |
|
|
except Exception as e: |
|
|
print(" ❌ vector_search_talks failed:", e) |
|
|
print() |
|
|
|
|
|
# 5. Fetch documents |
|
|
try: |
|
|
print("5️⃣ fetch_documents (demo id)...") |
|
|
# Adjust a known _id if needed; using a dummy for now |
|
|
docs = await asyncio.to_thread(tools.fetch_documents, ["riksdagen/1"]) |
|
|
print(" ✅ got", len(docs), "docs") |
|
|
except Exception as e: |
|
|
print(" ❌ fetch_documents failed:", e) |
|
|
print() |
|
|
|
|
|
# 6. Arango search |
|
|
try: |
|
|
print("6️⃣ arango_search...") |
|
|
result = await asyncio.to_thread(tools.arango_search, "budget", 3) |
|
|
print(" ✅ got", len(result.get("results", [])), "hits") |
|
|
except Exception as e: |
|
|
print(" ❌ arango_search failed:", e) |
|
|
print() |
|
|
|
|
|
print("🏁 Done.\n") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
asyncio.run(main())
|
|
|
|