cinematch-ai / test_mcp.py
dbadeev's picture
Upload 24 files
da524e0 verified
Raw
History Blame Contribute Delete
2.28 kB
# test_mcp.py
import asyncio
from tools.client import MCPToolManager
async def main():
print("🔌 Testing MCP Integration...")
manager = MCPToolManager()
# Подключаем локальный сервер поиска (он будет дергать Modal внутри)
# Убедитесь, что путь правильный относительно запуска
await manager.connect_to_server("vectordb", "tools/mcp_server_vectordb.py")
print("\n📋 Listing available tools via MCP:")
tools = await manager.list_tools()
for t in tools:
print(f" - {t.name}: {t.description}")
print("\n🔍 Testing search_plots tool via MCP protocol...")
try:
# Реальный вызов через MCP -> Client -> Server -> Modal
result = await manager.call_tool("search_plots", {
"query": "In a distant future, Earth has been abandoned and covered in trash. "
"A small waste-collecting robot has been left behind to clean up the planet. "
"He spends his days compacting garbage into cubes, but he's completely alone "
"and dreams of companionship. One day, a sleek probe robot arrives from space, "
"and he falls in love with her, leading to an adventure across the galaxy.",
"limit": 5
})
# ✅ ИСПРАВЛЕНО: Правильное извлечение содержимого из CallToolResult
if hasattr(result, 'content') and result.content:
# result.content - это список TextContent объектов
# Берём текст из первого элемента
content_text = result.content[0].text
print(f"✅ Result received:\n{content_text}")
else:
# Fallback на случай неожиданного формата
print(f"✅ Result received: {result}")
# print(f"✅ Result received: {result[:200]}...") # Печатаем начало JSON
except Exception as e:
import traceback
print(f"❌ Error: {e}")
traceback.print_exc()
finally:
await manager.cleanup()
if __name__ == "__main__":
asyncio.run(main())