Skip to content

Conversation

jfi
Copy link

@jfi jfi commented Jul 19, 2025

Overview

Following on from the discussion at #6, this PR enhances the GitHub MCP Extension for Zed by implementing automatic token authentication through wrapper scripts, addressing the limitation of Zed's WASM sandbox which cannot access host environment variables.

Problem Solved

Previously, users had to manually obtain and configure GitHub personal access tokens. This enhancement allows the extension to automatically use existing GitHub authentication from:

  • GitHub CLI (gh auth status)
  • Environment variables (GITHUB_TOKEN)
  • Token files (.github_token)

Key Features

🔄 Automatic Authentication

  • Auto-detection: Extension automatically detects and uses wrapper scripts
  • Multi-method support: GitHub CLI, environment variables, and token files
  • Cross-platform: Wrapper scripts for JavaScript (Node.js), Bash, and PowerShell
  • Backwards compatibility: Falls back to manual token configuration

📁 Improved Project Structure

  • Organized documentation: Dedicated configuration and troubleshooting guides
  • Wrapper scripts: Self-contained authentication handlers in wrappers/ directory
  • Clean configuration: Simplified settings with optional wrapper script usage

🛠 Enhanced User Experience

  • One-click setup: Simply set "use_wrapper_script": true in settings
  • Better error handling: Clear feedback when authentication fails
  • Comprehensive docs: Step-by-step guides for all supported platforms

NOTE: This should support Windows, but I don't have a machine lying around to test it.

Technical Implementation

Wrapper Script Auto-Detection

The extension automatically searches for wrapper scripts in the following order:

  1. github-mcp-wrapper.js (Node.js)
  2. github-mcp-wrapper.sh (Bash)
  3. github-mcp-wrapper.ps1 (PowerShell)

Authentication Flow

flowchart TD
    A[Extension Start] --> B{use_wrapper_script?}
    B -->|true| C[Detect Wrapper Script]
    B -->|false| D[Use Manual Token]
    C --> E{Script Found?}
    E -->|yes| F[Execute Wrapper]
    E -->|no| G[Log Warning + Use Manual Token]
    F --> H{Auth Successful?}
    H -->|yes| I[Initialize MCP Server]
    H -->|no| J[Show Error]
Loading

Configuration

Simple Setup

{
  "context_servers": {
    "mcp-server-github": {
      "source": "extension",
      "settings": {
        "use_wrapper_script": true
      }
    }
  }
}

Manual Fallback (Unchanged)

{
  "context_servers": {
    "mcp-server-github": {
      "source": "extension",
      "settings": {
        "github_token": "your_token_here"
      }
    }
  }
}

Files Added/Modified

New Files

  • wrappers/github-mcp-wrapper.js - Node.js authentication wrapper
  • wrappers/github-mcp-wrapper.sh - Bash authentication wrapper
  • wrappers/github-mcp-wrapper.ps1 - PowerShell authentication wrapper
  • wrappers/README.md - Wrapper script documentation
  • docs/configuration.md - Comprehensive configuration guide
  • docs/troubleshooting.md - Common issues and solutions
  • CHANGELOG.md - Version history

Modified Files

  • src/mcp_server_github.rs - Core extension logic with wrapper support
  • README.md - Updated with new features and simplified setup
  • configuration/default_settings.jsonc - Added wrapper script option

Removed Files

  • configuration/installation_instructions.md - Consolidated into docs/

Testing

The enhancement has been tested with:

  • ✅ GitHub CLI authentication (gh auth login)
  • ✅ Environment variable authentication (GITHUB_TOKEN)
  • ✅ Token file authentication (.github_token)
  • ✅ Manual token fallback
  • ✅ Error handling for missing/invalid authentication

Backwards Compatibility

  • ✅ All existing configurations continue to work unchanged
  • ✅ Manual token configuration remains fully supported
  • ✅ No breaking changes to existing functionality
  • ✅ Graceful fallback when wrapper scripts are unavailable

@jfi jfi changed the title feat: Add automatic GitHub authentication with wrapper scripts feat: Add "secret" GitHub authentication with wrapper scripts Jul 19, 2025
This enhancement addresses the limitation of Zed's WASM sandbox which cannot access host environment variables for GitHub authentication.

Key improvements:
- Add wrapper script auto-detection for seamless authentication
- Support multiple auth methods: GitHub CLI, environment variables, token files
- Provide wrapper scripts for cross-platform compatibility (JS/Bash/PowerShell)
- Maintain backwards compatibility with manual token configuration
- Reorganize documentation with dedicated configuration and troubleshooting guides

Features:
- Automatic detection of wrapper scripts in extension directory
- Fallback to manual token configuration if wrapper not available
- Improved error handling and user feedback
- Comprehensive documentation with examples

This enables users to authenticate with GitHub without manual token management while preserving all existing functionality.
@jfi jfi force-pushed the jfi/use-github-auth-token-from-cli branch from 7373e87 to 83491a4 Compare July 19, 2025 17:43
@jfi jfi mentioned this pull request Jul 19, 2025
@jeffreyguenther
Copy link
Member

I appreciate all the work that went into this. I prefer a first-party solution. The Zed team is keen to improve the extensions API, so I've taken this up with them.

Correct me if I'm wrong. It's my understanding the key thing we need is to have access the shell env of the user's machine. Then we can access the correct environment variables.

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