Skip to content

Commit c951aed

Browse files
phernandezclaude
andcommitted
refactor(mcp): convert continue_conversation.py to context manager pattern
Convert continue_conversation MCP prompt from module-level client import to the new get_client() context manager pattern, enabling proper dependency injection. Changes: - Import get_client() instead of client from async_client module - Wrap function body in 'async with get_client() as client:' block - Indent all code inside context manager (lines 45-62) - Update SPEC-16 checklist (15 of 16 main tools converted) The continue_conversation prompt helps users continue conversations and work across sessions by: - Finding recent context about specific topics - Showing general recent activity with timeframe filtering - Providing context from previous sessions to maintain continuity - Supporting session continuation in MCP-enabled AI assistants This conversion maintains the prompt's session continuation functionality while: - Ensuring proper client lifecycle management - Enabling cloud app to inject custom transport via factory - Allowing tests to mock client behavior - Following httpx best practices for async context managers - Moving auth to client creation instead of per-request Testing: - Typecheck passed (0 errors, 0 warnings) - Prompt function properly scoped (client inside async with block) Part of Phase 0.3: Converting 16 MCP tools/prompts to context manager pattern. Related to SPEC-16 MCP Cloud Service Consolidation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7856dd4 commit c951aed

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

specs/SPEC-16 MCP Cloud Service Consolidation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ Convert from `from async_client import client` to `async with get_client() as cl
462462
- [x] `tools/canvas.py` (5/5 tests passing)
463463
- [x] `tools/build_context.py` (6/6 tests passing)
464464
- [x] `tools/sync_status.py` (typecheck passed)
465+
- [x] `prompts/continue_conversation.py` (typecheck passed)
465466
- [ ] `prompts/search.py`
466-
- [ ] `prompts/continue_conversation.py`
467467
- [ ] `resources/project_info.py`
468468

469469
#### 0.4 Update CLI Commands (~3 files)

src/basic_memory/mcp/prompts/continue_conversation.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pydantic import Field
1111

1212
from basic_memory.config import get_project_config
13-
from basic_memory.mcp.async_client import client
13+
from basic_memory.mcp.async_client import get_client
1414
from basic_memory.mcp.server import mcp
1515
from basic_memory.mcp.tools.utils import call_post
1616
from basic_memory.schemas.base import TimeFrame
@@ -42,20 +42,21 @@ async def continue_conversation(
4242
"""
4343
logger.info(f"Continuing session, topic: {topic}, timeframe: {timeframe}")
4444

45-
# Create request model
46-
request = ContinueConversationRequest( # pyright: ignore [reportCallIssue]
47-
topic=topic, timeframe=timeframe
48-
)
45+
async with get_client() as client:
46+
# Create request model
47+
request = ContinueConversationRequest( # pyright: ignore [reportCallIssue]
48+
topic=topic, timeframe=timeframe
49+
)
4950

50-
project_url = get_project_config().project_url
51+
project_url = get_project_config().project_url
5152

52-
# Call the prompt API endpoint
53-
response = await call_post(
54-
client,
55-
f"{project_url}/prompt/continue-conversation",
56-
json=request.model_dump(exclude_none=True),
57-
)
53+
# Call the prompt API endpoint
54+
response = await call_post(
55+
client,
56+
f"{project_url}/prompt/continue-conversation",
57+
json=request.model_dump(exclude_none=True),
58+
)
5859

59-
# Extract the rendered prompt from the response
60-
result = response.json()
61-
return result["prompt"]
60+
# Extract the rendered prompt from the response
61+
result = response.json()
62+
return result["prompt"]

0 commit comments

Comments
 (0)