Skip to content

fix blocking during long queries#136

Open
joe-clickhouse wants to merge 5 commits intomainfrom
joe/128-mcp-server-calls-blocked-by-long-running-queries
Open

fix blocking during long queries#136
joe-clickhouse wants to merge 5 commits intomainfrom
joe/128-mcp-server-calls-blocked-by-long-running-queries

Conversation

@joe-clickhouse
Copy link
Collaborator

@joe-clickhouse joe-clickhouse commented Mar 2, 2026

Summary

  • Keep the public query helpers sync while making MCP query execution non-blocking
  • Queries were already dispatched to a thread pool, but the MCP tool path still blocked the event loop while waiting for results. This change adds async MCP-facing wrappers for ClickHouse and chDB queries that await thread-pool futures with asyncio.wait_for() while preserving the existing synchronous run_query and run_chdb_select_query APIs for direct Python callers
  • Other MCP requests, including list_tools can now be served while a query is in flight

Closes #128

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 addresses MCP server responsiveness issues during long-running ClickHouse/chDB queries by making the query tools non-blocking with respect to the asyncio event loop, so other MCP requests can be served while a query is in-flight (closes #128).

Changes:

  • Converted run_query and run_chdb_select_query to async def and replaced blocking future.result() with asyncio.wrap_future() + await asyncio.wait_for(...).
  • Updated synchronous unit tests to call the now-async functions via small asyncio.run(...) helpers.
  • Added required asyncio imports where needed.

Reviewed changes

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

File Description
mcp_clickhouse/mcp_server.py Makes ClickHouse/chDB query tools await threadpool futures instead of blocking the event loop thread.
tests/test_tool.py Adjusts tests to invoke async run_query from sync unittest methods.
tests/test_chdb_tool.py Adjusts tests to invoke async run_chdb_select_query from sync unittest methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. 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.

MCP server calls blocked by long-running queries

2 participants