Skip to content

Commit a8b83a3

Browse files
committed
feat: add CLI arguments support
- 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
1 parent 1a53cf1 commit a8b83a3

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
### Claude Desktop
5454
Go to `Claude > Settings > Developer > Edit Config > claude_desktop_config.json` to include the following:
5555

56-
```
56+
**Option 1: Using environment variables (traditional)**
57+
```json
5758
{
5859
"mcpServers": {
5960
"MiniMax": {
@@ -71,8 +72,34 @@ Go to `Claude > Settings > Developer > Edit Config > claude_desktop_config.json`
7172
}
7273
}
7374
}
75+
```
7476

77+
**Option 2: Using CLI arguments (recommended for GitHub Copilot CLI)**
78+
```json
79+
{
80+
"mcpServers": {
81+
"MiniMax": {
82+
"command": "uvx",
83+
"args": [
84+
"minimax-mcp",
85+
"-y",
86+
"--api-key=insert-your-api-key-here",
87+
"--base-path=/User/xxx/Desktop",
88+
"--api-host=https://api.minimax.io",
89+
"--resource-mode=url"
90+
]
91+
}
92+
}
93+
}
7594
```
95+
96+
**CLI Arguments:**
97+
- `--api-key`: MiniMax API key (overrides MINIMAX_API_KEY)
98+
- `--base-path`: Local output directory path (overrides MINIMAX_MCP_BASE_PATH)
99+
- `--api-host`: API host URL (overrides MINIMAX_API_HOST)
100+
- `--resource-mode`: Resource mode [url|local] (overrides MINIMAX_API_RESOURCE_MODE)
101+
102+
CLI arguments take precedence over environment variables.
76103
⚠️ Warning: The API key needs to match the host. If an error "API Error: invalid api key" occurs, please check your api host:
77104
- Global Host:`https://api.minimax.io`
78105
- Mainland Host:`https://api.minimaxi.com`

minimax_mcp/server.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"""
1313

1414
import os
15+
import sys
1516
import base64
1617
import requests
1718
import time
@@ -30,12 +31,27 @@
3031
from minimax_mcp.exceptions import MinimaxAPIError, MinimaxRequestError
3132
from minimax_mcp.client import MinimaxAPIClient
3233

34+
# Parse CLI arguments
35+
cli_args = {}
36+
args = sys.argv[1:]
37+
for i in range(len(args)):
38+
if args[i].startswith('--'):
39+
key_value = args[i][2:].split('=', 1)
40+
if len(key_value) == 2:
41+
cli_args[key_value[0]] = key_value[1]
42+
elif i + 1 < len(args) and not args[i + 1].startswith('--'):
43+
cli_args[key_value[0]] = args[i + 1]
44+
45+
def get_config(cli_key: str, env_key: str, default: str = None) -> str:
46+
"""Get config value with CLI args taking precedence over env vars."""
47+
return cli_args.get(cli_key) or os.getenv(env_key) or default
48+
3349
load_dotenv()
34-
api_key = os.getenv(ENV_MINIMAX_API_KEY)
35-
base_path = os.getenv(ENV_MINIMAX_MCP_BASE_PATH) or "~/Desktop"
36-
api_host = os.getenv(ENV_MINIMAX_API_HOST)
37-
resource_mode = os.getenv(ENV_RESOURCE_MODE) or RESOURCE_MODE_URL
38-
fastmcp_log_level = os.getenv(ENV_FASTMCP_LOG_LEVEL) or "WARNING"
50+
api_key = get_config('api-key', ENV_MINIMAX_API_KEY)
51+
base_path = get_config('base-path', ENV_MINIMAX_MCP_BASE_PATH, '~/Desktop')
52+
api_host = get_config('api-host', ENV_MINIMAX_API_HOST)
53+
resource_mode = get_config('resource-mode', ENV_RESOURCE_MODE, RESOURCE_MODE_URL)
54+
fastmcp_log_level = get_config('log-level', ENV_FASTMCP_LOG_LEVEL, 'WARNING')
3955

4056
if not api_key:
4157
raise ValueError("MINIMAX_API_KEY environment variable is required")

0 commit comments

Comments
 (0)