MoonshotAI / MoonshotAI/kimi-code

MCP:无法对同时允许匿名访问的 server 主动发起 OAuth 登录(如 Exa)

Open
#3,179 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

你希望看到什么功能?

允许对任意 HTTP/SSE MCP server 主动触发 OAuth 登录,而不是只能等 server 返回 401、进入 needs-auth 之后才能 /mcp-config login

具体场景:Exa 官方端点 https://mcp.exa.ai/mcp 通过 .well-known/oauth-protected-resource 声明了 OAuth(授权服务器为 https://auth.exa.ai),但同时接受匿名连接(匿名 initialize 返回 200,走公共免费档)。Kimi Code 连上之后就一直停留在匿名状态:

  • needs-auth 只在连接遇到 401 类错误时才设置(packages/agent-core-v2/src/mcpCore/connection-manager.tsshouldMarkNeedsAuth / isUnauthorizedLikeError),Exa 不拒绝匿名访问,所以永远进不了 needs-auth
  • /mcp-config login exa 因此不可用(不暴露 authenticate 工具);
  • auth: "oauth" 配置字段也帮不上忙:它只是 headers 启发式判断的逃生口(connection-manager.ts:451),而 resolveOAuthProviderconnection-manager.ts:435-444)只在本地已存 token 时才挂载 provider,没有任何代码路径会主动发起授权。

结果是用量永远记在匿名免费档,想绑定自己的 Exa 账号只能把 API key 明文写进 mcp.json。其他 MCP 客户端(Grok CLI、Antigravity)在 server 声明 OAuth 时会主动走授权流程,同样的配置在那边是已认证状态,在 Kimi Code 里是匿名状态。

建议(二选一,或都支持):

  1. /mcp-config login <server> 对任意 HTTP/SSE server 可用,无视当前状态直接启动 SDK auth() 流程;
  2. auth: "oauth" 的语义改为「连接时若本地无已存 token,则主动发起 OAuth」。
补充信息

版本 0.38.0。相关已关闭 issue:#2605(auth: "oauth" 字段本身已移植到 v2,但语义不含主动登录)。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/agent-core-v2/src/mcpCore/connection-manager.ts, especially shouldMarkNeedsAuth, isUnauthorizedLikeError, resolveOAuthProvider, and the auth: "oauth" handling. Trace the /mcp-config login entry point and the SDK auth() flow for HTTP/SSE servers. Done means a server such as https://mcp.exa.ai/mcp can explicitly start OAuth without first returning 401, while existing authenticated and anonymous behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
authentication, cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
54/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.