Skip to main content
Glama

mcp-hydrolix

Official
test_tool.py3.76 kB
import unittest import json from dotenv import load_dotenv from fastmcp.exceptions import ToolError from mcp_hydrolix import create_hydrolix_client, list_databases, list_tables, run_select_query load_dotenv() class TestHydrolixTools(unittest.TestCase): @classmethod def setUpClass(cls): """Set up the environment before tests.""" cls.client = create_hydrolix_client() # Prepare test database and table cls.test_db = "test_tool_db" cls.test_table = "test_table" cls.client.command(f"CREATE DATABASE IF NOT EXISTS {cls.test_db}") # Drop table if exists to ensure clean state cls.client.command(f"DROP TABLE IF EXISTS {cls.test_db}.{cls.test_table}") # Create table with comments cls.client.command(f""" CREATE TABLE {cls.test_db}.{cls.test_table} ( id UInt32 COMMENT 'Primary identifier', name String COMMENT 'User name field' ) ENGINE = MergeTree() ORDER BY id COMMENT 'Test table for unit testing' """) cls.client.command(f""" INSERT INTO {cls.test_db}.{cls.test_table} (id, name) VALUES (1, 'Alice'), (2, 'Bob') """) @classmethod def tearDownClass(cls): """Clean up the environment after tests.""" cls.client.command(f"DROP DATABASE IF EXISTS {cls.test_db}") def test_list_databases(self): """Test listing databases.""" result = list_databases.fn() # Parse JSON response databases = json.loads(result) self.assertIn(self.test_db, databases) def test_list_tables_without_like(self): """Test listing tables without a 'LIKE' filter.""" result = list_tables.fn(self.test_db) self.assertIsInstance(result, list) self.assertEqual(len(result), 1) self.assertEqual(result[0]["name"], self.test_table) def test_list_tables_with_like(self): """Test listing tables with a 'LIKE' filter.""" result = list_tables.fn(self.test_db, like=f"{self.test_table}%") self.assertIsInstance(result, list) self.assertEqual(len(result), 1) self.assertEqual(result[0]["name"], self.test_table) def test_run_select_query_success(self): """Test running a SELECT query successfully.""" query = f"SELECT * FROM {self.test_db}.{self.test_table}" result = run_select_query.fn(query) self.assertIsInstance(result, dict) self.assertEqual(len(result["rows"]), 2) self.assertEqual(result["rows"][0][0], 1) self.assertEqual(result["rows"][0][1], "Alice") def test_run_select_query_failure(self): """Test running a SELECT query with an error.""" query = f"SELECT * FROM {self.test_db}.non_existent_table" # Should raise ToolError with self.assertRaises(ToolError) as context: run_select_query.fn(query) self.assertIn("Query execution failed", str(context.exception)) def test_table_and_column_comments(self): """Test that table and column comments are correctly retrieved.""" result = list_tables.fn(self.test_db) self.assertIsInstance(result, list) self.assertEqual(len(result), 1) table_info = result[0] # Verify table comment self.assertEqual(table_info["comment"], "Test table for unit testing") # Get columns by name for easier testing columns = {col["name"]: col for col in table_info["columns"]} # Verify column comments self.assertEqual(columns["id"]["comment"], "Primary identifier") self.assertEqual(columns["name"]["comment"], "User name field") if __name__ == "__main__": unittest.main()

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hydrolix/mcp-hydrolix'

If you have feedback or need assistance with the MCP directory API, please join our Discord server