test_server.py•2.43 kB
#!/usr/bin/env python3
"""Simple test to verify the MCP server can be imported and initialized."""
import sys
from pathlib import Path
def test_import():
"""Test that the server module can be imported."""
try:
from rembg_mcp.server import RembgMCPServer
print("✓ Successfully imported RembgMCPServer")
return True
except ImportError as e:
print(f"✗ Failed to import RembgMCPServer: {e}")
return False
def test_server_creation():
"""Test that the server can be created."""
try:
from rembg_mcp.server import RembgMCPServer
server = RembgMCPServer()
print("✓ Successfully created RembgMCPServer instance")
return True
except Exception as e:
print(f"✗ Failed to create RembgMCPServer: {e}")
return False
def test_tools_listing():
"""Test that tools can be listed."""
try:
from rembg_mcp.server import RembgMCPServer
import asyncio
async def check_tools():
server = RembgMCPServer()
# Test if the server has the expected methods
if hasattr(server.server, '_handlers') and 'list_tools' in server.server._handlers:
tools = await server.server._handlers["list_tools"]()
print(f"✓ Found {len(tools)} tools: {[tool.name for tool in tools]}")
return len(tools) == 2
else:
print("✓ Server created with tool handlers (handler access not available in this version)")
return True
result = asyncio.run(check_tools())
return result
except Exception as e:
print(f"✗ Failed to list tools: {e}")
return False
def main():
"""Run all tests."""
print("Testing Rembg MCP Server")
print("=" * 30)
tests = [
("Import test", test_import),
("Server creation test", test_server_creation),
("Tools listing test", test_tools_listing),
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\n{test_name}:")
if test_func():
passed += 1
print(f"\nResults: {passed}/{total} tests passed")
if passed == total:
print("✓ All tests passed! Server is ready.")
sys.exit(0)
else:
print("✗ Some tests failed. Check your installation.")
sys.exit(1)
if __name__ == "__main__":
main()