Fix MCP file operations server errors#39
Conversation
- Add error field to MCP error responses to fix 'undefined' errors - Add REPO_DIR environment variable to fix file path resolution - Use GITHUB_WORKSPACE for correct repository directory - Simplify path processing logic in commit_files tool This fixes the issue where mcp__github_file_ops__commit_files would fail with 'Error calling tool commit_files: undefined' by ensuring error messages are properly formatted and files are read from the correct directory.
|
Claude finished @ltawfik's task —— View job Code Review: Fix MCP file operations server errorsAfter reviewing the changes in this PR, I've identified several positive improvements and some areas that could be enhanced further. Here's my detailed analysis: ✅ Positive ChangesError Handling Improvements (src/mcp/github-file-ops-server.ts:231-242)The updated error response format is a significant improvement: return {
content: [{ type: "text", text: `Error: ${errorMessage}` }],
error: errorMessage,
isError: true,
};
File Path Resolution (src/mcp/install-mcp-server.ts:37)Adding REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd(),
Improved File Path Handling (src/mcp/github-file-ops-server.ts:122-124)The file path resolution logic is more robust: const fullPath = filePath.startsWith('/')
? filePath
: join(REPO_DIR, filePath);
🔍 Areas for Consideration1. Inconsistent Path Handling LogicThere's a discrepancy in how paths are processed between the commit_files (lines 76-81): Simple leading slash removal const processedFiles = files.map((filePath) => {
if (filePath.startsWith("/")) {
return filePath.slice(1);
}
return filePath;
});delete_files (lines 271-283): More sophisticated validation const processedPaths = paths.map((filePath) => {
if (filePath.startsWith("/")) {
if (filePath.startsWith(cwd)) {
return filePath.slice(cwd.length + 1);
} else {
throw new Error(`Path '${filePath}' must be relative to repository root...`);
}
}
return filePath;
});Recommendation: Consider standardizing this logic across both functions for consistency. 2. File Reading Path ConstructionIn const fullPath = filePath.startsWith('/')
? filePath
: join(REPO_DIR, filePath);If 3. Error Message ConsistencyBoth functions have identical error handling patterns. Consider extracting this into a shared helper function to reduce code duplication. 🛡️ Security & Robustness
📝 Minor Suggestions
🎯 Overall AssessmentThis is a solid improvement that addresses the core issues mentioned in the PR description. The error handling is much better structured, and the Recommendation: ✅ Approve with minor suggestions - The changes solve the immediate problems and improve the codebase. The path handling inconsistency could be addressed in a follow-up PR if desired. Review completed ✅
|
Fix MCP file operations server errors
Fixes MCP
github_file_opsserver returning undefined errors when committing files.Changes
Testing
Tested locally to verify error format and file path resolution work correctly.