Skip to content

Conversation

@alfonsodg
Copy link

@alfonsodg alfonsodg commented Dec 9, 2025

Problem

GitHub Copilot CLI v1.2.0 has a known bug where environment variables in MCP server configurations are not properly passed to the server process. This affects MiniMax-MCP and other MCP servers that rely on environment variables for configuration.

Issue: When configured with env block, the server starts but cannot access API keys or other configuration values, causing authentication failures.

Solution

This PR adds CLI argument support as an alternative configuration method that works reliably across all MCP clients, including GitHub Copilot CLI.

Changes

  • Added CLI argument parser for --api-key, --base-path, --api-host, --resource-mode
  • CLI arguments take precedence over environment variables
  • Updated README with both configuration options
  • Maintains backward compatibility with existing configurations

Benefits

  • ✅ Solves environment variable issues in GitHub Copilot CLI (known bug in v1.2.0)
  • ✅ Better compatibility across all MCP clients
  • ✅ More flexible configuration options
  • ✅ No breaking changes - existing configs continue to work

Configuration Examples

Traditional (environment variables) - works in most clients:

{
  "command": "uvx",
  "args": ["minimax-mcp", "-y"],
  "env": {
    "MINIMAX_API_KEY": "your-key"
  }
}

New (CLI arguments) - works in ALL clients including Copilot CLI:

{
  "command": "uvx",
  "args": [
    "minimax-mcp",
    "-y",
    "--api-key=your-key"
  ]
}

Testing

  • ✅ Tested with GitHub Copilot CLI (previously broken, now works)
  • ✅ Tested with Claude Desktop (continues to work)
  • ✅ Backward compatibility verified with env vars

Related Work

Similar improvements implemented in other MCP servers:

These PRs solve the same GitHub Copilot CLI compatibility issue.

- Add --api-key, --base-path, --api-host, --resource-mode arguments
- CLI arguments take precedence over environment variables
- Improves compatibility with GitHub Copilot CLI
- Update README with both configuration options
Copilot AI review requested due to automatic review settings January 19, 2026 00:36
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 support to MiniMax-MCP to address a known bug in GitHub Copilot CLI v1.2.0 where environment variables are not properly passed to MCP server processes. The implementation maintains backward compatibility while providing an alternative configuration method.

Changes:

  • Added CLI argument parser with support for --api-key, --base-path, --api-host, --resource-mode, and --log-level
  • Implemented precedence hierarchy: CLI arguments > environment variables > defaults
  • Updated README with configuration examples for both environment variables and CLI arguments

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
minimax_mcp/server.py Added CLI argument parsing logic and get_config helper function to support CLI arguments with fallback to environment variables
README.md Added documentation for CLI argument configuration option with examples, marked as recommended for GitHub Copilot CLI
Comments suppressed due to low confidence (1)

minimax_mcp/server.py:59

  • The error messages still reference only environment variables, but now the values can also be provided via CLI arguments. The error messages should be updated to reflect both configuration methods to avoid confusion when users provide values via CLI arguments but still see error messages mentioning environment variables.
if not api_key:
    raise ValueError("MINIMAX_API_KEY environment variable is required")
if not api_host:
    raise ValueError("MINIMAX_API_HOST environment variable is required")

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

Comment on lines +35 to +44
cli_args = {}
args = sys.argv[1:]
for i in range(len(args)):
if args[i].startswith('--'):
key_value = args[i][2:].split('=', 1)
if len(key_value) == 2:
cli_args[key_value[0]] = key_value[1]
elif i + 1 < len(args) and not args[i + 1].startswith('--'):
cli_args[key_value[0]] = args[i + 1]

Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The CLI argument parsing code (lines 35-43) executes at module import time, which makes it difficult to test and could cause issues if this module is imported elsewhere. Consider wrapping this logic in a function (e.g., 'parse_cli_args') that can be called explicitly and tested independently.

