quick_query.pyā¢4.34 kB
#!/usr/bin/env python3
"""
Quick Query Tool
Simple command-line tool for single queries
"""
import requests
import sys
from datetime import datetime
def quick_query(query):
"""Send a quick query and display results."""
print("š MCP QUICK QUERY")
print("=" * 50)
print(f"š¤ Query: {query}")
print("=" * 50)
try:
# Check if server is running
health_response = requests.get("http://localhost:8000/api/health", timeout=5)
if health_response.status_code != 200:
print("ā Server not running!")
print("š” Start server: python production_mcp_server.py")
return False
health = health_response.json()
print(f"ā
Server: Ready")
print(f"ā
MongoDB: {'Connected' if health.get('mongodb_connected') else 'Disconnected'}")
print(f"ā
Agents: {health.get('system', {}).get('loaded_agents', 0)} loaded")
print()
# Send query
print("ā³ Processing...")
response = requests.post(
"http://localhost:8000/api/mcp/command",
json={"command": query},
timeout=30
)
if response.status_code == 200:
result = response.json()
print("š RESULT:")
print("-" * 30)
print(f"š¤ Agent: {result.get('agent_used', 'Unknown')}")
print(f"ā
Status: {result.get('status', 'Unknown').upper()}")
if result.get('status') == 'success':
# Math results
if 'result' in result:
print(f"š¢ Answer: {result['result']}")
# Weather results
elif 'city' in result and 'weather_data' in result:
weather = result['weather_data']
print(f"š Location: {result['city']}, {result.get('country', '')}")
print(f"š”ļø Temperature: {weather.get('temperature', 'N/A')}°C")
print(f"āļø Conditions: {weather.get('description', 'N/A')}")
print(f"š§ Humidity: {weather.get('humidity', 'N/A')}%")
print(f"šØ Wind: {weather.get('wind_speed', 'N/A')} m/s")
# Document results
elif 'total_documents' in result:
print(f"š Documents: {result['total_documents']} processed")
if result.get('authors_found'):
print(f"š¤ Authors: {', '.join(result['authors_found'])}")
# General message
elif 'message' in result:
print(f"š¬ Message: {result['message']}")
else:
print(f"ā Error: {result.get('message', 'Unknown error')}")
print(f"š¾ MongoDB: {'ā
Stored' if result.get('stored_in_mongodb') else 'ā Not Stored'}")
print(f"š Time: {datetime.now().strftime('%H:%M:%S')}")
return True
else:
print(f"ā Server error: HTTP {response.status_code}")
return False
except requests.exceptions.ConnectionError:
print("ā Cannot connect to server!")
print("š” Start server: python production_mcp_server.py")
return False
except Exception as e:
print(f"ā Error: {e}")
return False
def main():
"""Main function."""
if len(sys.argv) < 2:
print("š MCP QUICK QUERY TOOL")
print("=" * 50)
print("Usage: python quick_query.py \"Your question here\"")
print()
print("Examples:")
print(" python quick_query.py \"Calculate 25 * 4\"")
print(" python quick_query.py \"What is the weather in Mumbai?\"")
print(" python quick_query.py \"Analyze this text: Hello world\"")
print()
print("š” For interactive mode: python user_friendly_interface.py")
print("š For web interface: http://localhost:8000")
return
query = " ".join(sys.argv[1:])
success = quick_query(query)
if success:
print("\nā
Query completed successfully!")
else:
print("\nā Query failed!")
if __name__ == "__main__":
main()