8000 Refactor server internals into focused modules by joe-clickhouse · Pull Request #240 · ClickHouse/mcp-clickhouse · GitHub
[go: up one dir, main page]

Skip to content

Refactor server internals into focused modules - #240

Merged
joe-clickhouse merged 11 commits into
mainfrom
joe/structural-refactor
Sep 18, 2026
Merged

joe-clickhouse merged 11 commits into
mainfrom
joe/structural-refactor

Conversation

@joe-clickhouse
@joe-clickhouse joe-clickhouse commented Sep 18, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Over time mcp_server.py had grown to nearly 3K lines and was getting hard to follow. This PR splits it into smaller modules and leaves ~180 lines in this file for startup, registration and cleanup. The README has a guide about the new layout.

There aren't any new features. Tools, settings and documented Python imports still work the same.

If you're importing internals from mcp_server, these names have moved. All the paths below are under mcp_clickhouse:

Names Where they are now
Column, Table, result_to_table, result_to_column metadata
build_query_settings, get_readonly_setting clients
CHDB_PROMPT chdb_prompt
TLS_TOP_LEVEL_ONLY_KEYS mcp_env
execute_query queries._Queries.execute_query
execute_chdb_query chdb_backend._ChDBBackend.execute_chdb_query
QUERY_EXECUTOR, METADATA_EXECUTOR, CANCELLATION_EXECUTOR, HEALTH_EXECUTOR Each server's _Executors instance, as query, metadata, cancellation, health

The execution helpers and worker pools now belong to each server instance. They aren't standalone module exports or new public APIs.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No functional blockers were found; only two minor ASCII punctuation fixes remain.

Pull request overview

Refactors the monolithic server implementation into focused modules while preserving MCP behavior and compatibility exports.

Changes:

  • Separates authentication, transport, clients, queries, metadata, health, chDB, serialization, and executors.
  • Makes operational state and worker pools assembly-owned.
  • Updates tests and documentation for the new ownership boundaries.
File summaries
File Description
mcp_clickhouse/mcp_server.py Assembles and registers server components.
mcp_clickhouse/auth.py Owns authentication and dotenv handling.
mcp_clickhouse/transport.py Owns secured HTTP/SSE construction.
mcp_clickhouse/clients.py Owns client configuration, caching, and leases.
mcp_clickhouse/queries.py Owns execution, validation, and cancellation.
mcp_clickhouse/metadata.py Owns discovery and pagination.
mcp_clickhouse/health.py Owns health probes and caching.
mcp_clickhouse/chdb_backend.py Owns optional chDB state and execution.
mcp_clickhouse/executors.py Defines assembly-owned worker pools.
mcp_clickhouse/serialization.py Centralizes JSON result encoding.
README.md Documents the new module layout.
CHANGELOG.md Records internal import compatibility changes.
AGENTS.md Updates the repository architecture guidance.
.claude/agents/docs-drift-reviewer.md Updates documentation-review guidance.
tests/conftest.py Updates health-cache cleanup ownership.
tests/test_auth_config.py Targets extracted authentication helpers.
tests/test_chdb_tool.py Targets assembly-owned chDB state.
tests/test_client_cache.py Targets assembly-owned client caches and executors.
tests/test_connection_errors.py Targets extracted client diagnostics.
tests/test_context_config_override.py Updates client and metadata ownership references.
tests/test_destructive_ops.py Targets extracted query guards.
tests/test_grants_advisory.py Targets assembly-owned advisory state.
tests/test_health_cache.py Targets extracted health state.
tests/test_http_security_boundary.py Targets extracted auth and transport logic.
tests/test_mcp_server.py Updates query-owner test patches.
tests/test_optional_chdb.py Updates chDB and health ownership tests.
tests/test_pagination.py Imports metadata models from their owner.
tests/test_pagination_validation.py Updates pagination-owner references.
tests/test_protocol_compat.py Updates query execution references.
tests/test_query_cancellation.py Tests assembly-owned cancellation state.
tests/test_query_parameters.py Targets extracted query and client helpers.
tests/test_serialization.py Targets extracted serializers and chDB backend.
tests/test_tls_config.py Targets extracted client settings.
Review details

Suppressed comments (1)

mcp_clickhouse/clients.py:163

  • Use ASCII punctuation here; the repository writing style prohibits em dashes in new code and user-facing messages.
            "only — it is not MCP or ingress TLS. Use true for HTTPS database "
  • Files reviewed: 33/34 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread mcp_clickhouse/clients.py Resolved
@joe-clickhouse
joe-clickhouse merged commit 6753354 into main Sep 18, 2026
7 of 8 checks passed
@joe-clickhouse
joe-clickhouse deleted the joe/structural-refactor branch September 18, 2026 21:53
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.

3 participants

0