Skip to content

Keep HTTP health checks responsive during tool calls#63

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/http-tool-offload
Jul 7, 2026
Merged

Keep HTTP health checks responsive during tool calls#63
ChiragAgg5k merged 2 commits into
mainfrom
fix/http-tool-offload

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

  • Offload hosted HTTP MCP tool execution to an AnyIO worker thread so synchronous Appwrite SDK, docs search, context, and upload work cannot block the ASGI event loop.
  • Add a regression test proving a blocking HTTP tool call does not prevent the event loop from waking promptly.

Testing

  • uv run python -m unittest tests.unit.test_server -v
  • uv run python -m unittest discover -s tests/unit -v
  • uv run --group dev ruff check src/mcp_server_appwrite/server.py tests/unit/test_server.py
  • uv run --group dev black --check src/mcp_server_appwrite/server.py tests/unit/test_server.py
  • uv run --group dev pyright

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR keeps the ASGI event loop responsive during HTTP MCP tool calls by offloading synchronous Appwrite SDK work to an anyio worker thread, and fixes a concurrent-access bug in ResultStore that was exposed by the change.

  • server.py: Introduces _execute_public_tool_for_transport; for the HTTP transport it calls to_thread.run_sync(..., abandon_on_cancel=True) so blocking SDK/docs/upload calls cannot stall /healthz or other in-flight requests.
  • operator.py: Adds threading.Lock to ResultStore.get, list, and save, preventing iterator-mutation crashes when the event loop and a worker thread access the store concurrently.
  • Tests: New ResultStoreTests validates concurrent safety under ThreadPoolExecutor, and test_http_tool_execution_does_not_block_event_loop proves the event loop is free within 100 ms while a 200 ms blocking call runs in a thread.

Confidence Score: 5/5

Safe to merge — the thread offload and ResultStore locking are both correct and directly validated by new tests.

The core change is well-scoped: to_thread.run_sync with abandon_on_cancel=True correctly frees the event loop, the positional-arg forwarding to execute_public_tool matches its signature, and the new lock in ResultStore closes the iterator-mutation window without introducing deadlock risk. Both previous review concerns are fully addressed and covered by targeted regression tests.

No files require special attention.

Important Files Changed

Filename Overview
src/mcp_server_appwrite/server.py Adds _execute_public_tool_for_transport helper that offloads HTTP tool execution to an anyio worker thread with abandon_on_cancel=True, keeping the ASGI event loop free during blocking SDK calls.
src/mcp_server_appwrite/operator.py Adds threading.Lock to ResultStore covering get, list, and save, making the store safe for concurrent access from worker threads.
tests/unit/test_operator.py Adds ResultStoreTests with a concurrent save+list thread-safety regression test using ThreadPoolExecutor; correctly verifies no size overflow and no iterator crash.
tests/unit/test_server.py Adds test_http_tool_execution_does_not_block_event_loop which uses a 200ms blocking operator to prove the event loop remains free within 100ms while the task is still pending.
pyproject.toml Adds anyio>=4.0.0 as an explicit runtime dependency (it was previously transitively pulled via mcp[cli] but not declared).

Reviews (2): Last reviewed commit: "Address HTTP tool offload review feedbac..." | Re-trigger Greptile

Comment thread src/mcp_server_appwrite/server.py Outdated
Comment thread src/mcp_server_appwrite/server.py Outdated
@ChiragAgg5k ChiragAgg5k merged commit b2b3044 into main Jul 7, 2026
5 checks passed
@ChiragAgg5k ChiragAgg5k deleted the fix/http-tool-offload branch July 7, 2026 10:06
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.

1 participant