test_server.pyโข2.1 kB
#!/usr/bin/env python3
"""
Simple test script for the MCP Testing Harness
"""
import asyncio
import logging
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from core.server import MCPServer
from core.testing import MCPServerTester
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
async def test_basic_server():
"""Test the basic MCP server functionality."""
print("๐ Testing MCP Server")
print("=" * 30)
# Create server
server = MCPServer(host="localhost", port=8000, debug=True)
# Create tester
tester = MCPServerTester()
print("๐ก Starting server...")
# Start server in background
server_task = asyncio.create_task(server.start())
# Wait for server to start
await asyncio.sleep(2)
print("โ
Server started!")
try:
# Test connection
print("\n๐ง Testing connection...")
result = await tester.test_server_connection("localhost", 8000)
print(f"Connection test: {'โ
PASS' if result.success else 'โ FAIL'}")
if not result.success:
print(f"Error: {result.error_message}")
# Test tools
print("\n๐ง Testing tools...")
tools_result = await tester.test_server_tools("localhost", 8000)
print(f"Tools test: {'โ
PASS' if tools_result.success else 'โ FAIL'}")
if tools_result.success:
print(f"Found {tools_result.details.get('tools_count', 0)} tools")
except Exception as e:
print(f"โ Error: {e}")
finally:
# Stop server
print("\n๐ Stopping server...")
await server.stop()
server_task.cancel()
try:
await server_task
except asyncio.CancelledError:
pass
print("\nโ
Test completed!")
if __name__ == "__main__":
asyncio.run(test_basic_server())