Skip to content

feat(code-assistant): add lifespan for httpx client lifecycle management#198

Merged
cbjuan merged 3 commits intomainfrom
feat/197-code-assistant-httpx-lifespan
Apr 17, 2026
Merged

feat(code-assistant): add lifespan for httpx client lifecycle management#198
cbjuan merged 3 commits intomainfrom
feat/197-code-assistant-httpx-lifespan

Conversation

@cbjuan
Copy link
Copy Markdown
Member

@cbjuan cbjuan commented Apr 16, 2026

Summary

  • Add an async lifespan context manager that creates the httpx.AsyncClient on server startup and properly closes it on shutdown
  • Wire it into FastMCP() via the lifespan parameter
  • Add set_http_client() / clear_http_client() to utils.py for proper client injection
  • Remove the fragile atexit-based cleanup from __main__
  • Update test fixtures to use the new public API instead of accessing _client directly

Mirrors the approach from #176 for the docs server. Prevents resource leaks and ResourceWarning for unclosed connections.

Closes #197

Replace the fragile atexit-based cleanup with a proper FastMCP lifespan
context manager that creates the httpx.AsyncClient on startup and closes
it on shutdown, preventing resource leaks and ResourceWarning.

Closes #197

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cbjuan cbjuan requested a review from vabarbosa as a code owner April 16, 2026 11:16
Copy link
Copy Markdown
Collaborator

@vabarbosa vabarbosa left a comment

Choose a reason for hiding this comment

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

thank you

# Conflicts:
#	qiskit-code-assistant-mcp-server/src/qiskit_code_assistant_mcp_server/server.py
@cbjuan cbjuan merged commit 9d7a723 into main Apr 17, 2026
30 checks passed
@cbjuan cbjuan deleted the feat/197-code-assistant-httpx-lifespan branch April 17, 2026 15:37
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.

feat(code-assistant): add lifespan for httpx client lifecycle management

2 participants