File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ This MCP server supports both ClickHouse and chDB. You can enable either or both
7878 "CLICKHOUSE_PORT" : " <clickhouse-port>" ,
7979 "CLICKHOUSE_USER" : " <clickhouse-user>" ,
8080 "CLICKHOUSE_PASSWORD" : " <clickhouse-password>" ,
81+ "CLICKHOUSE_ROLE" : " <clickhouse-role>" ,
8182 "CLICKHOUSE_SECURE" : " true" ,
8283 "CLICKHOUSE_VERIFY" : " true" ,
8384 "CLICKHOUSE_CONNECT_TIMEOUT" : " 30" ,
@@ -298,6 +299,9 @@ The following environment variables are used to configure the ClickHouse and chD
298299* ` CLICKHOUSE_PORT ` : The port number of your ClickHouse server
299300 * Default: ` 8443 ` if HTTPS is enabled, ` 8123 ` if disabled
300301 * Usually doesn't need to be set unless using a non-standard port
302+ * ` CLICKHOUSE_ROLE ` : The role to use for authentication
303+ * Default: None
304+ * Set this if your user requires a specific role
301305* ` CLICKHOUSE_SECURE ` : Enable/disable HTTPS connection
302306 * Default: ` "true" `
303307 * Set to ` "false" ` for non-secure connections
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ class ClickHouseConfig:
3636 CLICKHOUSE_PASSWORD: The password for authentication
3737
3838 Optional environment variables (with defaults):
39+ CLICKHOUSE_ROLE: The role to use for authentication (default: None)
3940 CLICKHOUSE_PORT: The port number (default: 8443 if secure=True, 8123 if secure=False)
4041 CLICKHOUSE_SECURE: Enable HTTPS (default: true)
4142 CLICKHOUSE_VERIFY: Verify SSL certificates (default: true)
@@ -85,6 +86,11 @@ def password(self) -> str:
8586 """Get the ClickHouse password."""
8687 return os .environ ["CLICKHOUSE_PASSWORD" ]
8788
89+ @property
90+ def role (self ) -> Optional [str ]:
91+ """Get the ClickHouse role."""
92+ return os .getenv ("CLICKHOUSE_ROLE" )
93+
8894 @property
8995 def database (self ) -> Optional [str ]:
9096 """Get the default database name if set."""
@@ -145,6 +151,10 @@ def get_client_config(self) -> dict:
145151 "client_name" : "mcp_clickhouse" ,
146152 }
147153
154+ # Add optional role if set
155+ if self .role :
156+ config .setdefault ("settings" , {})["role" ] = self .role
157+
148158 # Add optional database if set
149159 if self .database :
150160 config ["database" ] = self .database
Original file line number Diff line number Diff line change @@ -81,3 +81,16 @@ def test_interface_https_with_custom_port(monkeypatch: pytest.MonkeyPatch):
8181 assert client_config ["interface" ] == "https"
8282 assert client_config ["secure" ] is True
8383 assert client_config ["port" ] == 9443
84+
85+
86+ def test_role_configuration (monkeypatch : pytest .MonkeyPatch ):
87+ """Test that role is correctly configured when CLICKHOUSE_ROLE is set."""
88+ monkeypatch .setenv ("CLICKHOUSE_HOST" , "localhost" )
89+ monkeypatch .setenv ("CLICKHOUSE_USER" , "test" )
90+ monkeypatch .setenv ("CLICKHOUSE_PASSWORD" , "test" )
91+ monkeypatch .setenv ("CLICKHOUSE_ROLE" , "analytics_reader" )
92+
93+ config = ClickHouseConfig ()
94+ client_config = config .get_client_config ()
95+
96+ assert client_config ["settings" ]["role" ] == "analytics_reader"
You can’t perform that action at this time.
0 commit comments