MoonshotAI / MoonshotAI/kimi-code
[Bug][Web UI] MCP OAuth 授权链接只在 15 分钟超时后才可见,导致授权流程无法完成
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
定位结论(已确认):问题出在 Web UI 前端——web 端未处理
mcp.oauth.authorization_url自定义事件,不会自动打开浏览器也不展示链接;TUI(终端)路径经复现确认是正常的。详细调查见下方评论。本 issue 类型为 bug。
问题描述
当某个 MCP server 处于 needs-auth 状态时,agent 调用 mcp__<server>__authenticate 工具启动 OAuth 流程。流程内部会 emit 一个 mcp.oauth.authorization_url 的 tool update(携带 authorizationUrl),但在实际交互会话中,授权链接不会实时显示到用户界面——它只在流程 15 分钟超时后,以错误文本的形式出现在工具结果里:
OAuth flow for MCP server "xxx" did not complete: OAuth flow for "xxx" failed: OAuth callback timed out
Authorization URL (still valid if the listener has not timed out): https://mcp.alibaba-inc.com/oauth/authorize?...&redirect_uri=http%3A%2F%2F127.0.0.1%3A<port>%2Fcallback&...
但此时本地回调监听器(127.0.0.1:<随机端口>)已经随超时关闭,用户再打开这个链接也无法完成回调,授权陷入死锁。
复现步骤
- 在
mcp.json配置一个需要 OAuth 的 HTTP MCP server - 启动 kimi 会话,该 server 显示
needs-auth - 让 agent 调用
mcp__<server>__authenticate - 观察:终端只显示工具阻塞执行中,没有任何授权链接展示,也没有自动打开浏览器
- 15 分钟后超时,错误结果里才出现链接,但监听器已死,链接作废
期间用户看到的界面就是"卡死"状态,且没有任何线索知道该做什么。
期望行为
- OAuth 流程启动时(
onUpdate发出authorizationUrl的那一刻),把授权链接实时展示在交互界面上(可复制/可点击) - 更进一步:直接自动调用系统默认浏览器打开该链接(类似
gh auth login的体验)
环境
- macOS (darwin arm64),kimi-code 终端交互模式
- MCP gateway 为标准 OAuth 2.1 + PKCE(
/.well-known/oauth-authorization-server正常)
附注
我最终通过手动复刻整个 OAuth 流程(动态客户端注册 → PKCE → 本地回调监听 → 换 token → 按 mcpOAuthStoreKey 哈希规则写入 ~/.kimi-code/credentials/mcp/<key>-tokens.json / -client.json / -meta.json)绕过此问题完成授权,之后再次调用 authenticate 工具即命中 AlreadyAuthorizedError 完成重连。说明链路其它环节(凭证存储、重连、refresh 调度)都是好的,唯一缺口就是授权 URL 没有及时展示给用户。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Web UI handling for the mcp.oauth.authorization_url custom event and trace the authenticate tool's onUpdate path. Make the authorization URL appear immediately as a copyable or clickable link, with automatic browser opening if supported, and verify the flow no longer waits for the 15-minute timeout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100