anthropics / anthropics/claude-code-action

GitHub MCP Docker server missing REPO_OWNER/REPO_NAME environment variables

Ouverte
#640 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
bug mcp p2
Langage dominant
TypeScript
Étoiles
8.9k
Forks
2.1k
Merge moyen
3 j 9 h
PR mergées (30 j)
10

Description

## Bug Report: GitHub MCP Docker server missing REPO_OWNER/REPO_NAME environment variables

### Description

The GitHub MCP server (Docker-based) does not receive `REPO_OWNER` and `REPO_NAME` environment variables, causing it to infer incorrect repository owner from GitHub App token metadata. This results in 404 errors when the GitHub App owner differs from the repository owner.

### Environment

- **Action Version**: `anthropics/claude-code-action@v1`
- **GitHub Environment**: GitHub Enterprise Server 3.17
- **MCP Server**: `ghcr.io/github/github-mcp-server` (Docker)
- **Authentication**: GitHub App (via `actions/create-github-app-token@v2`)

### Current Behavior

The action creates three MCP servers with **inconsistent** configuration:

1. ✅ **`github_inline_comment`** server (Bun-based):
```yaml
env:
REPO_OWNER: "ActualRepoOwner"
REPO_NAME: "example-repo"
```

2. ✅ **`github_ci`** server (Bun-based):
```yaml
env:
REPO_OWNER: "ActualRepoOwner"
REPO_NAME: "example-repo"
```

3. ❌ **`github`** MCP server (Docker-based):
```yaml
env:
GITHUB_PERSONAL_ACCESS_TOKEN: "***"
GITHUB_HOST: "https://ghe.company.com"
# MISSING: REPO_OWNER and REPO_NAME
```

### Expected Behavior

All three MCP servers should receive `REPO_OWNER` and `REPO_NAME` environment variables for consistency.

**Expected configuration for `github` server:**
```yaml
{
"github": {
"command": "docker",
"args": ["run", "-i", "--rm",
"-e", "GITHUB_PERSONAL_ACCESS_TOKEN",
"-e", "GITHUB_HOST",
"-e", "REPO_OWNER", // ← ADD THIS
"-e", "REPO_NAME", // ← ADD THIS
"ghcr.io/github/github-mcp-server:latest"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "***",
"GITHUB_HOST": "https://ghe.company.com",
"REPO_OWNER": "ActualRepoOwner", // ← ADD THIS
"REPO_NAME": "example-repo" // ← ADD THIS
}
}
}
```

### Impact

**Symptom**: GitHub MCP tools fail with 404 errors

**Affected Tools**:
- `mcp__github__get_pull_request`
- `mcp__github__get_pull_request_files`
- `mcp__github__get_pull_request_diff`
- Other `mcp__github__*` tools

**Error Pattern**:
```
API calls to: https://ghe.company.com/api/v3/repos/GitHubAppOwner/example-repo/pulls/123
^^^^^^^^^^^^^^^^
Wrong org inferred from GitHub App owner
Expected: https://ghe.company.com/api/v3/repos/ActualRepoOwner/example-repo/pulls/123
```

### Root Cause

When `REPO_OWNER` is not provided, the GitHub MCP Docker container infers the repository owner from the GitHub App installation token metadata.

**Scenario where this fails**:
- GitHub App is owned by organization "GitHubAppOwner"
- Repository is owned by organization "ActualRepoOwner"
- Docker container uses App owner ("GitHubAppOwner") instead of repo owner ("ActualRepoOwner")
- API calls fail with 404 errors

This is a common scenario in organizations that:
- Have multiple GitHub organizations
- Use a centralized GitHub App across organizations
- Use GitHub Enterprise with different org structures

### Steps to Reproduce

1. Create a GitHub App under organization A (e.g., "GitHubAppOwner")
2. Install the App in a repository under organization B (e.g., "ActualRepoOwner/example-repo")
3. Use `anthropics/claude-code-action@v1` with:
```yaml
- uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}

- uses: anthropics/claude-code-action@v1
with:
github_token: ${{ steps.token.outputs.token }}
prompt: "Review PR"
```
4. Observe 404 errors when Claude attempts to use `mcp__github__*` tools

### Actual vs Expected Results

**Actual**:
- GitHub MCP server uses inferred owner from App token → "GitHubAppOwner"
- API calls: `GET /repos/GitHubAppOwner/example-repo/pulls/123` → **404 Not Found**

**Expected**:
- GitHub MCP server uses explicit `REPO_OWNER` → "ActualRepoOwner"
- API calls: `GET /repos/ActualRepoOwner/example-repo/pulls/123` → **200 OK**

### Workaround

Users can override the MCP configuration via `claude_args`:

```yaml
- name: Build MCP config
id: mcp_config
run: |
cat > /tmp/mcp-config.json <<'EOF'
{
"mcpServers": {
"github": {
"command": "docker",
"args": ["run", "-i", "--rm",
"-e", "GITHUB_PERSONAL_ACCESS_TOKEN",
"-e", "GITHUB_HOST",
"-e", "REPO_OWNER",
"-e", "REPO_NAME",
"ghcr.io/github/github-mcp-server:latest"],
"env": {
"REPO_OWNER": "${{ github.repository_owner }}",
"REPO_NAME": "${{ github.event.repository.name }}"
}
}
}
}
EOF
echo "config_file=/tmp/mcp-config.json" >> $GITHUB_OUTPUT

- uses: anthropics/claude-code-action@v1
with:
claude_args: --mcp-config ${{ steps.mcp_config.outputs.config_file }}
```

However, this requires workflow modifications and is not ideal.

### Suggested Fix

Update the GitHub MCP server configuration in the action to include `REPO_OWNER` and `REPO_NAME`, matching the pattern used for `github_inline_comment` and `github_ci` servers.

**Proposed code location**: Where the action constructs the MCP server configuration for the Docker-based GitHub server

**Proposed change**: Add environment variables similar to the Bun-based servers:
```typescript
// Existing pattern for github_inline_comment and github_ci
const repo_owner = context.repo.owner;
const repo_name = context.repo.repo;

// Apply same pattern to github Docker server
mcpServers.github = {
command: "docker",
args: [
"run", "-i", "--rm",
"-e", "GITHUB_PERSONAL_ACCESS_TOKEN",
"-e", "GITHUB_HOST",
"-e", "REPO_OWNER", // ← Add this
"-e", "REPO_NAME", // ← Add this
"ghcr.io/github/github-mcp-server:latest"
],
env: {
GITHUB_PERSONAL_ACCESS_TOKEN: token,
GITHUB_HOST: apiUrl,
REPO_OWNER: repo_owner, // ← Add this
REPO_NAME: repo_name // ← Add this
}
};
```

### Additional Context

This issue affects organizations using:
- GitHub Enterprise
- Multi-organization setups
- Centralized GitHub App installations
- Any scenario where App owner ≠ repository owner

### Related Information

- Similar configuration works correctly for `github_inline_comment` and `github_ci` servers
- The issue is specific to the Docker-based GitHub MCP server
- Docker container expects these variables to be passed via `-e` flags
- Without explicit variables, the container falls back to App token introspection

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.