#!/usr/bin/env python3
"""Quick test script to verify the MCP server can be imported and initialized."""
import sys
import asyncio
def test_imports():
"""Test that all imports work."""
print("Testing imports...")
try:
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import Tool, Resource, Prompt, TextContent, PromptMessage
print("✓ MCP imports successful")
except ImportError as e:
print(f"✗ Import error: {e}")
return False
try:
from weather_api import WeatherAPI
print("✓ Weather API import successful")
except ImportError as e:
print(f"✗ Weather API import error: {e}")
return False
return True
def test_weather_api():
"""Test weather API initialization."""
print("\nTesting Weather API...")
try:
from weather_api import WeatherAPI
api = WeatherAPI()
print("✓ Weather API initialized")
return True
except Exception as e:
print(f"✗ Weather API error: {e}")
return False
def test_server_init():
"""Test MCP server initialization."""
print("\nTesting MCP Server...")
try:
from mcp.server import Server
from weather_api import WeatherAPI
weather_api = WeatherAPI()
app = Server("weather-mcp-server")
print("✓ MCP Server initialized")
return True
except Exception as e:
print(f"✗ Server initialization error: {e}")
import traceback
traceback.print_exc()
return False
async def test_async_functions():
"""Test that async functions can be defined."""
print("\nTesting async functions...")
try:
from mcp.server import Server
from weather_api import WeatherAPI
weather_api = WeatherAPI()
app = Server("weather-mcp-server")
# Test that we can define the handlers
@app.list_tools()
async def list_tools():
return []
print("✓ Async functions can be defined")
return True
except Exception as e:
print(f"✗ Async function error: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all tests."""
print("=" * 50)
print("Weather MCP Server - Quick Test")
print("=" * 50)
results = []
results.append(("Imports", test_imports()))
results.append(("Weather API", test_weather_api()))
results.append(("Server Init", test_server_init()))
results.append(("Async Functions", asyncio.run(test_async_functions())))
print("\n" + "=" * 50)
print("Test Results:")
print("=" * 50)
for name, result in results:
status = "✓ PASS" if result else "✗ FAIL"
print(f"{name}: {status}")
all_passed = all(result for _, result in results)
print("\n" + "=" * 50)
if all_passed:
print("✓ All tests passed! Server should work.")
print("\nNext steps:")
print("1. Make sure Cursor IDE is configured with the MCP server")
print("2. Restart Cursor IDE")
print("3. Try asking: 'What's the weather in New York?'")
else:
print("✗ Some tests failed. Fix errors before using the server.")
print("=" * 50)
return 0 if all_passed else 1
if __name__ == "__main__":
sys.exit(main())