Skip to main content
Glama
test_setup.pyโ€ข6.22 kB
#!/usr/bin/env python3 """ Test script for NLSQL MCP Server """ import sys import os def test_imports(): """Test all imports work correctly""" print("๐Ÿงช Testing NLSQL MCP Server Setup\n") # Test 1: Basic Python modules print("1. Testing basic imports...") try: import json import logging from pathlib import Path print(" โœ… Basic Python modules imported") except ImportError as e: print(f" โŒ Basic import error: {e}") return False # Test 2: MCP modules print("2. Testing MCP modules...") try: import mcp from mcp.server import Server from mcp.types import Tool print(" โœ… MCP modules imported") except ImportError as e: print(f" โŒ MCP import error: {e}") return False # Test 3: Check nl2sql/nlsql directory exists print("3. Checking nl2sql application directory...") nlsql_dir = Path(__file__).parent.parent / "nlsql" if not nlsql_dir.exists(): nlsql_dir = Path(__file__).parent.parent / "nl2sql" if nlsql_dir.exists(): print(f" โœ… Found nl2sql application at: {nlsql_dir}") # Check key files key_files = ["database_manager.py", "crew_setup.py", "agents.py", "tasks.py"] for file in key_files: if (nlsql_dir / file).exists(): print(f" โœ… Found {file}") else: print(f" โŒ Missing {file}") return False else: print(f" โŒ nl2sql application not found. Please install from:") print(f" https://github.com/tushar-badhwar/nl2sql") return False # Test 4: NLSQL modules import print("4. Testing nlsql module imports...") sys.path.insert(0, str(nlsql_dir)) try: from database_manager import DatabaseManager from crew_setup import NL2SQLCrew from agents import NL2SQLAgents from tasks import NL2SQLTasks print(" โœ… NLSQL modules imported successfully") except ImportError as e: print(f" โŒ NLSQL import error: {e}") return False # Test 5: MCP Server modules print("5. Testing MCP server modules...") try: from nlsql_mcp_server.nlsql_client import NLSQLClient from nlsql_mcp_server.tools import NLSQLTools print(" โœ… MCP server modules imported") except ImportError as e: print(f" โŒ MCP server import error: {e}") return False # Test 6: Create client instance print("6. Testing client instantiation...") try: client = NLSQLClient() tools = NLSQLTools(client) print(" โœ… Client and tools created successfully") print(f" ๐Ÿ“Š Available tools: {len(tools.get_tools())}") except Exception as e: print(f" โŒ Client creation error: {e}") return False # Test 7: Check environment print("7. Checking environment...") if os.getenv("OPENAI_API_KEY"): print(" โœ… OpenAI API key found") else: print(" โš ๏ธ OpenAI API key not set (required for NLโ†’SQL conversion)") return True def test_sample_database(): """Test connection to sample database""" print("\n๐Ÿ€ Testing Sample Database Connection\n") try: from nlsql_mcp_server.nlsql_client import NLSQLClient client = NLSQLClient() result = client.connect_sample_database() if result["success"]: print(" โœ… Sample database connected successfully") print(f" ๐Ÿ“Š Database type: {result.get('database_type', 'Unknown')}") print(f" ๐Ÿ“‹ Tables found: {result.get('table_count', 0)}") if result.get('tables'): print(f" ๐Ÿ“ Table names: {', '.join(result['tables'][:5])}") # Test basic info info = client.get_database_info() if info["success"]: print(" โœ… Database info retrieved successfully") # Disconnect client.disconnect() print(" โœ… Disconnected successfully") return True else: print(f" โŒ Sample database connection failed: {result.get('error')}") return False except Exception as e: print(f" โŒ Sample database test error: {e}") return False def test_tools(): """Test MCP tools""" print("\n๐Ÿ”ง Testing MCP Tools\n") try: from nlsql_mcp_server.nlsql_client import NLSQLClient from nlsql_mcp_server.tools import NLSQLTools client = NLSQLClient() tools = NLSQLTools(client) # List tools tool_list = tools.get_tools() print(f" ๐Ÿ“‹ Found {len(tool_list)} tools:") for tool in tool_list: print(f" - {tool.name}: {tool.description}") # Test a simple tool call (status check) print("\n ๐Ÿงช Testing get_connection_status tool...") import asyncio result = asyncio.run(tools.call_tool("get_connection_status", {})) print(f" โœ… Tool call successful: {result[0].text[:100]}...") return True except Exception as e: print(f" โŒ Tools test error: {e}") return False def main(): """Run all tests""" print("=" * 60) print("NLSQL MCP SERVER - SETUP TEST") print("=" * 60) success = True # Run tests success &= test_imports() success &= test_sample_database() success &= test_tools() # Summary print("\n" + "=" * 60) if success: print("๐ŸŽ‰ ALL TESTS PASSED! Your NLSQL MCP Server is ready to use.") print("\nNext steps:") print("1. Set OPENAI_API_KEY environment variable") print("2. Run: python -m nlsql_mcp_server.server") print("3. Configure your MCP client to use this server") else: print("โŒ SOME TESTS FAILED. Please check the errors above.") print("=" * 60) return success if __name__ == "__main__": sys.exit(0 if main() else 1)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tushar-badhwar/nlsql-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server