Skip to content

feat: add CLI arguments support for configuration#291

Merged
zereight merged 4 commits intozereight:mainfrom
alfonsodg:main
Jan 14, 2026
Merged

feat: add CLI arguments support for configuration#291
zereight merged 4 commits intozereight:mainfrom
alfonsodg:main

Conversation

@alfonsodg
Copy link
Contributor

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
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds CLI argument parsing support to the GitLab MCP server to address compatibility issues with MCP clients that don't properly handle environment variables (such as GitHub Copilot CLI). CLI arguments take precedence over environment variables while maintaining full backward compatibility.

Key Changes:

  • Added CLI argument parser at the top of index.ts with --key=value and --key value syntax support
  • Created getConfig() helper function with TypeScript overloads to unify configuration retrieval from CLI args and environment variables
  • Updated all configuration constants to use getConfig() instead of direct process.env access

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.

File Description
package.json Updated package name to @alfonsodg/mcp-gitlab, bumped version to 2.0.14, and enhanced description to mention CLI args support
package-lock.json Removed "peer: true" flags from various dependencies (npm version update artifact)
index.ts Implemented CLI argument parser, added getConfig() helper function, and migrated all configuration variables to use the new unified config retrieval system
README.md Added new section documenting CLI arguments with usage examples and available argument list for compatibility with clients having environment variable issues

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zereight
Copy link
Owner

zereight commented Jan 4, 2026

@alfonsodg Thanks plz resolve conflicts

Copy link
Owner

@zereight zereight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of conflicts

- Integrate multi-URL support for GITLAB_API_URL
- Add ENABLE_DYNAMIC_API_URL and GITLAB_POOL_MAX_SIZE options
- Update HOST default to 127.0.0.1
- Maintain CLI arguments support for all new options
- Bump version to 2.0.22
@zereight zereight merged commit ad2d2ef into zereight:main Jan 14, 2026
5 checks passed
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