-
Notifications
You must be signed in to change notification settings - Fork 210
feat: add CLI arguments support for better MCP client compatibility #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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
There was a problem hiding this 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.
| 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] | ||
|
|
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
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.
| 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() |
| 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] |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
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.
| 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 |
| "minimax-mcp", | ||
| "-y", | ||
| "--api-key=insert-your-api-key-here", | ||
| "--base-path=/User/xxx/Desktop", |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
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.
| # 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 |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
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.
| return cli_args.get(cli_key) or os.getenv(env_key) or default | ||
|
|
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
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.
| 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 |
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
envblock, 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
--api-key,--base-path,--api-host,--resource-modeBenefits
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
Related Work
Similar improvements implemented in other MCP servers:
These PRs solve the same GitHub Copilot CLI compatibility issue.