Skip to content
FunCoding

Search

Search docs, Skills and MCP

MCP 连接与 CLI 配置

配置 stdio、HTTP、SSE,选择 user/project 范围并核对命令参数。

This page has not been translated into English yet. The original Chinese version is shown below.

MCP 配置位于 settings 的 mcpServers 对象,键是服务名称。CLI 与手写 JSON 生成同类条目,选择适合维护的方式即可。

配置作用域

默认用户范围写 ~/.qwen/settings.json,项目范围写项目根 .qwen/settings.json。CLI 用 --scope user 或 --scope project 指定。

同名服务在不同配置来源之间按优先级替换整个对象,不逐字段合并。要给已有服务加超时或 App 上限,应改原始声明处,而不是在另一个文件仅放几个字段。

本地 stdio

{
  "mcpServers": {
    "project-tools": {
      "command": "python",
      "args": ["-m", "my_mcp_server"],
      "cwd": "./mcp-servers/python",
      "env": {"API_KEY": "${EXTERNAL_API_KEY}"},
      "timeout": 30000
    }
  }
}

示例模块需自行准备。env 支持 $VAR_NAME 与 ${VAR_NAME} 引用运行环境;GUI 与 shell 启动时继承环境可能不同。无法启动时检查 command、cwd、env,必要时把 command 改成已核实的绝对路径。

远程 HTTP 与 SSE

{
  "mcpServers": {
    "remote-tools": {
      "httpUrl": "https://tools.example.com/mcp",
      "headers": {"Authorization": "Bearer your-api-token"},
      "timeout": 30000
    }
  }
}

这是需替换端点和凭据的配置示例。HTTP 使用 httpUrl,SSE 使用 url;不要因为两者都是 URL 就互换字段。headers 可用于两种远程传输。

timeout 单位毫秒,默认 600,000,即十分钟,用于请求/工具调用;初始发现有独立 discoveryTimeoutMs,见可用性。官方 CLI 表仍把 timeout 简称连接超时,不能因此用它替代发现预算。

CLI 常用选项

qwen mcp add [options] <name> <commandOrUrl> [args...]
qwen mcp remove <name>
选项用途
-s, --scopeuser 或 project,默认 user
-t, --transportstdio、http、sse,默认 stdio
-e, --env为本地进程设置 KEY=value
-H, --headerHTTP/SSE 请求头
--timeout毫秒超时
--trust可信工作区中跳过该服务确认,默认 false
--description服务说明
--include-tools / --exclude-tools逗号分隔工具列表

OAuth 参数包括 --oauth-client-id、--oauth-client-secret、--oauth-redirect-uri、--oauth-authorization-url、--oauth-token-url、--oauth-scopes;scopes 为逗号分隔,只能用于 http/sse,与 stdio 组合会被拒绝。

高级身份配置还包括 authProviderType: service_account_impersonation 下的 targetAudience 和 targetServiceAccount,分别指 IAP 应用允许的 OAuth Client ID 与要模拟的服务账号邮件地址。是否具备服务端授权仍取决于对应云环境配置。