Skip to content

Conversation

@alfonsodg
Copy link

Summary

This PR adds support for command-line arguments to configure the GitLab MCP server, solving compatibility issues with MCP clients that don't properly handle environment variables (like GitHub Copilot CLI).

Problem

Some MCP clients have issues with environment variables in server configurations. This makes it impossible to configure the GitLab MCP server in those clients.

Solution

Added CLI argument parsing that takes precedence over environment variables, allowing configuration through command-line arguments.

Changes

Core Changes

  • ✅ Added CLI argument parser at the start of index.ts
  • ✅ Created getConfig() helper function with proper TypeScript overloads
  • ✅ Updated all configuration variables to use getConfig()
  • ✅ CLI arguments take precedence over environment variables

Available CLI Arguments

  • --token - GitLab Personal Access Token (replaces GITLAB_PERSONAL_ACCESS_TOKEN)
  • --api-url - GitLab API URL (replaces GITLAB_API_URL)
  • --read-only - Enable read-only mode (replaces GITLAB_READ_ONLY_MODE)
  • --use-wiki - Enable wiki API (replaces USE_GITLAB_WIKI)
  • --use-milestone - Enable milestone API (replaces USE_MILESTONE)
  • --use-pipeline - Enable pipeline API (replaces USE_PIPELINE)

Documentation

  • ✅ Added new section in README explaining CLI arguments
  • ✅ Documented the GitHub Copilot CLI compatibility issue
  • ✅ Provided examples for both env vars and CLI args

Usage Examples

With environment variables (existing behavior):

{
  "mcpServers": {
    "gitlab": {
      "command": "npx",
      "args": ["-y", "@zereight/mcp-gitlab"],
      "env": {
        "GITLAB_PERSONAL_ACCESS_TOKEN": "your_token",
        "GITLAB_API_URL": "https://gitlab.com/api/v4"
      }
    }
  }
}

With CLI arguments (new feature):

{
  "mcpServers": {
    "gitlab": {
      "command": "npx",
      "args": [
        "-y",
        "@zereight/mcp-gitlab",
        "--token=your_token",
        "--api-url=https://gitlab.com/api/v4"
      ]
    }
  }
}

Backward Compatibility

Fully backward compatible - All existing configurations using environment variables will continue to work without any changes.

Testing

  • ✅ Compiled successfully with TypeScript
  • ✅ Tested with GitHub Copilot CLI (previously broken, now works)
  • ✅ Tested with environment variables (still works)
  • ✅ Tested CLI args precedence over env vars

Benefits

  1. Broader Compatibility - Works with all MCP clients, including those with env var issues
  2. Flexibility - Users can choose between env vars or CLI args
  3. No Breaking Changes - Existing configurations continue to work
  4. Better DX - Clearer error messages mentioning both configuration methods

Related Issues

Fixes compatibility with GitHub Copilot CLI and similar MCP clients that have environment variable handling issues.

Allows configuration via command-line arguments for MCP clients
that don't support environment variables (like GitHub Copilot CLI).

CLI arguments take precedence over environment variables.

Available arguments:
- --token: GitLab Personal Access Token
- --api-url: GitLab API URL
- --read-only: Enable read-only mode
- --use-wiki: Enable wiki API
- --use-milestone: Enable milestone API
- --use-pipeline: Enable pipeline API

Example:
  npx @zereight/mcp-gitlab --token=glpat-xxx --api-url=https://gitlab.com/api/v4
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.

1 participant