Repository navigation
feat: support ZCode official MCP auth headers and ZCODE_BASE_URL injection - #411
Merged
Merged
Conversation
Translate the PR's comments and test titles to English (repo convention: code and comments are English-only) and extend the coding-plan resolution with the upstream wire rules for team plans: a bigmodel team selection sends Bigmodel-Target-Type: TEAM plus the atomic Bigmodel-Organization / Bigmodel-Project pair, a zai team sends the plan token with no scope headers, and a malformed bigmodel team selection falls back to identity-only instead of half-sending the pair.
Owner
|
Thanks for the clean implementation — the review found no security issues (enc:v2 decrypt path, fail-closed origin trust, arrival-time responder wiring, and ZCODE_BASE_URL injection all check out against upstream 3.18.2). I pushed one maintainer commit (
Verified on the branch: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable ZCode official plugin MCP servers (such as
tianyancha@zcode-plugins-officialandzcode-site:sites) that requireauth: { type: "zcode_official", provider: "jwt_token" }and${ZCODE_BASE_URL}URL expansion when running headless behindzcode-acp-server.Root causes addressed
${ZCODE_BASE_URL}in plugin.mcp.json:mergeEnvWithCreds()rightly strips any inheritedZCODE_BASE_URL(which could be a provider model API URL), leavingZCODE_BASE_URLunset whenzcode app-serverresolves official plugin manifests like${ZCODE_BASE_URL}/api/v1/mcp/server/finance_tianyancha. Those MCP servers were skipped during plugin resolution.interaction/requestOfficialMcpAuthHeaders: When official MCP servers connect or invoke tools,zcode app-serversends a server→clientinteraction/requestOfficialMcpAuthHeadersrequest to the host. Previously this fell through to the unhandled-request path, causingofficial_auth_unavailable.Changes
src/config/official-mcp-auth.ts:resolveOfficialZCodeBaseUrl()resolves the authoritative ZCode service origin (ZCODE_ENDPOINT_ORIGINor defaulthttps://zcode.z.ai, ignoring any inheritedZCODE_BASE_URL).isTrustedOfficialMcpOrigin()validatestargetOriginbefore reading credentials (matching ZCode desktop's fail-closed origin check, with optionalZCODE_OFFICIAL_MCP_DEV_TRUSTED_ORIGINSloopback support).resolveOfficialMcpAuthHeaders()readszcodejwttokenand active individual Coding Planoauth:<family>:access_tokenfrom the existing local credential store (readCredentialStoreSync) and buildsAuthorization,X-Bigmodel-Authorization, andBigmodel-Target-Type: PERSONALwithout logging any token values.src/backend/client.ts&src/handlers/server-requests.ts&src/server.ts:officialMcpAuthHeadersResponderonZcodeBackend(plus turn-loop / orphan fallbacks) mirroringproviderRuntimeHeadersResponder.ZCODE_BASE_URL: resolveOfficialZCodeBaseUrl()inensureBackend()while keepingmergeEnvWithCreds()unchanged so inherited model URLs remain stripped.tests/official-mcp-auth.test.ts:ZCODE_BASE_URLresolution, full coding-plan headers, identity-only fallback, missing credentials, untrusted-origin rejection, andanswerOfficialMcpAuthHeadersdispatch.Verification
pnpm typecheck,pnpm lint,pnpm build, and fullpnpm testpass.zcode 0.17.1) in an ACP client (T3 Code):plugin:tianyancha:tianyancharegistered and executedsearch_companies,get_company_registration_info, andget_company_basic_profilesuccessfully with zerounhandled server→client requestwarnings.