配置选项
gm-mcp 支持多种配置选项来定制项目创建过程。
命令行选项
init 命令选项
| 选项 | 简写 | 描述 | 默认值 | 示例 |
|---|---|---|---|---|
--template | -t | 选择项目模板 | basic | --template advanced |
--yes | -y | 跳过确认提示 | false | --yes |
全局选项
| 选项 | 简写 | 描述 | 示例 |
|---|---|---|---|
--help | -h | 显示帮助信息 | --help |
--version | -V | 显示版本信息 | --version |
环境变量
| 变量名 | 描述 | 默认值 | 示例 |
|---|---|---|---|
NPM_REGISTRY | npm注册表URL | https://registry.npmjs.org/ | https://registry.npmmirror.com |
GM_MCP_CACHE_DIR | 缓存目录 | ~/.gm-mcp/cache | /tmp/gm-mcp-cache |
GM_MCP_DEFAULT_TEMPLATE | 默认模板 | basic | advanced |
配置文件
创建 ~/.gm-mcp/config.json 文件:
json
{
"defaultTemplate": "basic",
"autoInstall": true,
"registry": "https://registry.npmmirror.com",
"cacheDir": "~/.gm-mcp/cache",
"templates": {
"custom": {
"path": "~/my-templates/custom",
"description": "我的自定义模板"
}
}
}配置选项说明
| 选项 | 类型 | 描述 | 默认值 |
|---|---|---|---|
defaultTemplate | string | 默认使用的模板 | basic |
autoInstall | boolean | 是否自动安装依赖 | true |
registry | string | npm注册表URL | https://registry.npmjs.org/ |
cacheDir | string | 缓存目录路径 | ~/.gm-mcp/cache |
templates | object | 自定义模板配置 | {} |
模板配置
内置模板
basic: 基础模板advanced: 高级模板minimal: 最小模板
自定义模板
json
{
"templates": {
"my-template": {
"path": "/path/to/template",
"description": "我的自定义模板",
"default": false
}
}
}使用示例
使用环境变量
bash
export GM_MCP_DEFAULT_TEMPLATE=advanced
export NPM_REGISTRY=https://registry.npmmirror.com
gm-mcp init my-project使用配置文件
bash
# 创建配置文件
mkdir -p ~/.gm-mcp
cat > ~/.gm-mcp/config.json << EOF
{
"defaultTemplate": "advanced",
"autoInstall": true,
"registry": "https://registry.npmmirror.com"
}
EOF
# 使用配置
gm-mcp init my-project命令行覆盖
bash
# 使用命令行选项覆盖配置
gm-mcp init my-project --template minimal --yes优先级
配置的优先级从高到低:
- 命令行选项
- 环境变量
- 配置文件
- 默认值
验证配置
bash
# 查看当前配置
gm-mcp version
# 测试配置
gm-mcp init test-project --template basic --yes故障排除
配置文件错误
如果配置文件格式错误,gm-mcp会使用默认配置并显示警告。
模板路径错误
如果自定义模板路径不存在,会回退到默认模板。
网络配置
如果npm注册表无法访问,会尝试使用备用注册表。