clickhouse-mcp-server
clickhouse-mcp-serverは、ClickHouseデータベースを管理するためのサーバーです。TypeScriptで実装されており、高速なデータ分析を可能にします。データのストレージとクエリ処理を効率化し、スケーラブルなアーキテクチャを提供します。特に大規模データセットに対するパフォーマンスが優れています。
GitHubスター
0
ユーザー評価
未評価
お気に入り
0
閲覧数
31
フォーク
0
イシュー
0
ClickHouse MCP Server
English | 日本語
A remote MCP (Model Context Protocol) server that enables Claude to interact with ClickHouse databases through a secure web interface.
Overview
This project implements an MCP server that:
- Provides read-only access to ClickHouse databases
- Authenticates users via Google OAuth 2.0
- Implements secure communication using Server-Sent Events (SSE)
- Restricts access to whitelisted email addresses
- Works seamlessly with Claude's web interface
Features
- Secure Authentication: Google OAuth 2.0 with email whitelist
- Read-Only Access: Safe database queries without modification risks
- Session Management: UUID-based sessions with automatic cleanup
- CORS Protection: Restricted to Claude.ai origins
- Comprehensive Logging: Debug capabilities with optional protocol logging
Prerequisites
- Node.js 18+ and npm
- ClickHouse server instance
- Google Cloud Console account (for OAuth)
- Domain with HTTPS (Let's Encrypt recommended)
- Apache2 or similar reverse proxy
Installation
Clone the repository
git clone https://github.com/yourusername/clickhouse-mcp-server.git cd clickhouse-mcp-server
Install dependencies
npm install
Configure environment variables
cp .env.example .env
Edit
.env
with your configuration:- ClickHouse connection details
- Google OAuth credentials
- Security keys (generate secure random strings)
- Allowed email addresses
Build the project
npm run build
Google OAuth Setup
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Create OAuth 2.0 credentials:
- Application type: Web application
- Authorized redirect URIs:
https://your-domain.com/mcp-clickhouse/oauth/callback
- Copy Client ID and Client Secret to
.env
Apache Configuration
Enable required modules
sudo a2enmod proxy proxy_http proxy_wstunnel ssl
Add proxy configuration
# MCP ClickHouse Server ProxyPass /mcp-clickhouse http://localhost:3001 ProxyPassReverse /mcp-clickhouse http://localhost:3001 # SSE Support <Location /mcp-clickhouse/sse> ProxyPass http://localhost:3001/mcp-clickhouse/sse ProxyPassReverse http://localhost:3001/mcp-clickhouse/sse Header set Cache-Control "no-cache" Header set X-Accel-Buffering "no" </Location>
Restart Apache
sudo systemctl restart apache2
Running the Server
Development Mode
npm run dev
Production Mode
Using systemd (recommended)
# Copy service file sudo cp config/mcp-clickhouse.service /etc/systemd/system/ # Edit service file with your paths sudo nano /etc/systemd/system/mcp-clickhouse.service # Enable and start service sudo systemctl enable mcp-clickhouse sudo systemctl start mcp-clickhouse
Using PM2
npm install -g pm2 pm2 start dist/index.js --name mcp-clickhouse pm2 save pm2 startup
Configuration Details
Environment Variables
Variable | Description | Example |
---|---|---|
PORT |
Server port | 3001 |
CLICKHOUSE_HOST |
ClickHouse server address | localhost |
CLICKHOUSE_USER |
Database username | default |
CLICKHOUSE_PASSWORD |
Database password | your-password |
GOOGLE_CLIENT_ID |
OAuth client ID | 123456789.apps.googleusercontent.com |
GOOGLE_CLIENT_SECRET |
OAuth client secret | GOCSPX-... |
JWT_SECRET |
JWT signing key | Random 64+ character string |
MCP_API_KEY |
API authentication key | Random 64+ character string |
ALLOWED_EMAILS |
Comma-separated whitelist | user1@gmail.com,user2@gmail.com |
Security Keys Generation
Generate secure random strings:
# Generate JWT_SECRET
openssl rand -hex 64
# Generate MCP_API_KEY
openssl rand -hex 32
Usage with Claude
- Navigate to https://claude.ai
- Add the MCP server:
- URL:
https://your-domain.com/mcp-clickhouse
- URL:
- Authenticate with Google when prompted
- Use Claude to query your ClickHouse database
Example queries:
- "Show me the tables in the database"
- "Get the row count for the users table"
- "Analyze the data distribution in the events table"
Troubleshooting
Common Issues
Authentication fails
- Verify Google OAuth credentials
- Check redirect URI matches exactly
- Ensure email is in ALLOWED_EMAILS
Connection refused
- Check if service is running:
sudo systemctl status mcp-clickhouse
- Verify Apache proxy configuration
- Check firewall settings
- Check if service is running:
ClickHouse connection errors
- Verify ClickHouse is running
- Check connection credentials
- Test with clickhouse-client
Logs
View logs:
# systemd logs
sudo journalctl -u mcp-clickhouse -f
# Application logs
tail -f /path/to/app/logs/*.log
Documentation
- MCP Tools Reference - Available MCP tools and ClickHouse query examples
- Protocol Communication Flow - Detailed OAuth and SSE communication flow with diagrams
Development
Project Structure
├── src/
│ ├── index.ts # Main server & SSE handler
│ ├── auth/
│ │ └── oauth.ts # OAuth implementation
│ └── server/
│ ├── config.ts # Configuration management
│ ├── logger.ts # Logging utilities
│ └── mcp-handler.ts # MCP protocol handler
├── config/ # Deployment configurations
├── docs/ # Documentation
├── tests/ # Test files
└── package.json
Testing
# Run tests
npm test
# Test SSE connection
node test-sse.cjs
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Anthropic for the MCP specification
- ClickHouse for the amazing database
- The Node.js and TypeScript communities
0
フォロワー
0
リポジトリ
0
Gist
0
貢献数
🤯 Lobe Chat - an open-source, modern design AI chat framework. Supports multiple AI providers (OpenAI / Claude 4 / Gemini / DeepSeek / Ollama / Qwen), Knowledge Base (file upload / RAG ), one click install MCP Marketplace and Artifacts / Thinking. One-click FREE deployment of your private AI Agent application.