Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions fastmcp.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}

1 change: 1 addition & 0 deletions mcp_clickhouse/mcp_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 1 addition & 9 deletions mcp_clickhouse/mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
83 changes: 83 additions & 0 deletions tests/test_config_interface.py
Original file line number Diff line number Diff line change
@@ -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