66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Test FastAPI Server
|
|
This script tests the FastAPI server implementation for Maya MCP.
|
|
Run this script outside of Maya to test the server.
|
|
|
|
Usage:
|
|
python test_fastapi_server.py [port]
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
# Add parent directory to path
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
def test_fastapi_server(port=4551): # Use different port 4551
|
|
"""Test FastAPI server"""
|
|
print("===================================")
|
|
print("Maya MCP FastAPI Server Test")
|
|
print("===================================")
|
|
|
|
try:
|
|
# Import FastAPI server
|
|
print("Importing FastAPI server module...")
|
|
import fastapi_server
|
|
print("FastAPI server module imported successfully")
|
|
|
|
# Start server
|
|
print("\nStarting FastAPI server...")
|
|
host = "127.0.0.1"
|
|
|
|
print(f"Starting server on {host}:{port}...")
|
|
print("Server will run in a separate process. Press Ctrl+C to stop.")
|
|
|
|
# Run server directly using uvicorn
|
|
import uvicorn
|
|
uvicorn.run(fastapi_server.app, host=host, port=port)
|
|
|
|
return True
|
|
except ImportError as e:
|
|
print(f"Error importing FastAPI server: {e}")
|
|
print("Make sure FastAPI and UVicorn are installed:")
|
|
print("pip install fastapi uvicorn")
|
|
return False
|
|
except Exception as e:
|
|
print(f"Error testing FastAPI server: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
# Get port from command line arguments
|
|
port = 4551 # Default port
|
|
if len(sys.argv) > 1:
|
|
try:
|
|
port = int(sys.argv[1])
|
|
except ValueError:
|
|
print(f"Invalid port: {sys.argv[1]}")
|
|
print("Using default port: 4551")
|
|
|
|
test_fastapi_server(port)
|