Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(mcp-market): keep unbound header tokens literal

ct-jaryn8f561adbbbf8
diff --git a/docs/adr/registry-header-variable-spelling.md b/docs/adr/registry-header-variable-spelling.md
index 32d98d83a..6177ba854 100644
--- a/docs/adr/registry-header-variable-spelling.md
+++ b/docs/adr/registry-header-variable-spelling.md
@@ -30,6 +30,11 @@ behavior, actual HTTP transmission, or a user's observed response status.
declared by the registry. Each header owns its variable definitions.
2. Add optional `headerBindings` to the shared catalog template. Each header
maps exact tokens to an editable `requiredEnv` input or a fixed literal.
+ Presence of `headerBindings`, including an empty map, selects explicit
+ binding mode for all headers. A header absent from that map has no bound
+ tokens: both `{name}` and `${NAME}` remain literal, regardless of global
+ `requiredEnv` names or defaults. Only catalogs with no `headerBindings`
+ metadata use the legacy global input scope.
Same-named inputs in separate headers get distinct collision-safe names.
Variable `default` prefills the editable input; omitted `isRequired` means
optional. A fixed `value` is not editable and its content is never parsed
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 53d7688de..b6f34c033 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -13401,7 +13401,8 @@ plugin-form fixtures in an isolated temporary directory at runtime.
| E2E-MCP-MARKET-NET-BOUNDARY | URL guard rejects credentials, loopback, private, special-use IPv4, v4-mapped, ULA, site-local and link-local bypass forms (trailing dot included); Main pins the checked public address and rechecks HTTPS redirects | deterministic guard assertions; source-contract coverage for DNS pin and bounded responses |
| E2E-MCP-MARKET-SEMANTICS | Registry records map to install templates preserving package versions, named/positional runtime/package arguments and required/optional env variables; a remote header variable is recognized in both the registry's `{name}` and the catalog's `${NAME}` spelling, prompts for declared editable values, preserves unbound brace literals, and resolves header-local defaults, fixed values, and optional flags without merging same-named inputs across headers (ADR registry-header-variable-spelling) | deterministic mapping assertions |
| E2E-MCP-MARKET-INSTALL | Builtin catalog entry resolves through `resolveCatalogEntry` and installs via the host `mcp.upsert` RPC; record lands in `~/.agents/servers/` | real host binary, isolated temp HOME |
-| E2E-MCP-MARKET-HEADER-SCOPE | Registry header-local `{token}` resolves only in its header; same-named URL path/query tokens remain literal through mapping, resolution, host upsert/list and persistence. URL templates retain only legacy `${NAME}` substitution | shared regressions plus real host binary with isolated temporary storage; remote entry disabled, no network call |
+| E2E-MCP-MARKET-HEADER-SCOPE | Registry header-local `{token}` resolves only in its header; same-named URL path/query tokens remain literal through mapping, resolution, host upsert/list and persistence. URL templates retain only legacy `${NAME}` substitution. When `headerBindings` exists (even empty or partial), unbound tokens in every header stay literal and never consume another header's input or default | shared regressions plus real host binary with isolated temporary storage; remote entry disabled, no network call |
+| E2E-MCP-MARKET-partial-header-bindings-stay-literal | Resolve a catalog with only Authorization bound and another header using the same `{token}` / `${token}`; an undeclared `${UNBOUND}` in a third header also remains literal through host upsert/list and disk persistence | real host binary, disabled remote entry, synthetic input and isolated temporary storage; no network call |
#### E2E-SKILL-MARKET-NET-BOUNDARY: Public-HTTPS skill sources reject private and loopback URLs
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 9600a6b4b..a9c28b2c4 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -7882,7 +7882,8 @@ runner 会在运行时的隔离临时目录中生成六个插件形态 fixture
| E2E-MCP-MARKET-NET-BOUNDARY | URL guard 拒绝凭据、回环、私网、special-use IPv4、v4-mapped、ULA、site-local 和 link-local 及尾点绕过形态;Main 固定已检查的公网地址并逐跳复核 HTTPS 重定向 | 确定性 guard 断言;DNS pin 与响应上限 source-contract 覆盖 |
| E2E-MCP-MARKET-SEMANTICS | Registry 记录映射为安装模板时保留包版本、named/positional runtime/package 参数与 required/optional 环境变量语义;远端 header 变量同时识别注册表的 `{name}` 与目录的 `${NAME}` 两种写法,仅为已声明的可编辑值显示输入,保留未声明花括号字面量,并按各 header 的作用域处理默认值、固定值与可选标记,不合并不同 header 的同名输入(ADR registry-header-variable-spelling) | 确定性映射断言 |
| E2E-MCP-MARKET-INSTALL | 内置目录条目经 `resolveCatalogEntry` 解析并通过宿主 `mcp.upsert` RPC 安装;记录落盘 `~/.agents/servers/` | 真实宿主二进制,隔离临时 HOME |
-| E2E-MCP-MARKET-HEADER-SCOPE | Registry header-local `{token}` resolves only in its header; same-named URL path/query tokens remain literal through mapping, resolution, host upsert/list and persistence. URL templates retain only legacy `${NAME}` substitution | shared regressions plus real host binary with isolated temporary storage; remote entry disabled, no network call |
+| E2E-MCP-MARKET-HEADER-SCOPE | Registry header-local `{token}` resolves only in its header; same-named URL path/query tokens remain literal through mapping, resolution, host upsert/list and persistence. URL templates retain only legacy `${NAME}` substitution. When `headerBindings` exists (even empty or partial), unbound tokens in every header stay literal and never consume another header's input or default | shared regressions plus real host binary with isolated temporary storage; remote entry disabled, no network call |
+| E2E-MCP-MARKET-partial-header-bindings-stay-literal | Resolve a catalog with only Authorization bound and another header using the same `{token}` / `${token}`; an undeclared `${UNBOUND}` in a third header also remains literal through host upsert/list and disk persistence | real host binary, disabled remote entry, synthetic input and isolated temporary storage; no network call |
#### E2E-SKILL-MARKET-NET-BOUNDARY:技能源公网 HTTPS 策略拒绝私网与回环
diff --git a/packages/shared/src/mcp-catalog.test.ts b/packages/shared/src/mcp-catalog.test.ts
index 161a8caf4..b65abc170 100644
--- a/packages/shared/src/mcp-catalog.test.ts
+++ b/packages/shared/src/mcp-catalog.test.ts
@@ -157,6 +157,74 @@ describe("resolveCatalogEntry", () => {
expect(() => resolveCatalogEntry(entry, { token: "synthetic-secret" })).toThrow("missing value for REGION");
});
+ it.each(["{token}", "${token}"])("keeps unbound %s literal in a partial header binding map", (token) => {
+ const entry: McpCatalogEntry = {
+ ...httpTemplate,
+ headers: { Authorization: `Bearer ${token}`, "X-Unbound": token },
+ headerBindings: { Authorization: { [token]: { input: "token" } } },
+ requiredEnv: [{ name: "token", defaultValue: "synthetic-default" }],
+ };
+ expect(catalogEntryError(entry)).toBeNull();
+ expect(collectCatalogPlaceholders(entry)).toEqual(["token"]);
+ expect(resolveCatalogEntry(entry, { token: "synthetic-secret" }).headers).toEqual({
+ Authorization: "Bearer synthetic-secret", "X-Unbound": token,
+ });
+ expect(resolveCatalogEntry(entry).headers).toEqual({
+ Authorization: "Bearer synthetic-default", "X-Unbound": token,
+ });
+ });
+
+ it("does not discover or require an unbound header token in explicit binding mode", () => {
+ const entry: McpCatalogEntry = {
+ ...httpTemplate,
+ headers: { Authorization: "Bearer {token}", "X-Unbound": "${UNBOUND}" },
+ headerBindings: { Authorization: { "{token}": { input: "key" } } },
+ requiredEnv: [{ name: "key" }],
+ };
+ expect(collectCatalogPlaceholders(entry)).toEqual(["key"]);
+ expect(catalogEntryError(entry)).toBeNull();
+ expect(resolveCatalogEntry(entry, { key: "synthetic-secret" }).headers).toEqual({
+ Authorization: "Bearer synthetic-secret", "X-Unbound": "${UNBOUND}",
+ });
+ });
+
+ it.each<NonNullable<McpCatalogEntry["headerBindings"]>>([{}, { Authorization: {} }])("treats an empty binding map as explicit mode: %j", (headerBindings) => {
+ const entry: McpCatalogEntry = {
+ ...httpTemplate,
+ headers: { Authorization: "Bearer ${TOKEN}", "X-Unbound": "{TOKEN}" },
+ headerBindings,
+ requiredEnv: [{ name: "TOKEN", defaultValue: "synthetic-default" }],
+ };
+ expect(collectCatalogPlaceholders(entry)).toEqual([]);
+ expect(catalogEntryError(entry)).toBeNull();
+ expect(resolveCatalogEntry(entry).headers).toEqual(entry.headers);
+ expect(resolveCatalogEntry(entry, { TOKEN: "synthetic-secret" }).headers).toEqual(entry.headers);
+ expect(resolveCatalogEntry({ ...entry, requiredEnv: [{ name: "TOKEN" }] }).headers).toEqual(entry.headers);
+ });
+
+ it("ignores inherited header bindings instead of falling back to global inputs", () => {
+ const entry: McpCatalogEntry = {
+ ...httpTemplate,
+ headers: { Authorization: "Bearer {token}" },
+ headerBindings: Object.create({ Authorization: { "{token}": { input: "token" } } }),
+ requiredEnv: [{ name: "token" }],
+ };
+ expect(collectCatalogPlaceholders(entry)).toEqual([]);
+ expect(resolveCatalogEntry(entry, { token: "synthetic-secret" }).headers).toEqual(entry.headers);
+ });
+
+ it("preserves legacy dollar and declared brace headers without binding metadata", () => {
+ const entry: McpCatalogEntry = {
+ ...httpTemplate,
+ headers: { Authorization: "Bearer ${TOKEN}", "X-Token": "{TOKEN}" },
+ requiredEnv: [{ name: "TOKEN" }],
+ };
+ expect(collectCatalogPlaceholders(entry)).toEqual(["TOKEN"]);
+ expect(resolveCatalogEntry(entry, { TOKEN: "synthetic-secret" }).headers).toEqual({
+ Authorization: "Bearer synthetic-secret", "X-Token": "synthetic-secret",
+ });
+ });
+
it("substitutes values into stdio args and env", () => {
const input = resolveCatalogEntry(stdioTemplate, {
GITHUB_PAT: "pat-value",
diff --git a/packages/shared/src/mcp-catalog.ts b/packages/shared/src/mcp-catalog.ts
index 62138b269..54bc2e51a 100644
--- a/packages/shared/src/mcp-catalog.ts
+++ b/packages/shared/src/mcp-catalog.ts
@@ -39,7 +39,10 @@ export type McpCatalogEntry = {
/** Public HTTPS template; only legacy `${NAME}` URL tokens are expanded. */
url?: string;
headers?: Record<string, string>;
- /** Header-local token bindings. Unbound text stays literal, including braces. */
+ /**
+ * Header-local token bindings. When present (even empty), every unbound token
+ * stays literal, including in headers without a binding map.
+ */
headerBindings?: Record<string, Record<string, McpCatalogHeaderBinding>>;
requiredEnv?: McpCatalogRequiredEnv[];
prerequisites?: string[];
@@ -191,7 +194,9 @@ export function collectCatalogPlaceholders(entry: McpCatalogEntry): string[] {
}
function bindingsForHeader(entry: McpCatalogEntry, header: string): Record<string, McpCatalogHeaderBinding> | undefined {
- return entry.headerBindings && Object.hasOwn(entry.headerBindings, header) ? entry.headerBindings[header] : undefined;
+ // Only catalogs without binding metadata use the legacy global input scope.
+ if (entry.headerBindings === undefined) return undefined;
+ return Object.hasOwn(entry.headerBindings, header) ? entry.headerBindings[header] : {};
}
function declaredNames(entry: McpCatalogEntry): Map<string, McpCatalogRequiredEnv> {
diff --git a/scripts/e2e-mcp-market.mjs b/scripts/e2e-mcp-market.mjs
index ca139b3ee..fd730b8d9 100644
--- a/scripts/e2e-mcp-market.mjs
+++ b/scripts/e2e-mcp-market.mjs
@@ -7,7 +7,8 @@
* E2E-MCP-MARKET-SEMANTICS registry record → template keeps named
* arguments and required/optional envs
* E2E-MCP-MARKET-HEADER-SCOPE header credential stays out of the URL
- * through mapping, resolution and persistence
+ * through mapping, resolution and persistence; unbound
+ * headers stay literal with a partial binding map
* E2E-MCP-MARKET-NET-BOUNDARY the URL guard rejects loopback/private/
* mapped/ULA/link-local bypass forms
*
@@ -234,6 +235,34 @@ try {
&& scopedRow.enabled === false,
"header resolves while the same-named URL token remains literal in host configuration",
);
+
+ // A partial binding map must not authorize tokens in a different header.
+ const partialEntry = {
+ ...scopedEntry, id: "partial-header-scope", name: "Partial header scope",
+ headers: {
+ Authorization: "Bearer {token}",
+ "X-Unbound": "{token}/${token}",
+ "X-Undeclared": "${UNBOUND}",
+ },
+ headerBindings: { Authorization: { "{token}": { input: "token" } } },
+ };
+ const partialInput = resolveCatalogEntry(partialEntry, { token: "synthetic-header-secret" });
+ await host.call("mcp.upsert", { server: {
+ ...partialInput, enabled: false, level: "global", scope: GLOBAL_SCOPE,
+ } });
+ const partialList = await host.call("mcp.list", { level: "global" });
+ const partialRow = partialList.servers.find((server) => server.id === partialEntry.id);
+ const partialDisk = JSON.parse(readFileSync(join(home, ".agents", "servers", `${partialEntry.id}.json`), "utf8"));
+ const partialScopeOk = [partialInput, partialRow, partialDisk].every((server) =>
+ server?.url === scopedUrl
+ && server.headers?.Authorization === "Bearer synthetic-header-secret"
+ && server.headers?.["X-Unbound"] === "{token}/${token}"
+ && server.headers?.["X-Undeclared"] === "${UNBOUND}");
+ record(
+ "E2E-MCP-MARKET-partial-header-bindings-stay-literal",
+ partialScopeOk && partialRow?.enabled === false,
+ "partial bindings leave other headers literal through resolution, host upsert/list and persistence",
+ );
}
} catch (error) {
record("E2E-MCP-MARKET-INSTALL", false, error.message);