Skip to content

Commit 965592b

Browse files
explicitly set interface based on secure value
1 parent 415c3b3 commit 965592b

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

mcp_clickhouse/mcp_env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def get_client_config(self) -> dict:
173173
"port": self.port,
174174
"username": self.username,
175175
"password": self.password,
176+
"interface": "https" if self.secure else "http",
176177
"secure": self.secure,
177178
"verify": self.verify,
178179
"connect_timeout": self.connect_timeout,

tests/test_config_interface.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import os
2+
3+
from mcp_clickhouse.mcp_env import ClickHouseConfig
4+
5+
6+
def test_interface_http_when_secure_false():
7+
"""Test that interface is set to 'http' when CLICKHOUSE_SECURE=false."""
8+
os.environ["CLICKHOUSE_HOST"] = "localhost"
9+
os.environ["CLICKHOUSE_USER"] = "test"
10+
os.environ["CLICKHOUSE_PASSWORD"] = "test"
11+
os.environ["CLICKHOUSE_SECURE"] = "false"
12+
os.environ["CLICKHOUSE_PORT"] = "8123"
13+
14+
config = ClickHouseConfig()
15+
client_config = config.get_client_config()
16+
17+
assert client_config["interface"] == "http"
18+
assert client_config["secure"] is False
19+
assert client_config["port"] == 8123
20+
21+
22+
def test_interface_https_when_secure_true():
23+
"""Test that interface is set to 'https' when CLICKHOUSE_SECURE=true."""
24+
os.environ["CLICKHOUSE_HOST"] = "example.com"
25+
os.environ["CLICKHOUSE_USER"] = "test"
26+
os.environ["CLICKHOUSE_PASSWORD"] = "test"
27+
os.environ["CLICKHOUSE_SECURE"] = "true"
28+
os.environ["CLICKHOUSE_PORT"] = "8443"
29+
30+
config = ClickHouseConfig()
31+
client_config = config.get_client_config()
32+
33+
assert client_config["interface"] == "https"
34+
assert client_config["secure"] is True
35+
assert client_config["port"] == 8443
36+
37+
38+
def test_interface_https_by_default():
39+
"""Test that interface defaults to 'https' when CLICKHOUSE_SECURE is not set."""
40+
os.environ["CLICKHOUSE_HOST"] = "example.com"
41+
os.environ["CLICKHOUSE_USER"] = "test"
42+
os.environ["CLICKHOUSE_PASSWORD"] = "test"
43+
if "CLICKHOUSE_SECURE" in os.environ:
44+
del os.environ["CLICKHOUSE_SECURE"]
45+
if "CLICKHOUSE_PORT" in os.environ:
46+
del os.environ["CLICKHOUSE_PORT"]
47+
48+
config = ClickHouseConfig()
49+
client_config = config.get_client_config()
50+
51+
assert client_config["interface"] == "https"
52+
assert client_config["secure"] is True
53+
assert client_config["port"] == 8443
54+
55+
56+
def test_interface_http_with_custom_port():
57+
"""Test that interface is 'http' with custom port when CLICKHOUSE_SECURE=false."""
58+
os.environ["CLICKHOUSE_HOST"] = "localhost"
59+
os.environ["CLICKHOUSE_USER"] = "test"
60+
os.environ["CLICKHOUSE_PASSWORD"] = "test"
61+
os.environ["CLICKHOUSE_SECURE"] = "false"
62+
os.environ["CLICKHOUSE_PORT"] = "9000"
63+
64+
config = ClickHouseConfig()
65+
client_config = config.get_client_config()
66+
67+
assert client_config["interface"] == "http"
68+
assert client_config["secure"] is False
69+
assert client_config["port"] == 9000
70+
71+
72+
def test_interface_https_with_custom_port():
73+
"""Test that interface is 'https' with custom port when CLICKHOUSE_SECURE=true."""
74+
os.environ["CLICKHOUSE_HOST"] = "example.com"
75+
os.environ["CLICKHOUSE_USER"] = "test"
76+
os.environ["CLICKHOUSE_PASSWORD"] = "test"
77+
os.environ["CLICKHOUSE_SECURE"] = "true"
78+
os.environ["CLICKHOUSE_PORT"] = "9443"
79+
80+
config = ClickHouseConfig()
81+
client_config = config.get_client_config()
82+
83+
assert client_config["interface"] == "https"
84+
assert client_config["secure"] is True
85+
assert client_config["port"] == 9443

0 commit comments

Comments
 (0)