agentscope-ai / agentscope-ai/QwenPaw

[Bug]: MCP legacy migration leaves empty-env clients with a dangling credential ref — every new session fails with CredentialNotFoundError

Open
#7,301 3 comments 0 reactions 1 assignee Claimed by @yuanxs21 View on GitHub
Dominant language
Python
Stars
34.9k
Forks
3.1k
Avg merge
1d 15h
Merged PRs (30d)
225

Description

--- 标题(复制到 Issue 标题栏)---
[Bug]: MCP legacy migration leaves empty-env clients with a dangling credential ref — every new session fails with CredentialNotFoundError

--- 正文(复制到 Issue 正文)---
```yaml
name: Bug Report
about: Report a bug or unexpected behavior
title: "[Bug]: MCP legacy migration leaves empty-env clients with a dangling credential ref — every new session fails with CredentialNotFoundError"
labels: ["bug", "triage"]
assignees: []
```

## QwenPaw Version

qwenpaw 2.1.0(桌面版自带打包后端;内置 agentscope 2.0.4.post1)。运行 `qwenpaw --version` 可确认。

## Description

通过 `agent.json` 的 `mcp.clients` 添加的 stdio MCP 客户端,当其 `env` 为空时,自动迁移到新式 `drivers/mcp/*.yaml` 后会在 `credentials.yaml` 中留下**悬空的凭证引用**:

- 生成的 driver 卡片声明 `credentials.static.ref: mcp/`;
- 但 `credentials.yaml` 中**没有**对应条目(空 `env` 客户端没有可迁移的 secret,迁移逻辑直接跳过建凭证)。

结果是**每次会话启动构建 Driver 时**都报 `CredentialNotFoundError`,MCP 客户端连不上,该客户端的工具(vision_chat / ocr / grounding 等)**从不注册到 agent 工具列表**。现象表现为「当时能用、换窗口/重启后端就坏」,因为新窗口=新会话=后端按磁盘配置重新构建 Driver,每次都在同一位置失败。

**Security considerations:** 无涉密信息暴露;插件自身的密钥由其独立配置文件(`~/.qwen-mm-plugins/config`)管理,与 QwenPaw 的 credential store 无关,只是 QwenPaw 侧缺少一个空的凭证占位条目。

## Component(s) Affected

- [x] Core / Backend (app, agents, config, providers, utils, local_models)
- [ ] Console (frontend web UI)
- [ ] Channels (DingTalk, Feishu, QQ, Discord, iMessage, etc.)
- [ ] Skills
- [ ] CLI
- [ ] Documentation (website)
- [ ] Tests
- [ ] CI/CD
- [ ] Scripts / Deploy

## Environment

- **QwenPaw version:** 2.1.0(若 `qwenpaw --version` 输出不同,以实际输出为准)
- **OS:** Windows 10 (AMD64)
- **Install method:** 桌面版(DeepSeek Harness Desktop / QwenPaw Desktop,binaries 自带后端,非 pip)
- **Python version (if applicable):** 不适用(桌面版打包,未单独装 Python)

## Steps to Reproduce

1. 在 `agent.json` 的 `mcp.clients` 中添加一个 stdio 传输的 MCP 客户端,例如 Qwen-MM-Plugins:`transport: stdio`、`command: uvx`、`args: ["--from", "[api]", "qwen-mm-plugins-api"]`、`env: {}`;
2. 彻底重启桌面端/后端进程;
3. 新建任意会话,观察:
- 日志出现 `Failed to build Driver 'qwen-mm-plugins-api': Credential not found: mcp/qwen-mm-plugins-api`;
- 该 MCP 客户端连接失败,其工具不出现在 agent 工具列表。

对照组:同一流程下,`env` 声明了变量引用的客户端(如内置 `tavily_search`)会自动生成 `credentials.yaml` 条目并正常连接(日志可见 `MCP client connected: tavily_search`)。

## Actual vs Expected

- **Actual:** 每新会话/重启后必报 `CredentialNotFoundError: Credential not found: mcp/`,MCP 工具不注册;仅在同一会话内绕过注册(直接调用 MCP CLI)时才「暂时能用」。
- **Expected:** 空 `env` 客户端迁移后应自动补建空凭证条目(`kind: static`、`secrets: {}`),或允许不声明 `credentials` 的 driver 直接构建,使 MCP 客户端正常连接、工具正常注册。

## Logs / Screenshots

```
(qwenpaw.log,反复出现,最早 2026-08-18,最近 2026-08-26 07:06:16)
Failed to build Driver 'qwen-mm-plugins-api': Credential not found: mcp/qwen-mm-plugins-api
File "qwenpaw\drivers\handlers\mcp.py", line 67, in _setup
qwenpaw.drivers.errors.CredentialNotFoundError: Credential not found: mcp/qwen-mm-plugins-api
```

对照组(同日志,同时间附近):

```
MCP client connected: tavily_search
```

## Additional Notes

**临时方案(已验证可行)**:在 `credentials.yaml` 手工补一条空凭证并彻底重启:

```yaml
mcp/:
kind: static
public: {}
secrets: {}
meta:
created_at:
updated_at:
source: manual
```

重启后日志变为 `MCP client connected: `,工具正常注册,且新窗口/重启后不再复发。

**同类问题参考**:本仓库已有多个 MCP 迁移/持久化相关 bug:#6130(删除的 MCP 客户端重启后复现)、#6524(后端重启后 MCP 客户端无法自动恢复)、#6029/#6091(MCP 迁移把 `${VAR}` 原样写入 credential store 导致认证失败)。本 issue 是同一类「legacy 迁移与凭证库衔接」盲区的另一面:空 `env` 客户端被迁移生成 driver 卡片,却没有生成对应凭证条目。

**建议**:在 legacy migration 中,对 `env` 为空的客户端同样生成空凭证条目;或在 `mcp.py` 的 `_setup` 中对无 env/secret 绑定的 driver 允许缺省凭证;并在 MCP 文档中说明「手动添加 MCP 服务需先在 credentials 中建对应凭证」。

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.