Skip to content

Conversation

@joe-clickhouse
Copy link
Contributor

Summary

This PR enables LLMs to perform write operations on ClickHouse databases with built-in safety controls to prevent accidental data loss.

Write Access Mode

  • New CLICKHOUSE_ALLOW_WRITE_ACCESS flag (default: false) enables DDL and DML operations (INSERT, UPDATE, CREATE, ALTER, DROP)
  • When enabled, queries run with readonly=0 instead of the default readonly=1

Two-Tier DROP Protection

  • CLICKHOUSE_ALLOW_DROP (default: false) provides additional safety for destructive operations
  • Both flags must be true to allow DROP operations
  • Other write operations (INSERT, CREATE, etc.) only require CLICKHOUSE_ALLOW_WRITE_ACCESS=true

Usage

Enable write access:

"env": {
  "CLICKHOUSE_ALLOW_WRITE_ACCESS": "true"
}

Enable write access including DROP:

"env": {
  "CLICKHOUSE_ALLOW_WRITE_ACCESS": "true",
  "CLICKHOUSE_ALLOW_DROP": "true"
}

Closes #24

@joe-clickhouse joe-clickhouse linked an issue Oct 23, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds optional write access capabilities to the ClickHouse MCP server with built-in safety mechanisms. By default, the server maintains read-only behavior, but can now be explicitly configured to allow write operations with DROP protection.

Key changes:

  • Renamed run_select_query to run_query to reflect broader SQL support
  • Added CLICKHOUSE_ALLOW_WRITE_ACCESS flag to enable DDL/DML operations
  • Added CLICKHOUSE_ALLOW_DROP flag for additional protection against destructive operations

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mcp_clickhouse/mcp_env.py Added two new configuration properties (allow_write_access and allow_drop) to control write permissions
mcp_clickhouse/mcp_server.py Implemented DROP validation, refactored readonly setting logic, renamed query function, and added dynamic tool description
mcp_clickhouse/init.py Updated exports to reflect function rename
tests/test_tool.py Renamed function references and added comprehensive test coverage for write mode, DROP protection, and read-only mode
tests/test_mcp_server.py Updated function calls to use new run_query name
README.md Updated documentation to reflect new function name and write access features

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional write access?

1 participant