You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refactor: introduce ProjectResolver and unify project selection across MCP/API/CLI #493
# Add optional default project support to API if needed# Currently API is path-driven which is correct for REST semantics# But could add header-based project selection later
✅ Implement ProjectResolver class with typed results
✅ Comprehensive unit tests (mirror existing test_project_context.py)
✅ Update mcp/project_context.py to use ProjectResolver internally
✅ Verify all MCP tests still pass (behavior preserved)
Phase 2: CLI Integration (Follow-up PR)
Create CLI helper in cli/commands/command_utils.py
Replace manual default_project access across CLI commands
Add CLI integration tests
Phase 3: API Enhancement (Optional, Future)
Consider adding optional default project support to API
Would require middleware or header-based project selection
Lower priority since API's path-based approach is RESTful
Dependencies & Ordering
Mentioned in issue:
Ideally after containers/config injection work, so resolver is used via injected config
Current assessment:
✅ Config is already injectable (BasicMemoryConfig via ConfigManager)
✅ Can implement now without waiting for container work
✅ When container work lands, switch from ConfigManager() to injected config
Suggested approach:
Implement ProjectResolver now with ConfigManager() dependency
When container/DI work completes, refactor to inject config
This allows incremental progress without blocking on other work
Issue Classification
Type: Enhancement / Refactoring Priority: Medium Component: MCP, CLI, Architecture Complexity: Medium
Estimated scope:
Phase 1 (core): ~200 LOC + ~150 LOC tests
Phase 2 (CLI): ~100 LOC changes across 5-7 files
Well-scoped with clear acceptance criteria
Label applied:enhancement
Summary
This is a well-defined refactoring task with clear benefits:
✅ Reduces duplication - Single implementation replacing 3+ scattered versions
✅ Improves maintainability - One place to update project resolution logic
✅ Better observability - Typed results explain how projects were resolved
✅ Preserves behavior - Can maintain backward compatibility during transition
✅ Aligns with architecture - Fits dependency injection pattern
The existing MCP implementation in project_context.py serves as an excellent starting point - it already handles all the complex cases (cloud mode, env constraints, discovery mode). The refactor would extract and enhance this logic into a reusable service.
Ready to proceed with implementation when prioritized. I recommend starting with Phase 1 (core ProjectResolver) as it provides immediate value and can be tested in isolation before broader integration.
Activity
claude commentedon Dec 31, 2025
Claude finished @phernandez's task in 3m 27s —— View job
Analysis Complete: ProjectResolver Refactor
Task List
Current State Analysis
I've completed a thorough analysis of the project resolution logic across the codebase. Here's what I found:
1. MCP Layer (
src/basic_memory/mcp/project_context.py)Strengths:
resolve_project_parameter()with clear three-tier hierarchytests/mcp/test_project_context.py)Resolution logic:
2. CLI Layer (
src/basic_memory/cli/commands/)Issues:
ConfigManager().config.default_projectget_active_project(), others don't)Examples of duplication:
tool.py(lines 110, 145, 182, 262):project_name or config_manager.default_projectformat.py(line 173): Manual default project handlingcommand_utils.py: Usesget_active_project()but no standalone CLI resolution3. API Layer (
src/basic_memory/deps.py,src/basic_memory/api/v2/routers/)Current approach:
ProjectPathDep(path-based)ProjectIdPathDep(more efficient)/v2/projects/resolve(name/permalink → ID)Issues:
4. Environment Variables
BASIC_MEMORY_MCP_PROJECT- CLI constraint for MCP server (takes highest priority)mcpcommandIdentified Inconsistencies
Duplication: Same resolution logic exists in:
mcp/project_context.py::resolve_project_parameter()- most completedefault_projectMissing Coverage:
BASIC_MEMORY_MCP_PROJECTenv varBehavioral Differences:
Proposed Solution:
ProjectResolverDesign Goals
Proposed Implementation
Location:
src/basic_memory/services/project_resolver.pyCore Types:
Integration Points
MCP Layer (
project_context.py):CLI Layer (
cli/commands/command_utils.py):API Layer (optional enhancement):
Recommendations
Phase 1: Core Implementation (This PR)
src/basic_memory/services/project_resolver.pyProjectResolverclass with typed resultstest_project_context.py)mcp/project_context.pyto useProjectResolverinternallyPhase 2: CLI Integration (Follow-up PR)
cli/commands/command_utils.pyPhase 3: API Enhancement (Optional, Future)
Dependencies & Ordering
Mentioned in issue:
Current assessment:
BasicMemoryConfigviaConfigManager)ConfigManager()to injected configSuggested approach:
ProjectResolvernow withConfigManager()dependencyIssue Classification
Type: Enhancement / Refactoring
Priority: Medium
Component: MCP, CLI, Architecture
Complexity: Medium
Estimated scope:
Label applied:
enhancementSummary
This is a well-defined refactoring task with clear benefits:
✅ Reduces duplication - Single implementation replacing 3+ scattered versions
✅ Improves maintainability - One place to update project resolution logic
✅ Better observability - Typed results explain how projects were resolved
✅ Preserves behavior - Can maintain backward compatibility during transition
✅ Aligns with architecture - Fits dependency injection pattern
The existing MCP implementation in
project_context.pyserves as an excellent starting point - it already handles all the complex cases (cloud mode, env constraints, discovery mode). The refactor would extract and enhance this logic into a reusable service.Ready to proceed with implementation when prioritized. I recommend starting with Phase 1 (core
ProjectResolver) as it provides immediate value and can be tested in isolation before broader integration.refactor: introduce ProjectResolver for unified project selection (#493)