Altinity MCP Server
A Model Context Protocol (MCP) server that provides tools for interacting with ClickHouse® databases. This server enables AI assistants and other MCP clients to query, analyze, and interact with ClickHouse® databases through a standardized protocol.
Features
- Multiple Transport Options: Support for STDIO, HTTP, and Server-Sent Events (SSE) transports
- Stateless MCP Protocol: The HTTP transport serves the stateless MCP protocol (spec revision 2026-07-28) — no session affinity required, safe to run behind round-robin load balancers; older clients transparently negotiate down to 2025-11-25 and earlier
- OAuth 2.0 Authorization: Broker OAuth flows from MCP clients against any OIDC provider; auto-detects Bearer vs Basic auth for ClickHouse (see OAuth 2.0 Documentation)
- JWE Authentication: Optional JWE-based authentication with encryption for secure database access
- TLS Support: Full TLS encryption support for both ClickHouse® connections and MCP server endpoints
- Comprehensive Tools: Built-in tools for listing tables, describing schemas, and executing queries
- Dynamic Tools: Automatically generate MCP tools from ClickHouse® views and tables (see Tools Documentation)
- Resource Templates: Dynamic resource discovery for database schemas and table information
- Query Prompts: AI-assisted query building and optimization prompts
- Configuration Management: Flexible configuration via files, environment variables, or CLI flags
- Hot Reload: Dynamic configuration reloading without server restart
Table of Contents
Quick Start
Using STDIO Transport (Default)
# Basic usage with default settings
./altinity-mcp --clickhouse-host localhost --clickhouse-port 8123
# With custom database and credentials
./altinity-mcp \
--clickhouse-host clickhouse.example.com \
--clickhouse-port 9000 \
--clickhouse-protocol tcp \
--clickhouse-database analytics \
--clickhouse-username reader \
--clickhouse-password secret123 \
--clickhouse-limit 5000
Using HTTP Transport with OpenAPI
./altinity-mcp \
--transport http \
--address 0.0.0.0 \
--port 8080 \
--clickhouse-host localhost \
--openapi http
Using SSE Transport with JWE Authentication and OpenAPI
./altinity-mcp \
--transport sse \
--port 8080 \
--allow-jwe-auth \
--jwe-secret-key "your-jwe-encryption-secret" \
--jwt-secret-key "your-jwt-signing-secret" \
--clickhouse-host localhost \
--openapi http
Integration Guide
For detailed instructions on integrating Altinity MCP with various AI tools and platforms, see our Integration Guide.
Installation & Deployment
Using Docker
docker run -it --rm ghcr.io/altinity/altinity-mcp:latest --clickhouse-host clickhouse
Kubernetes with Helm
From OCI helm registry (recommended)
# Install from OCI registry
helm install altinity-mcp oci://ghcr.io/altinity/altinity-mcp/helm/altinity-mcp \
--set config.clickhouse.host=clickhouse.example.com \
--set config.clickhouse.database=default \
--set config.clickhouse.limit=5000
From local helm chart
git clone https://github.com/Altinity/altinity-mcp
cd altinity-mcp
helm install altinity-mcp ./helm/altinity-mcp \
--set config.clickhouse.host=clickhouse-service \
--set config.clickhouse.database=analytics \
--set config.server.transport=http \
--set config.server.port=8080
From a tag-published GHCR image
helm install altinity-mcp oci://ghcr.io/altinity/altinity-mcp/helm/altinity-mcp \
--set image.tag=<tag-or-sha-tag> \
--set config.clickhouse.host=clickhouse.example.com \
--set config.clickhouse.database=default
For detailed Helm chart configuration options, see Helm Chart README.
Docker Compose
version: '3.8'
services:
altinity-mcp:
build: .
ports:
- "8080:8080"
environment:
- CLICKHOUSE_HOST=clickhouse
- MCP_TRANSPORT=http
- MCP_PORT=8080
depends_on:
- clickhouse
entrypoint: ["/bin/sh", "-c", "/bin/altinity-mcp"]
clickhouse:
image: clickhouse/clickhouse-server:latest
ports:
- "8123:8123"
With installed golang
go install github.com/altinity/altinity-mcp/cmd/altinity-mcp@latest
$(go env GOPATH)/bin/altinity-mcp --help
From Source
git clone https://github.com/altinity/altinity-mcp.git
cd altinity-mcp
go build -o altinity-mcp ./cmd/altinity-mcp
Configuration
Configuration File
Create a YAML or JSON configuration file:
# config.yaml
clickhouse:
host: "localhost"
# Optional TCP destination override. The logical host above remains the
# HTTP Host header and TLS SNI/certificate verification name.
connect_host: ""
port: 8123
database: "default"
username: "default"
password: ""
protocol: "http"
read_only: false
max_execution_time: 600
tls:
enabled: false
ca_cert: ""
client_cert: ""
client_key: ""
insecure_skip_verify: false
server:
transport: "stdio"
address: "0.0.0.0"
port: 8080
tls:
enabled: false
cert_file: ""
key_file: ""
ca_cert: ""
jwt:
enabled: false
secret_key: ""
openapi:
enabled: false
tls: false
metrics:
enabled: false
dynamic_tools:
- regexp: "mydb\\..*"
prefix: "db_"
- name: "get_user_data"
regexp: "users\\.user_info_view"
logging:
level: "info"
When connect_host is set, it takes precedence over HTTP_PROXY and
HTTPS_PROXY for ClickHouse HTTP connections so the configured address is
always the TCP destination. Environment proxy behavior is unchanged when
connect_host is empty.
Note: For detailed information about dynamic tools configuration, see the Tools Documentation.
Use the configuration file:
./altinity-mcp --config config.yaml
Environment Variables
Every configuration field with a flag: tag in pkg/config/config.go is settable via CLI flag or env var. The CLI flag and env-var name are listed in the field's flag: and env: tags. altinity-mcp --help prints the full surface.
Common examples:
export CLICKHOUSE_HOST=localhost
export CLICKHOUSE_PORT=8123
export CLICKHOUSE_DATABASE=analytics
export CLICKHOUSE_LIMIT=5000
export MCP_TRANSPORT=http
export MCP_PORT=8080
export MCP_METRICS_ENABLED=true
export LOG_LEVEL=debug
# OAuth — env-var injection lets operators pull secrets from a Kubernetes
# Secret via `valueFrom.secretKeyRef` instead of committing them to YAML.
export MCP_OAUTH_ENABLED=true
export MCP_OAUTH_BROKER=true
export MCP_OAUTH_ISSUER=https://accounts.example.com
export MCP_OAUTH_SIGNING_SECRET=...
./altinity-mcp
Special flags that don't follow this pattern: --config (config file path), --config-reload-time, --openapi (one flag → two struct fields). See altinity-mcp --help.
Prometheus metrics
HTTP and SSE transports (including JWE and multicluster modes) expose
/metrics when server.metrics.enabled, MCP_METRICS_ENABLED, or
--metrics-enabled is true. Metrics are disabled by default, and a disabled
server is a true no-op: no /metrics route, no request middleware, no query
instrumentation, and no collectors registered.
server.metrics.enabled is restart-only. A config reload that changes it
logs a warning and keeps the running value, because the route and middleware
are bound when the HTTP server starts.
The endpoint serves the standard Go runtime and process collectors plus:
| Metric |
Type |
Labels |
Meaning |
altinity_mcp_http_requests_total |
counter |
route, method, status |
Requests by registered route pattern, normalized method (GET, POST, ..., other) and status class (2xx, 4xx, ...) |
altinity_mcp_http_request_duration_seconds |
histogram |
route |
End-to-end handler latency |
altinity_mcp_clickhouse_queries_total |
counter |
kind, outcome |
ClickHouse queries by select/execute and ok/error |
altinity_mcp_clickhouse_query_duration_seconds |
histogram |
kind |
ClickHouse round-trip latency |
altinity_mcp_clickhouse_query_rows |
histogram |
kind |
Rows returned by successful queries |
altinity_mcp_clickhouse_query_bytes |
histogram |
kind |
Approximate bytes returned by successful queries |
altinity_mcp_blocked_clause_rejections_total |
counter |
clause |
Queries rejected by blocked_query_clauses |
altinity_mcp_clickhouse_up |
gauge |
|
1/0 from the last /health readiness ping; NaN in JWE/OAuth modes where no static credentials exist |
altinity_mcp_catalog_cache_* |
gauge/counter |
|
Multicluster catalog-cache activity (multicluster mode only) |
Every label is drawn from a fixed set: route labels use registered patterns
rather than raw URLs (so JWE tokens never appear), methods outside the
standard set collapse to other, and status codes collapse to their class.
The /metrics endpoint is unauthenticated. Restrict network access to it in
the same way you would for /health.
The Helm chart uses metrics.enabled for the endpoint. Set
metrics.serviceMonitor.enabled as well to create a Prometheus Operator
ServiceMonitor that scrapes the existing HTTP service port. When
config.server.tls.enabled is true the ServiceMonitor scrapes over https
automatically; supply metrics.serviceMonitor.tlsConfig if Prometheus does
not trust the server certificate.
Available Tools
execute_query
Executes SQL queries against ClickHouse® with optional result limiting.
MCP tool safety annotations:
- When the server runs with
--read-only, execute_query is exposed as read-only.
- Otherwise
execute_query is marked as potentially destructive.
Parameters:
query (required): The SQL query to execute
limit (optional): Maximum number of rows to return (default: server configured limit, max: 10,000)
Dynamic Tools
Dynamic tools generated from ClickHouse views are always exposed as read-only MCP tools with explicit safety hints.
View COMMENT supports either:
- A plain string description.
- A strict JSON object with top-level
title, description, and annotations.
See Tools Documentation for examples and supported metadata.
Available Resources
clickhouse://schema
Provides complete schema information for the ClickHouse® database in JSON format.
clickhouse://table/{database}/{table}
Provides detailed information about a specific table including schema, sample data, and statistics.
Available Prompts
No prompts currently available
OpenAI GPTs Integration
The Altinity MCP Server supports seamless integration with OpenAI GPTs through its OpenAPI-compatible endpoints. These endpoints enable GPT assistants to perform ClickHouse® database operations directly.
OpenAI MCP/tooling references:
Authentication
- With JWE: Add the JWE token to either:
- Path parameter:
/{jwe_token}/openapi/...
- Authorization header:
Bearer {token} (alternative)
x-altinity-mcp-key header (alternative)
- With OAuth: Send
Authorization: Bearer {token}.
- With both: A self-contained JWE takes priority; otherwise OAuth supplies the credentials.
- With both disabled