@futuretea/clickhouse-mcp-server 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +186 -0
- package/bin/index.js +30 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 futuretea
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# ClickHouse MCP Server
|
|
2
|
+
|
|
3
|
+
[中文文档](README.zh.md)
|
|
4
|
+
|
|
5
|
+
A small, read-only MCP server for exploring ClickHouse from an AI client or the command line. It connects to ClickHouse only over HTTP(S) through [`clickhouse-go/v2`](https://github.com/ClickHouse/clickhouse-go), and exposes Streamable HTTP at `/mcp`.
|
|
6
|
+
|
|
7
|
+
The MCP service has no authentication. It listens on `127.0.0.1` by default. Keep it on a trusted local network unless you separately design the authentication and network boundary.
|
|
8
|
+
|
|
9
|
+
## Quick start
|
|
10
|
+
|
|
11
|
+
1. Copy the example configuration and set the ClickHouse HTTP address.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
cp config.example.yaml config.yaml
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. Build and start the HTTP server.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
make build
|
|
21
|
+
./bin/clickhouse-mcp-server mcp --config config.yaml --port 8080
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
3. Confirm that the process is healthy.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
curl -s http://127.0.0.1:8080/healthz
|
|
28
|
+
# healthy
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
4. Configure an MCP client with the Streamable HTTP endpoint.
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"clickhouse": {
|
|
37
|
+
"url": "http://127.0.0.1:8080/mcp"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Tools
|
|
44
|
+
|
|
45
|
+
All successful tool calls return JSON in MCP text content.
|
|
46
|
+
|
|
47
|
+
| Tool | Input | Result |
|
|
48
|
+
|------|-------|--------|
|
|
49
|
+
| `clickhouse_list_databases` | none | `{"databases":["default"]}` |
|
|
50
|
+
| `clickhouse_list_tables` | optional `database` | database name plus table name, engine, and comment |
|
|
51
|
+
| `clickhouse_describe_table` | required `table`, optional `database` | column name, type, defaults, and comment |
|
|
52
|
+
| `clickhouse_query` | required `query`, optional positive integer `max_rows` | columns, display-string rows, returned `row_count`, and `truncated` |
|
|
53
|
+
|
|
54
|
+
`clickhouse_query` defaults to 1,000 rows. The server reads one additional row to report `truncated: true`; that extra row is not returned. Each non-null cell is rendered as a string so clients receive a stable JSON shape.
|
|
55
|
+
|
|
56
|
+
The query tool accepts exactly one statement. Semicolons in strings, quoted identifiers, and SQL comments are allowed; a second statement is rejected before it reaches ClickHouse. Every query is sent with ClickHouse `readonly=1`, so ClickHouse rejects writes and DDL for a user that honors that setting. The connected ClickHouse user should still have only the privileges appropriate for read access.
|
|
57
|
+
|
|
58
|
+
## Configuration
|
|
59
|
+
|
|
60
|
+
Configuration priority is **flags > environment variables > YAML file > defaults**. `clickhouse.address` is required and must be a `host:port` value without a scheme or path.
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
port: 8080
|
|
64
|
+
listen: 127.0.0.1
|
|
65
|
+
log_level: info
|
|
66
|
+
clickhouse:
|
|
67
|
+
address: 127.0.0.1:8123
|
|
68
|
+
database: default
|
|
69
|
+
secure: false
|
|
70
|
+
username: ""
|
|
71
|
+
password: ""
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| Group | YAML key | Environment variable | Default | Meaning |
|
|
75
|
+
|-------|----------|----------------------|---------|---------|
|
|
76
|
+
| ClickHouse connection | `clickhouse.address` | `MCP_CLICKHOUSE_ADDRESS` | none | Required ClickHouse `host:port` address |
|
|
77
|
+
| ClickHouse connection | `clickhouse.database` | `MCP_CLICKHOUSE_DATABASE` | `default` | Default database for table tools |
|
|
78
|
+
| ClickHouse connection | `clickhouse.secure` | `MCP_CLICKHOUSE_SECURE` | `false` | Use HTTPS instead of HTTP to ClickHouse |
|
|
79
|
+
| ClickHouse connection | `clickhouse.username` | `MCP_CLICKHOUSE_USERNAME` | empty | Optional ClickHouse username |
|
|
80
|
+
| ClickHouse connection | `clickhouse.password` | `MCP_CLICKHOUSE_PASSWORD` | empty | Optional ClickHouse password |
|
|
81
|
+
| Server | `port` | `MCP_PORT` | `0` | HTTP port; `0` starts stdio mode |
|
|
82
|
+
| Server | `listen` | `MCP_LISTEN` | `127.0.0.1` | HTTP listen host |
|
|
83
|
+
| Server | `sse_base_url` | `MCP_SSE_BASE_URL` | empty | Public base URL for legacy SSE message endpoints |
|
|
84
|
+
| Server | `log_level` | `MCP_LOG_LEVEL` | `info` | Server log level |
|
|
85
|
+
| Tool filters | `enabled_tools` | `MCP_ENABLED_TOOLS` | empty | Comma-separated tool names to enable |
|
|
86
|
+
| Tool filters | `disabled_tools` | `MCP_DISABLED_TOOLS` | empty | Comma-separated tool names to disable |
|
|
87
|
+
| Tool filters | `enabled_domains` | `MCP_ENABLED_DOMAINS` | empty | Comma-separated tool domains to enable |
|
|
88
|
+
| Tool filters | `disabled_domains` | `MCP_DISABLED_DOMAINS` | empty | Comma-separated tool domains to disable |
|
|
89
|
+
|
|
90
|
+
The server never logs the configured password. `secure: true` protects the connection to ClickHouse; it does not add TLS or authentication to the MCP HTTP endpoint.
|
|
91
|
+
|
|
92
|
+
### Environment-only configuration check
|
|
93
|
+
|
|
94
|
+
For the smallest local setup, set just the ClickHouse HTTP address and inspect the effective configuration. This command does not start MCP or access the network.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
export MCP_CLICKHOUSE_ADDRESS=127.0.0.1:8123
|
|
98
|
+
./bin/clickhouse-mcp-server config check
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The command prints the 13 configuration fields in a stable order with their source (`flag`, `environment`, `YAML`, or `default`). Passwords are reported only as `set` or `unset`. `sse_base_url` removes query and fragment values and redacts URL userinfo before display.
|
|
102
|
+
|
|
103
|
+
Use `--connect` only when you intentionally want one ClickHouse HTTP(S) `Ping`; it opens, pings, and closes a short-lived connection without starting the MCP server.
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
./bin/clickhouse-mcp-server config check --connect
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## CLI
|
|
110
|
+
|
|
111
|
+
The CLI uses the same configuration and is useful for checking connectivity without an MCP client.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
./bin/clickhouse-mcp-server tools list --config config.yaml
|
|
115
|
+
./bin/clickhouse-mcp-server tools describe clickhouse_query --config config.yaml --json
|
|
116
|
+
./bin/clickhouse-mcp-server tools call clickhouse_list_databases --config config.yaml
|
|
117
|
+
./bin/clickhouse-mcp-server tools call clickhouse_query --config config.yaml \
|
|
118
|
+
--params '{"query":"SELECT version()"}'
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Transports
|
|
122
|
+
|
|
123
|
+
`mcp` starts stdio when `port` is `0`, or an HTTP process when it is non-zero. HTTP mode exposes:
|
|
124
|
+
|
|
125
|
+
| Path | Purpose |
|
|
126
|
+
|------|---------|
|
|
127
|
+
| `/mcp` | Primary Streamable HTTP MCP endpoint |
|
|
128
|
+
| `/healthz` | Health check (`GET` and `HEAD`) |
|
|
129
|
+
| `/sse` | Legacy SSE MCP endpoint |
|
|
130
|
+
| `/message` | SSE message endpoint |
|
|
131
|
+
|
|
132
|
+
## Docker
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
make docker
|
|
136
|
+
docker run --rm -p 8080:8080 \
|
|
137
|
+
-v "$PWD/config.yaml:/config.yaml:ro" \
|
|
138
|
+
clickhouse-mcp-server:dev --config /config.yaml --port 8080
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Do not publish the unauthenticated HTTP port directly to the internet.
|
|
142
|
+
|
|
143
|
+
## Release artifacts
|
|
144
|
+
|
|
145
|
+
Only stable `vX.Y.Z` Git tags trigger releases. A validated stable release updates the npm, Docker, and GitHub Release `latest` pointers; use a versioned reference when you need a fixed version.
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npx -y @futuretea/clickhouse-mcp-server
|
|
149
|
+
npx -y @futuretea/clickhouse-mcp-server@<version>
|
|
150
|
+
docker run --rm -i ghcr.io/futuretea/clickhouse-mcp-server:latest
|
|
151
|
+
docker run --rm -i ghcr.io/futuretea/clickhouse-mcp-server:v<version>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Both commands launch the `mcp` command. Arguments after the package or image are forwarded to it. Maintainers need a GitHub Actions `NPM_TOKEN` with publish permission for `@futuretea`; after the first release, set the GHCR package visibility to public.
|
|
155
|
+
|
|
156
|
+
## Troubleshooting
|
|
157
|
+
|
|
158
|
+
- `clickhouse.address is required`: add a `host:port` value such as `127.0.0.1:8123` to the configuration or `MCP_CLICKHOUSE_ADDRESS`.
|
|
159
|
+
- Connection failure: check the address, `secure` value, ClickHouse HTTP port, and network reachability.
|
|
160
|
+
- Query rejection: verify the statement is a single read-only query and that the configured ClickHouse user has access to the database.
|
|
161
|
+
- `truncated: true`: lower the result size in SQL or increase `max_rows` deliberately.
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
make format
|
|
167
|
+
make lint
|
|
168
|
+
make test
|
|
169
|
+
make ci
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Optional ClickHouse integration test
|
|
173
|
+
|
|
174
|
+
The default test suite has no external dependency. The opt-in integration test starts an isolated local ClickHouse Docker container to verify database discovery, parameterized table inspection, `SELECT`, and that `readonly=1` rejects temporary DDL. It also builds the public server binary, starts it in HTTP mode on loopback, checks `/healthz`, and calls `tools/list` and `tools/call` through `/mcp`.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
make test-integration
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
The target requires Docker and `curl`, creates a random loopback port, waits for ClickHouse health, and removes its container on exit. Set `CLICKHOUSE_INTEGRATION_IMAGE` to test another isolated image. It runs the full MCP HTTP E2E test, the read-only toolset integration test, and `config check --connect`. It is local-only: neither `make test` nor the GitHub Actions CI workflow runs it.
|
|
181
|
+
|
|
182
|
+
The repository retains its template assets under `scripts/` and `templates/` for local reference; they are not part of the ClickHouse server runtime.
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
[MIT](LICENSE)
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const childProcess = require('child_process');
|
|
4
|
+
|
|
5
|
+
const goos = process.platform === 'win32' ? 'windows' : process.platform;
|
|
6
|
+
const goarch = process.arch === 'x64' ? 'amd64' : process.arch;
|
|
7
|
+
const suffix = process.platform === 'win32' ? '.exe' : '';
|
|
8
|
+
const packageName = `@futuretea/clickhouse-mcp-server-${goos}-${goarch}`;
|
|
9
|
+
|
|
10
|
+
let binaryPath;
|
|
11
|
+
try {
|
|
12
|
+
binaryPath = require.resolve(`${packageName}/bin/clickhouse-mcp-server${suffix}`);
|
|
13
|
+
} catch {
|
|
14
|
+
throw new Error(`Could not resolve binary path for platform/architecture: ${process.platform}/${process.arch}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const child = childProcess.spawn(binaryPath, ['mcp', ...process.argv.slice(2)], {
|
|
18
|
+
stdio: 'inherit',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
for (const signal of ['SIGTERM', 'SIGINT', 'SIGHUP']) {
|
|
22
|
+
process.on(signal, () => {
|
|
23
|
+
if (!child.killed) child.kill(signal);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
child.on('close', (code, signal) => {
|
|
28
|
+
if (signal) process.exit(128 + (signal === 'SIGTERM' ? 15 : signal === 'SIGINT' ? 2 : 1));
|
|
29
|
+
process.exit(code || 0);
|
|
30
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@futuretea/clickhouse-mcp-server",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Read-only ClickHouse Model Context Protocol server",
|
|
5
|
+
"main": "./bin/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"clickhouse-mcp-server": "bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"optionalDependencies": {
|
|
10
|
+
"@futuretea/clickhouse-mcp-server-darwin-amd64": "0.0.1",
|
|
11
|
+
"@futuretea/clickhouse-mcp-server-darwin-arm64": "0.0.1",
|
|
12
|
+
"@futuretea/clickhouse-mcp-server-linux-amd64": "0.0.1",
|
|
13
|
+
"@futuretea/clickhouse-mcp-server-linux-arm64": "0.0.1",
|
|
14
|
+
"@futuretea/clickhouse-mcp-server-windows-amd64": "0.0.1"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/futuretea/clickhouse-mcp-server.git"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"mcp",
|
|
22
|
+
"clickhouse",
|
|
23
|
+
"database",
|
|
24
|
+
"model-context-protocol"
|
|
25
|
+
],
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "futuretea",
|
|
28
|
+
"url": "https://github.com/futuretea"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/futuretea/clickhouse-mcp-server/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/futuretea/clickhouse-mcp-server#readme"
|
|
35
|
+
}
|