Suggested change
cli_args = {}
args = sys.argv[1:]
for i in range(len(args)):
if args[i].startswith('--'):
key_value = args[i][2:].split('=', 1)
if len(key_value) == 2:
cli_args[key_value[0]] = key_value[1]
elif i + 1 < len(args) and not args[i + 1].startswith('--'):
cli_args[key_value[0]] = args[i + 1]
def parse_cli_args(argv=None):
"""Parse command-line arguments into a dictionary.
Supports flags in the form --key=value or --key value.
"""
if argv is None:
argv = sys.argv[1:]
parsed = {}
for i in range(len(argv)):
if argv[i].startswith('--'):
key_value = argv[i][2:].split('=', 1)
if len(key_value) == 2:
parsed[key_value[0]] = key_value[1]
elif i + 1 < len(argv) and not argv[i + 1].startswith('--'):
parsed[key_value[0]] = argv[i + 1]
return parsed
cli_args = parse_cli_args()

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +43
for i in range(len(args)):
if args[i].startswith('--'):
key_value = args[i][2:].split('=', 1)
if len(key_value) == 2:
cli_args[key_value[0]] = key_value[1]
elif i + 1 < len(args) and not args[i + 1].startswith('--'):
cli_args[key_value[0]] = args[i + 1]
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The CLI argument parser has a potential issue with how it handles arguments. When parsing an argument like '--api-key' without a value (line 42), it will consume the next argument even if it's another flag or option. This could lead to unexpected behavior if someone accidentally omits a value. Additionally, the parser will skip incrementing the loop counter when it consumes the next argument, potentially processing the same argument twice.

Suggested change
for i in range(len(args)):
if args[i].startswith('--'):
key_value = args[i][2:].split('=', 1)
if len(key_value) == 2:
cli_args[key_value[0]] = key_value[1]
elif i + 1 < len(args) and not args[i + 1].startswith('--'):
cli_args[key_value[0]] = args[i + 1]
i = 0
while i < len(args):
arg = args[i]
if arg.startswith('--'):
key_value = arg[2:].split('=', 1)
key = key_value[0]
if len(key_value) == 2:
# Handle --key=value form
cli_args[key] = key_value[1]
elif i + 1 < len(args) and not args[i + 1].startswith('-'):
# Handle --key value form, ensuring the next token is not another flag
cli_args[key] = args[i + 1]
i += 1 # Skip the value we just consumed
i += 1

Copilot uses AI. Check for mistakes.
"minimax-mcp",
"-y",
"--api-key=insert-your-api-key-here",
"--base-path=/User/xxx/Desktop",
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The path '/User/xxx/Desktop' is incorrect for macOS/Unix systems. The correct path should be '/Users/xxx/Desktop' (with an 's'). This appears in both the CLI argument example and should be corrected to avoid confusing users.

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +47
# Parse CLI arguments
cli_args = {}
args = sys.argv[1:]
for i in range(len(args)):
if args[i].startswith('--'):
key_value = args[i][2:].split('=', 1)
if len(key_value) == 2:
cli_args[key_value[0]] = key_value[1]
elif i + 1 < len(args) and not args[i + 1].startswith('--'):
cli_args[key_value[0]] = args[i + 1]

def get_config(cli_key: str, env_key: str, default: str = None) -> str:
"""Get config value with CLI args taking precedence over env vars."""
return cli_args.get(cli_key) or os.getenv(env_key) or default
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The newly added CLI argument parsing logic (lines 34-43) and the get_config function (lines 45-47) lack test coverage. Since the repository has existing test infrastructure in the tests directory, these new functions should have corresponding unit tests to verify correct behavior, especially for edge cases like missing values, empty strings, and various argument formats.

Copilot uses AI. Check for mistakes.
Comment on lines +47 to +48
return cli_args.get(cli_key) or os.getenv(env_key) or default

Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The get_config function uses the 'or' operator for fallback logic, which means empty strings will be treated as falsy and fall through to the next option. If a user explicitly sets a CLI argument to an empty string (e.g., '--api-key='), it will fall back to the environment variable or default value instead of using the empty string. This behavior should be intentional, but if it's not, consider using 'is None' checks instead.

Suggested change
return cli_args.get(cli_key) or os.getenv(env_key) or default
cli_value = cli_args.get(cli_key)
if cli_value is not None:
return cli_value
env_value = os.getenv(env_key)
if env_value is not None:
return env_value
return default

Copilot uses AI. Check for mistakes.
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