feat(mcp): Refactor initialize_project tool for direct execution

Refactors the initialize_project MCP tool to call a dedicated direct function (initializeProjectDirect) instead of executing the CLI command. This improves reliability and aligns it with other MCP tools.

Key changes include: Modified initialize-project.js to call initializeProjectDirect, required projectRoot parameter, implemented handleApiResult for MCP response formatting, enhanced direct function to prioritize args.projectRoot over session-derived paths, added validation to prevent initialization in invalid directories, forces yes:true for non-interactive use, ensures process.chdir() targets validated directory, and added isSilentMode() checks to suppress console output during MCP operations.

This resolves issues where the tool previously failed due to incorrect fallback directory resolution when session context was incomplete.
This commit is contained in:
Eyal Toledano
2025-04-11 01:16:32 -04:00
parent 59208ab7a9
commit e88682f881
12 changed files with 8487 additions and 8278 deletions

View File

@@ -28,6 +28,7 @@ import { fixDependenciesDirect } from './direct-functions/fix-dependencies.js';
import { complexityReportDirect } from './direct-functions/complexity-report.js';
import { addDependencyDirect } from './direct-functions/add-dependency.js';
import { removeTaskDirect } from './direct-functions/remove-task.js';
import { initializeProjectDirect } from './direct-functions/initialize-project-direct.js';
// Re-export utility functions
export { findTasksJsonPath } from './utils/path-utils.js';
@@ -92,5 +93,6 @@ export {
fixDependenciesDirect,
complexityReportDirect,
addDependencyDirect,
removeTaskDirect
removeTaskDirect,
initializeProjectDirect
};