"""Quick test script for the standalone Dolibarr MCP server.""" import asyncio import sys import os # Add src to path for imports sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) try: from src.dolibarr_mcp.standalone_server import StandaloneMCPServer from src.dolibarr_mcp.config import Config print("โœ… All imports successful - standalone server ready!") except ImportError as e: print(f"โŒ Import error: {e}") print("๐Ÿ’ก Please run: setup_standalone.bat first") sys.exit(1) async def test_standalone(): """Test the standalone server.""" print("๐Ÿงช Testing Standalone Dolibarr MCP Server...") print("") try: # Test config loading config = Config() print(f"โœ… Configuration loaded") print(f" URL: {config.dolibarr_url}") print(f" API Key: {'*' * min(len(config.api_key), 10)}...") print("") # Test server creation server = StandaloneMCPServer("test-server") print("โœ… Server instance created") # Test tool definitions tools = server.get_tool_definitions() print(f"โœ… Tools loaded: {len(tools)} available") print("") # List some tools print("๐Ÿ“‹ Available Tools (first 10):") for i, tool in enumerate(tools[:10]): print(f" {i+1:2}. {tool['name']} - {tool['description']}") if len(tools) > 10: print(f" ... and {len(tools) - 10} more") print("") # Test a simple tool call (without actual API) print("๐Ÿงช Testing tool call structure...") try: # This will fail with API error, but tests the structure result = await server.handle_tool_call("test_connection", {}) if "error" in result and "api_error" in result.get("type", ""): print("โœ… Tool call structure working (API connection expected to fail)") else: print("โœ… Tool call successful!") print(f" Result: {result}") except Exception as e: print(f"โœ… Tool call structure working (got expected error: {type(e).__name__})") print("") print("๐ŸŽ‰ Standalone server test completed successfully!") print("") print("๐Ÿš€ Ready to run:") print(" python -m src.dolibarr_mcp.standalone_server") print(" OR") print(" .\\run_standalone.bat") except Exception as e: print(f"โŒ Test failed: {e}") return False return True if __name__ == "__main__": print("=" * 50) print("Dolibarr MCP Standalone Server Test") print("=" * 50) print("") success = asyncio.run(test_standalone()) if success: print("") print("=" * 50) print("โœ… ALL TESTS PASSED - SERVER READY!") print("=" * 50) sys.exit(0) else: print("") print("=" * 50) print("โŒ TESTS FAILED - CHECK SETUP") print("=" * 50) sys.exit(1)