Skip to content

Fix MCP file operations server errors#39

Merged
ltawfik merged 4 commits into
mainfrom
fix-mcp-undefined-error
May 23, 2025
Merged

Fix MCP file operations server errors#39
ltawfik merged 4 commits into
mainfrom
fix-mcp-undefined-error

Conversation

@ltawfik

@ltawfik ltawfik commented May 23, 2025

Copy link
Copy Markdown
Collaborator

Fixes MCP github_file_ops server returning undefined errors when committing files.

Changes

  • Fix error response format in MCP server
  • Add proper file path resolution using GITHUB_WORKSPACE

Testing

Tested locally to verify error format and file path resolution work correctly.

ltawfik added 2 commits May 23, 2025 11:17
- 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

claude Bot commented May 23, 2025

Copy link
Copy Markdown
Contributor

Claude finished @ltawfik's task —— View job


Code Review: Fix MCP file operations server errors

After 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 Changes

Error 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,
};
  • Good: Now returns proper MCP server response format with structured error information
  • Good: Includes both human-readable content and machine-readable error fields
  • Good: The isError: true flag provides clear error state indication

File Path Resolution (src/mcp/install-mcp-server.ts:37)

Adding GITHUB_WORKSPACE fallback is practical:

REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd(),
  • Good: Addresses GitHub Actions environment where GITHUB_WORKSPACE is the standard
  • Good: Maintains backward compatibility with process.cwd() fallback

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);
  • Good: Handles both absolute and relative paths appropriately
  • Good: Uses REPO_DIR for proper workspace resolution

🔍 Areas for Consideration

1. Inconsistent Path Handling Logic

There's a discrepancy in how paths are processed between the commit_files and delete_files functions:

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 Construction

In commit_files (lines 122-124), there's potential for path confusion:

const fullPath = filePath.startsWith('/') 
  ? filePath 
  : join(REPO_DIR, filePath);

If filePath is already processed to remove leading slashes (line 76-81), this logic might not work as expected for originally absolute paths.

3. Error Message Consistency

Both functions have identical error handling patterns. Consider extracting this into a shared helper function to reduce code duplication.

🛡️ Security & Robustness

  • Good: No security vulnerabilities introduced
  • Good: Proper error handling prevents information leakage
  • Good: Path validation in delete_files prevents directory traversal

📝 Minor Suggestions

  1. Type Safety: The file path processing logic could benefit from more explicit typing
  2. Documentation: Consider adding JSDoc comments for the path resolution logic
  3. Testing: The changes would benefit from unit tests to verify path handling edge cases

🎯 Overall Assessment

This is a solid improvement that addresses the core issues mentioned in the PR description. The error handling is much better structured, and the GITHUB_WORKSPACE integration is essential for GitHub Actions environments. The changes are focused and don't introduce breaking changes.

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

  • Read changed files to understand the MCP server modifications
  • Analyze error handling improvements in github-file-ops-server.ts
  • Review file path resolution changes using GITHUB_WORKSPACE
  • Check for potential bugs or security issues
  • Provide comprehensive code review feedback

@ltawfik ltawfik requested a review from bcherny May 23, 2025 18:39
@ltawfik ltawfik merged commit cbc3ca2 into main May 23, 2025
4 checks passed
shabaraba pushed a commit to shabaraba/claude-code-action that referenced this pull request May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants