Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
### Claude Desktop
Go to `Claude > Settings > Developer > Edit Config > claude_desktop_config.json` to include the following:

```
**Option 1: Using environment variables (traditional)**
```json
{
"mcpServers": {
"MiniMax": {
Expand All @@ -71,8 +72,34 @@ Go to `Claude > Settings > Developer > Edit Config > claude_desktop_config.json`
}
}
}
```

**Option 2: Using CLI arguments (recommended for GitHub Copilot CLI)**
```json
{
"mcpServers": {
"MiniMax": {
"command": "uvx",
"args": [
"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.
"--api-host=https://api.minimax.io",
"--resource-mode=url"
]
}
}
}
```

**CLI Arguments:**
- `--api-key`: MiniMax API key (overrides MINIMAX_API_KEY)
- `--base-path`: Local output directory path (overrides MINIMAX_MCP_BASE_PATH)
- `--api-host`: API host URL (overrides MINIMAX_API_HOST)
- `--resource-mode`: Resource mode [url|local] (overrides MINIMAX_API_RESOURCE_MODE)

CLI arguments take precedence over environment variables.
⚠️ Warning: The API key needs to match the host. If an error "API Error: invalid api key" occurs, please check your api host:
- Global Host:`https://api.minimax.io`
- Mainland Host:`https://api.minimaxi.com`
Expand Down
26 changes: 21 additions & 5 deletions minimax_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""

import os
import sys
import base64
import requests
import time
Expand All @@ -30,12 +31,27 @@
from minimax_mcp.exceptions import MinimaxAPIError, MinimaxRequestError
from minimax_mcp.client import MinimaxAPIClient

# 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]
Comment on lines +37 to +43
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.

Comment on lines +35 to +44
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.
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
Comment on lines +34 to +47
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
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.
load_dotenv()
api_key = os.getenv(ENV_MINIMAX_API_KEY)
base_path = os.getenv(ENV_MINIMAX_MCP_BASE_PATH) or "~/Desktop"
api_host = os.getenv(ENV_MINIMAX_API_HOST)
resource_mode = os.getenv(ENV_RESOURCE_MODE) or RESOURCE_MODE_URL
fastmcp_log_level = os.getenv(ENV_FASTMCP_LOG_LEVEL) or "WARNING"
api_key = get_config('api-key', ENV_MINIMAX_API_KEY)
base_path = get_config('base-path', ENV_MINIMAX_MCP_BASE_PATH, '~/Desktop')
api_host = get_config('api-host', ENV_MINIMAX_API_HOST)
resource_mode = get_config('resource-mode', ENV_RESOURCE_MODE, RESOURCE_MODE_URL)
fastmcp_log_level = get_config('log-level', ENV_FASTMCP_LOG_LEVEL, 'WARNING')

if not api_key:
raise ValueError("MINIMAX_API_KEY environment variable is required")
Expand Down
Loading