inspector/core/mcp/node/server-secrets.ts
Cliff Hall 373f346e5f
Some checks failed
Run install, format, lint, build, and test on every push / build (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish (push) Has been cancelled
Run install, format, lint, build, and test on every push / publish-github-container-registry (push) Has been cancelled
chore: close quality-gate coverage gaps (#1689) (#1766)
Closes #1689. Typecheck cli/tui src, add a core/ format+lint gate, and gate core/json + core/client coverage. See PR #1766 for the full review history.
2026-07-24 17:20:12 -04:00

31 lines
1.1 KiB
TypeScript

import type { SecretStore } from "../../auth/node/secret-store.js";
import { expectedSecretFields, mergeSecretsIntoStored } from "../serverList.js";
import type { MCPConfig } from "../types.js";
/**
* Merge per-server secrets from the OS keychain into an on-disk MCP catalog
* shape. Mirrors the web `/api/servers` GET rehydration path so TUI/CLI see
* the same effective OAuth client secrets and stdio env values as the browser.
*/
export async function rehydrateMcpConfigFromKeychain(
config: MCPConfig,
secretStore: SecretStore,
): Promise<MCPConfig> {
const out: MCPConfig = { mcpServers: {} };
await Promise.all(
Object.entries(config.mcpServers).map(async ([id, stored]) => {
const fields = expectedSecretFields(stored);
const secrets: Record<string, string> = {};
await Promise.all(
fields.map(async (field) => {
const value = await secretStore.get(id, field);
if (value !== null) {
secrets[field] = value;
}
}),
);
out.mcpServers[id] = mergeSecretsIntoStored(stored, secrets);
}),
);
return out;
}