Skip to content

Commit def8cb3

Browse files
phernandezclaude
andcommitted
refactor(mcp): convert project_info.py resource to context manager pattern
Convert project_info MCP resource 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 63-71) - Update SPEC-16 checklist - Phase 0.3 COMPLETE! (All 16 tools/prompts/resources converted) The project_info resource provides comprehensive project information via MCP: - Project configuration and metadata - Entity, observation, and relation counts - Graph metrics (most connected entities, isolated entities) - Recent activity and growth over time - System status (database, watch service, version) This conversion maintains the resource's 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) - Resource function properly scoped (client inside async with block) ✅ Phase 0.3 Complete: All 16 MCP tools/prompts/resources converted! - 13 tools in tools/ directory - 2 prompts in prompts/ directory - 1 resource in resources/ directory Next: Phase 0.4 - Update CLI commands to use 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 1b20e6c commit def8cb3

2 files changed

Lines changed: 10 additions & 8 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
@@ -464,7 +464,7 @@ Convert from `from async_client import client` to `async with get_client() as cl
464464
- [x] `tools/sync_status.py` (typecheck passed)
465465
- [x] `prompts/continue_conversation.py` (typecheck passed)
466466
- [x] `prompts/search.py` (typecheck passed)
467-
- [ ] `resources/project_info.py`
467+
- [x] `resources/project_info.py` (typecheck passed)
468468

469469
#### 0.4 Update CLI Commands (~3 files)
470470
Remove manual auth header passing, use context manager:

src/basic_memory/mcp/resources/project_info.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from loguru import logger
66
from fastmcp import Context
77

8-
from basic_memory.mcp.async_client import client
8+
from basic_memory.mcp.async_client import get_client
99
from basic_memory.mcp.project_context import get_active_project
1010
from basic_memory.mcp.server import mcp
1111
from basic_memory.mcp.tools.utils import call_get
@@ -59,11 +59,13 @@ async def project_info(
5959
print(f"Basic Memory version: {info.system.version}")
6060
"""
6161
logger.info("Getting project info")
62-
project_config = await get_active_project(client, project, context)
63-
project_url = project_config.permalink
6462

65-
# Call the API endpoint
66-
response = await call_get(client, f"{project_url}/project/info")
63+
async with get_client() as client:
64+
project_config = await get_active_project(client, project, context)
65+
project_url = project_config.permalink
6766

68-
# Convert response to ProjectInfoResponse
69-
return ProjectInfoResponse.model_validate(response.json())
67+
# Call the API endpoint
68+
response = await call_get(client, f"{project_url}/project/info")
69+
70+
# Convert response to ProjectInfoResponse
71+
return ProjectInfoResponse.model_validate(response.json())

0 commit comments

Comments
 (0)