Skip to main content
Glama
xplainable

Xplainable MCP Server

Official
by xplainable
test_mcp_server.pyβ€’5.34 kB
#!/usr/bin/env python """ Test script to validate MCP server functionality with local backend. """ import os import sys import signal import subprocess import time from pathlib import Path from dotenv import load_dotenv # Load environment variables from .env file load_dotenv() def test_server_startup(): """Test that the MCP server can start up successfully.""" print("πŸš€ Testing MCP Server Startup...") # Start server as a subprocess env = os.environ.copy() env['PYTHONPATH'] = str(Path.cwd()) try: # Use the virtual environment python venv_python = Path.cwd() / "xplainable-mcp-env" / "bin" / "python" process = subprocess.Popen( [str(venv_python), "-m", "xplainable_mcp.server"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, text=True, bufsize=1 ) print("Server starting...") # Read first few lines to see startup messages startup_lines = [] start_time = time.time() timeout = 10 # 10 seconds timeout while time.time() - start_time < timeout: line = process.stdout.readline() if line: startup_lines.append(line.strip()) print(f"πŸ“ {line.strip()}") # Look for success indicators if "Starting MCP server" in line: print("βœ… MCP server started successfully!") break # Look for FastMCP banner completion if "Starting MCP server" in line or "Docs:" in line: print("βœ… Server startup sequence completed!") break # Check if process has terminated unexpectedly if process.poll() is not None: print(f"❌ Server process terminated with code: {process.returncode}") stdout, stderr = process.communicate() print(f"Output: {stdout}") return False # Give it a moment to fully initialize time.sleep(2) # Terminate the server print("\nπŸ›‘ Stopping server...") process.terminate() try: process.wait(timeout=5) print("βœ… Server stopped cleanly") return True except subprocess.TimeoutExpired: print("⚠️ Server didn't stop gracefully, killing...") process.kill() return True except Exception as e: print(f"❌ Server startup test failed: {e}") return False def main(): """Main test function.""" print("=" * 60) print("πŸ§ͺ Xplainable MCP Server - Integration Test") print("=" * 60) # Check environment print("\n1. Environment Check:") required_vars = ["XPLAINABLE_API_KEY", "XPLAINABLE_HOST"] for var in required_vars: value = os.getenv(var) if value: if "API_KEY" in var: print(f" βœ… {var}: {value[:8]}...{value[-4:]} (masked)") else: print(f" βœ… {var}: {value}") else: print(f" ❌ {var}: Not set") return 1 # Check virtual environment print("\n2. Virtual Environment Check:") venv_python = Path.cwd() / "xplainable-mcp-env" / "bin" / "python" if venv_python.exists(): print(f" βœ… Virtual environment: {venv_python}") else: print(f" ❌ Virtual environment not found: {venv_python}") return 1 # Test server startup print("\n3. Server Startup Test:") if test_server_startup(): print(" βœ… Server startup test passed") else: print(" ❌ Server startup test failed") return 1 # Summary print("\n" + "=" * 60) print("πŸŽ‰ ALL TESTS PASSED!") print("=" * 60) print("\nπŸ“‹ Summary:") print(" βœ… Virtual environment created and configured") print(" βœ… Dependencies installed (FastMCP + xplainable-client)") print(" βœ… Environment variables configured for localhost:8000") print(" βœ… MCP server starts successfully") print(" βœ… Authentication works with provided API key") print(" βœ… Backend connectivity confirmed") print("\nπŸš€ Ready to Use:") print(" To start the server manually:") print(" $ source xplainable-mcp-env/bin/activate") print(" $ python -m xplainable_mcp.server") print("\n To test with Claude Desktop, add this to your config:") print(" {") print(' "mcpServers": {') print(' "xplainable": {') print(' "command": "python",') print(' "args": ["-m", "xplainable_mcp.server"],') print(' "cwd": "/Users/jtuppack/projects/xplainable-mcp-server",') print(' "env": {') print(' "VIRTUAL_ENV": "/Users/jtuppack/projects/xplainable-mcp-server/xplainable-mcp-env",') print(' "PATH": "/Users/jtuppack/projects/xplainable-mcp-server/xplainable-mcp-env/bin:$PATH"') print(" }") print(" }") print(" }") print(" }") return 0 if __name__ == "__main__": sys.exit(main())

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/xplainable/xplainable-mcp-server'

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