server_health_check.py•2.55 kB
#!/usr/bin/env python3
import subprocess
import time
import os
import signal
import sys
def validate_server():
"""
Validates that the UniProt MCP server starts correctly without errors.
This is a health check utility that:
1. Starts the MCP server process
2. Verifies it launches successfully
3. Checks for any error output
4. Cleanly terminates the process
Returns:
bool: True if server starts successfully, False otherwise
"""
print("Performing UniProt MCP server health check...")
# Start the server process
server_process = subprocess.Popen(
[sys.executable, "server.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
try:
# Wait for a moment to allow any immediate errors to show up
time.sleep(2)
# Check if the process is still running
if server_process.poll() is None:
print("✅ Server started successfully and is running!")
# Check for any error output
stderr_output = server_process.stderr.read(1024) # Non-blocking read
if stderr_output and len(stderr_output.strip()) > 0:
print("⚠️ Server started but has error output:")
print(stderr_output)
else:
print("✅ No error output detected")
return True
else:
# Process exited - check return code and error output
return_code = server_process.poll()
stderr_output = server_process.stderr.read()
print(f"❌ Server process exited with return code {return_code}")
if stderr_output:
print("Error output:")
print(stderr_output)
return False
finally:
# Ensure we terminate the server process
if server_process.poll() is None:
# Process is still running, terminate it
try:
server_process.terminate()
# Give it some time to terminate gracefully
time.sleep(0.5)
if server_process.poll() is None:
# Force kill if still running
server_process.kill()
except Exception as e:
print(f"Error terminating server process: {str(e)}")
if __name__ == "__main__":
success = validate_server()
# Return appropriate exit code
sys.exit(0 if success else 1)