diff --git a/fastmcp.json b/fastmcp.json new file mode 100644 index 0000000..6b905e7 --- /dev/null +++ b/fastmcp.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://gofastmcp.com/public/schemas/fastmcp.json/v1.json", + "source": { + "path": "mcp_clickhouse/mcp_server.py", + "entrypoint": "mcp" + }, + "environment": { + "dependencies": [ + "clickhouse-connect", + "python-dotenv", + "pip-system-certs", + "chdb" + ] + } +} + diff --git a/mcp_clickhouse/mcp_env.py b/mcp_clickhouse/mcp_env.py index 40c0424..aec6826 100644 --- a/mcp_clickhouse/mcp_env.py +++ b/mcp_clickhouse/mcp_env.py @@ -173,6 +173,7 @@ def get_client_config(self) -> dict: "port": self.port, "username": self.username, "password": self.password, + "interface": "https" if self.secure else "http", "secure": self.secure, "verify": self.verify, "connect_timeout": self.connect_timeout, diff --git a/mcp_clickhouse/mcp_server.py b/mcp_clickhouse/mcp_server.py index 589ff2e..a3fa081 100644 --- a/mcp_clickhouse/mcp_server.py +++ b/mcp_clickhouse/mcp_server.py @@ -67,15 +67,7 @@ class Table: load_dotenv() -mcp = FastMCP( - name=MCP_SERVER_NAME, - dependencies=[ - "clickhouse-connect", - "python-dotenv", - "pip-system-certs", - "chdb", - ], -) +mcp = FastMCP(name=MCP_SERVER_NAME) @mcp.custom_route("/health", methods=["GET"]) diff --git a/tests/test_config_interface.py b/tests/test_config_interface.py new file mode 100644 index 0000000..d39a460 --- /dev/null +++ b/tests/test_config_interface.py @@ -0,0 +1,83 @@ +import pytest + +from mcp_clickhouse.mcp_env import ClickHouseConfig + + +def test_interface_http_when_secure_false(monkeypatch: pytest.MonkeyPatch): + """Test that interface is set to 'http' when CLICKHOUSE_SECURE=false.""" + monkeypatch.setenv("CLICKHOUSE_HOST", "localhost") + monkeypatch.setenv("CLICKHOUSE_USER", "test") + monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") + monkeypatch.setenv("CLICKHOUSE_SECURE", "false") + monkeypatch.setenv("CLICKHOUSE_PORT", "8123") + + config = ClickHouseConfig() + client_config = config.get_client_config() + + assert client_config["interface"] == "http" + assert client_config["secure"] is False + assert client_config["port"] == 8123 + + +def test_interface_https_when_secure_true(monkeypatch: pytest.MonkeyPatch): + """Test that interface is set to 'https' when CLICKHOUSE_SECURE=true.""" + monkeypatch.setenv("CLICKHOUSE_HOST", "example.com") + monkeypatch.setenv("CLICKHOUSE_USER", "test") + monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") + monkeypatch.setenv("CLICKHOUSE_SECURE", "true") + monkeypatch.setenv("CLICKHOUSE_PORT", "8443") + + config = ClickHouseConfig() + client_config = config.get_client_config() + + assert client_config["interface"] == "https" + assert client_config["secure"] is True + assert client_config["port"] == 8443 + + +def test_interface_https_by_default(monkeypatch: pytest.MonkeyPatch): + """Test that interface defaults to 'https' when CLICKHOUSE_SECURE is not set.""" + monkeypatch.setenv("CLICKHOUSE_HOST", "example.com") + monkeypatch.setenv("CLICKHOUSE_USER", "test") + monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") + monkeypatch.delenv("CLICKHOUSE_SECURE", raising=False) + monkeypatch.delenv("CLICKHOUSE_PORT", raising=False) + + config = ClickHouseConfig() + client_config = config.get_client_config() + + assert client_config["interface"] == "https" + assert client_config["secure"] is True + assert client_config["port"] == 8443 + + +def test_interface_http_with_custom_port(monkeypatch: pytest.MonkeyPatch): + """Test that interface is 'http' with custom port when CLICKHOUSE_SECURE=false.""" + monkeypatch.setenv("CLICKHOUSE_HOST", "localhost") + monkeypatch.setenv("CLICKHOUSE_USER", "test") + monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") + monkeypatch.setenv("CLICKHOUSE_SECURE", "false") + monkeypatch.setenv("CLICKHOUSE_PORT", "9000") + + config = ClickHouseConfig() + client_config = config.get_client_config() + + assert client_config["interface"] == "http" + assert client_config["secure"] is False + assert client_config["port"] == 9000 + + +def test_interface_https_with_custom_port(monkeypatch: pytest.MonkeyPatch): + """Test that interface is 'https' with custom port when CLICKHOUSE_SECURE=true.""" + monkeypatch.setenv("CLICKHOUSE_HOST", "example.com") + monkeypatch.setenv("CLICKHOUSE_USER", "test") + monkeypatch.setenv("CLICKHOUSE_PASSWORD", "test") + monkeypatch.setenv("CLICKHOUSE_SECURE", "true") + monkeypatch.setenv("CLICKHOUSE_PORT", "9443") + + config = ClickHouseConfig() + client_config = config.get_client_config() + + assert client_config["interface"] == "https" + assert client_config["secure"] is True + assert client_config["port"] == 9443