1.6 KiB
1.6 KiB
Fix MCP server undefined error and file path resolution
Problem
The mcp__github_file_ops__commit_files tool was failing with "Error calling tool commit_files: undefined" when Claude tried to commit files through the GitHub Action.
Root Causes
- Error format mismatch: The MCP server returned errors with the message in a
contentfield, but the claude-cli-internal client expected it in anerrorfield - Working directory mismatch: The MCP server couldn't find repository files because it was looking in the wrong directory
Solution
- Added
errorfield to error responses in bothcommit_filesanddelete_filestools - Added
REPO_DIRenvironment variable support to the MCP server - Updated file reading to use
REPO_DIRfor correct path resolution - Pass
GITHUB_WORKSPACEto the MCP server configuration
Changes
src/mcp/github-file-ops-server.ts
- Added
errorfield to error response objects - Added
REPO_DIRenvironment variable (defaults toprocess.cwd()) - Updated file reading to construct full paths using
REPO_DIR - Simplified path processing logic
src/mcp/install-mcp-server.ts
- Added
REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd()to MCP server environment
Testing
- Created local tests to verify error format fix
- Confirmed that "undefined" errors are now replaced with actual error messages
- Verified that the MCP server can handle both relative and absolute file paths
Impact
- Fixes the immediate "undefined" error issue
- Enables proper file path resolution in GitHub Actions environment
- Provides clearer error messages for debugging
Fixes #[issue-number-if-applicable]