Skip to content

feat(mcp): support plugin authorization targets - #2831

Closed
pvzheroes125 wants to merge 8 commits into
MoonshotAI:mainfrom
pvzheroes125:feat/plugin-mcp-auth-targets
Closed

feat(mcp): support plugin authorization targets#2831
pvzheroes125 wants to merge 8 commits into
MoonshotAI:mainfrom
pvzheroes125:feat/plugin-mcp-auth-targets

Conversation

@pvzheroes125

@pvzheroes125 pvzheroes125 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Related Issue

No public issue is linked. This PR exposes the MCP authorization surface needed by hosts that manage plugin-provided MCP servers.

Problem

MCP OAuth management is currently keyed only by entries in the user-global mcp.json. Plugin MCP servers are loaded by the runtime too, but hosts cannot explicitly:

  • query their authorization status;
  • start, complete, cancel, or reset their OAuth flow; or
  • distinguish an expired credential from an unavailable server.

Treating plugin MCP servers as global configuration would give hosts an authorization entry point, but it would also mix plugin-owned configuration into the global registry and create conflicting ownership.

The existing status shortcuts can also become stale: the presence of stored tokens or auth: "oauth" does not prove that the server currently accepts the credential.

What Changed

Target-aware authorization API

Introduced a shared locator for both configuration sources:

type McpServerLocator =
  | { source: 'global'; name: string }
  | { source: 'plugin'; pluginId: string; serverName: string };

The Core and Node SDK now expose target-aware operations for:

  • listing authorization status;
  • beginning authorization;
  • completing or cancelling an active flow; and
  • resetting stored authorization.

Plugin targets are resolved through plugin metadata. OAuth credentials continue to use the runtime server name and URL, matching the identity used by the connection manager.

Runtime-backed status

Authorization status is determined with an isolated, non-interactive connection probe instead of treating stored credentials or an auth marker as authoritative.

  • A resource authentication failure reports oauth-required.
  • A successful authenticated connection reports oauth-authorized.
  • Static bearer-token and non-OAuth configurations retain their existing classifications.
  • Ordinary connection failures report unavailable rather than being mislabeled as authentication failures.
  • Existing access-token refresh behavior remains active during the probe.

SSE startup now preserves a resource-level HTTP 401 even when the MCP SDK subsequently wraps it in an OAuth discovery or registration error. Non-401 startup failures are not reclassified.

Compatibility and ownership boundaries

  • Existing global MCP methods remain available as compatibility wrappers.
  • listGlobalMcpServers and global CRUD still operate only on mcp.json.
  • Plugin MCP configuration remains plugin-owned; this PR does not copy it into the global registry.
  • Connection probes preserve enabled: false and do not connect disabled servers. Explicit OAuth management calls retain their existing behavior and do not mutate enabled state.
  • Core V1 and SDK V2 implement the same contract through their existing runtime-specific services.

Validation

All GitHub Actions workflows for the current head passed:

  • CI
  • Nix Build
  • pkg.pr.new
  • PR Title Checker

Focused local validation also passed:

  • Vitest: focused MCP authorization, SSE retry, disabled-probe, and V1/V2 parity regressions passed
  • TypeScript: @moonshot-ai/agent-core, @moonshot-ai/agent-core-v2, and @moonshot-ai/kimi-code-sdk
  • git diff --check

The regression coverage includes V1/V2 plugin target parity, runtime credential identity, disabled-server probe behavior, stale credentials, unavailable servers, configuration hints, SSE stale-provider 401 recovery, clearing stale 401 state when an authenticated retry returns HTTP 500, and non-401 classification.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c1823eb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Patch
@moonshot-ai/kimi-code-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pvzheroes125
pvzheroes125 marked this pull request as ready for review August 11, 2026 17:51
@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@c1823eb
npx https://pkg.pr.new/@moonshot-ai/kimi-code@c1823eb

commit: c1823eb

@pvzheroes125
pvzheroes125 force-pushed the feat/plugin-mcp-auth-targets branch from 1538c93 to e1ef0e3 Compare August 11, 2026 18:41

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1ef0e339b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core-v2/src/mcpCore/client-sse.ts Outdated
Comment thread packages/agent-core/src/mcp/client-sse.ts

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: fc58fe9247

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c710b10545

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core/src/rpc/core-impl.ts

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2db35b6ed2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-core-v2/src/mcpCore/client-sse.ts

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: d8ecd590c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac58763eb0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/node-sdk/src/sdk-rpc-client-v2.ts

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1823eb431

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2158 to +2161
return Promise.all(
targets.map(async (target) => {
const server = await this.resolveMcpServerTarget(target);
return { target, authStatus: await this.mcpServerAuthState(server, oauth) };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Serialize probes that share an OAuth identity

When targets contains the same locator twice, or multiple locators resolve to the same runtime name and URL, this Promise.all starts concurrent connections through the same cached OAuth provider. If the credential requires refresh and the authorization server rotates refresh tokens, both probes can submit the old token; one succeeds while the other reports oauth-required, producing inconsistent results and potentially disrupting concurrent live-server authentication. Fresh evidence beyond the earlier cache-coherence comment is that reloadCachedMcpOAuthTokens runs only after each probe finishes, so it cannot prevent this refresh race; deduplicate or serialize probes by OAuth credential identity. The v1 implementation in core-impl.ts mirrors the same parallel behavior.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant