Skip to content

配置选项

gm-mcp 支持多种配置选项来定制项目创建过程。

命令行选项

init 命令选项

选项简写描述默认值示例
--template-t选择项目模板basic--template advanced
--yes-y跳过确认提示false--yes

全局选项

选项简写描述示例
--help-h显示帮助信息--help
--version-V显示版本信息--version

环境变量

变量名描述默认值示例
NPM_REGISTRYnpm注册表URLhttps://registry.npmjs.org/https://registry.npmmirror.com
GM_MCP_CACHE_DIR缓存目录~/.gm-mcp/cache/tmp/gm-mcp-cache
GM_MCP_DEFAULT_TEMPLATE默认模板basicadvanced

配置文件

创建 ~/.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": "我的自定义模板"
    }
  }
}

配置选项说明

选项类型描述默认值
defaultTemplatestring默认使用的模板basic
autoInstallboolean是否自动安装依赖true
registrystringnpm注册表URLhttps://registry.npmjs.org/
cacheDirstring缓存目录路径~/.gm-mcp/cache
templatesobject自定义模板配置{}

模板配置

内置模板

  • 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

优先级

配置的优先级从高到低:

  1. 命令行选项
  2. 环境变量
  3. 配置文件
  4. 默认值

验证配置

bash
# 查看当前配置
gm-mcp version

# 测试配置
gm-mcp init test-project --template basic --yes

故障排除

配置文件错误

如果配置文件格式错误,gm-mcp会使用默认配置并显示警告。

模板路径错误

如果自定义模板路径不存在,会回退到默认模板。

网络配置

如果npm注册表无法访问,会尝试使用备用注册表。

下一步

基于 MIT 许可证发布