From 1a5180f5b9892f54b21472d5841f41b5df23ae37 Mon Sep 17 00:00:00 2001 From: Tolga Ergin Date: Sun, 8 Nov 2026 04:33:25 +0000 Subject: [PATCH 1/2] Read LPM CLI logins keyed without the registry's trailing slash LPM CLI now keys logins by the registry URL without trailing slashes, so https://lpm.dev/ and https://lpm.dev share one keychain account. The MCP server derives the account the same way, and for a slashed LPM_REGISTRY_URL also tries the account earlier CLI releases used for that spelling. Co-Authored-By: Claude Opus 5.5 --- lib/__tests__/auth.test.js | 23 ++++++++++++++++++++++- lib/auth.js | 34 ++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/lib/__tests__/auth.test.js b/lib/__tests__/auth.test.js index 8959e09..d701a09 100644 --- a/lib/__tests__/auth.test.js +++ b/lib/__tests__/auth.test.js @@ -52,6 +52,27 @@ describe("auth", () => { ) }) + it("reads a login an older LPM CLI stored under the trailing-slash registry", async () => { + process.env.LPM_REGISTRY_URL = "https://lpm.dev/" + const keytar = await import("keytar") + keytar.default.getPassword + .mockResolvedValueOnce(null) + .mockResolvedValueOnce("lpm_slashed_token") + + const token = await getToken() + expect(token).toBe("lpm_slashed_token") + expect(keytar.default.getPassword).toHaveBeenNthCalledWith( + 1, + "lpm-cli", + "auth-token:bd90fc32d95766d5", + ) + expect(keytar.default.getPassword).toHaveBeenNthCalledWith( + 2, + "lpm-cli", + "auth-token:89f54e26677b97ec", + ) + }) + it("returns null when keytar has no token", async () => { const keytar = await import("keytar") keytar.default.getPassword.mockResolvedValueOnce(null) @@ -136,7 +157,7 @@ describe("auth", () => { describe("registry-scoped keychain accounts", () => { it.each([ ["https://lpm.dev", "auth-token:bd90fc32d95766d5"], - ["https://lpm.dev/", "auth-token:89f54e26677b97ec"], + ["https://lpm.dev/", "auth-token:bd90fc32d95766d5"], ["http://localhost:3000", "auth-token:f1de9e489ba88cb1"], ["http://127.0.0.1:8787", "auth-token:b1a61bf29a38ff36"], ["https://registry.example.com/custom", "auth-token:1658e811bb24ec08"], diff --git a/lib/auth.js b/lib/auth.js index f40043b..174910a 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -39,11 +39,10 @@ export async function getToken(loadKeytar = () => import("keytar")) { try { const keytar = keytarModule.default ?? keytarModule - const token = await keytar.getPassword( - KEYTAR_SERVICE_NAME, - getKeychainAccount(), - ) - if (token) return token + for (const account of keychainAccountsToTry(getBaseUrl())) { + const token = await keytar.getPassword(KEYTAR_SERVICE_NAME, account) + if (token) return token + } } catch { throw new Error(KEYCHAIN_READ_ERROR) } @@ -51,6 +50,22 @@ export async function getToken(loadKeytar = () => import("keytar")) { return null } +/** + * The accounts that may hold the login for `registryUrl`: the one LPM CLI + * uses now, then the one CLI releases before 0.86 used for a registry + * spelled with a trailing slash. + * + * @param {string} registryUrl + * @returns {string[]} + */ +function keychainAccountsToTry(registryUrl) { + const accounts = [getKeychainAccount(registryUrl)] + if (registryUrl.endsWith("/")) { + accounts.push(accountForKey(registryUrl)) + } + return accounts +} + /** * Apply the LPM CLI's default registry transport contract: HTTPS, or HTTP * only for loopback. The MCP server has no `--insecure` remote-HTTP escape hatch. @@ -85,12 +100,19 @@ export function getBaseUrl() { /** * Derive the keychain account used by LPM CLI for one effective registry URL. + * LPM CLI keys logins by the registry without trailing slashes, so both + * spellings name one account. * * @param {string} [registryUrl] * @returns {string} */ export function getKeychainAccount(registryUrl = getBaseUrl()) { - const digest = createHash("sha256").update(registryUrl, "utf8").digest("hex") + return accountForKey(registryUrl.replace(/\/+$/, "")) +} + +/** @param {string} key */ +function accountForKey(key) { + const digest = createHash("sha256").update(key, "utf8").digest("hex") return `${KEYTAR_ACCOUNT_PREFIX}:${digest.slice(0, 16)}` } From 7b0a987cea20ba0e879be7ebfcb5e9220db92025 Mon Sep 17 00:00:00 2001 From: Tolga Ergin Date: Sun, 8 Nov 2026 05:08:02 +0000 Subject: [PATCH 2/2] Try the trailing-slash account for either registry spelling A login an older LPM CLI made with `--registry https://lpm.dev/` stays under the slashed account until the new CLI reads it, so the MCP server tries that account after the canonical one whether or not LPM_REGISTRY_URL ends with a slash. Co-Authored-By: Claude Opus 5.5 --- lib/__tests__/auth.test.js | 15 +++++++++++++++ lib/auth.js | 13 +++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/__tests__/auth.test.js b/lib/__tests__/auth.test.js index d701a09..0cb6bbb 100644 --- a/lib/__tests__/auth.test.js +++ b/lib/__tests__/auth.test.js @@ -73,6 +73,21 @@ describe("auth", () => { ) }) + it("reads a login an older LPM CLI stored under the trailing-slash spelling of the default registry", async () => { + const keytar = await import("keytar") + keytar.default.getPassword + .mockResolvedValueOnce(null) + .mockResolvedValueOnce("lpm_slashed_token") + + const token = await getToken() + expect(token).toBe("lpm_slashed_token") + expect(keytar.default.getPassword).toHaveBeenNthCalledWith( + 2, + "lpm-cli", + "auth-token:89f54e26677b97ec", + ) + }) + it("returns null when keytar has no token", async () => { const keytar = await import("keytar") keytar.default.getPassword.mockResolvedValueOnce(null) diff --git a/lib/auth.js b/lib/auth.js index 174910a..c2e9a20 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -51,19 +51,16 @@ export async function getToken(loadKeytar = () => import("keytar")) { } /** - * The accounts that may hold the login for `registryUrl`: the one LPM CLI - * uses now, then the one CLI releases before 0.86 used for a registry - * spelled with a trailing slash. + * The accounts that may hold the login for `registryUrl`, whichever way it + * ends: the one LPM CLI uses now, then the one CLI releases before 0.86 used + * for a login made with the registry spelled with a trailing slash. * * @param {string} registryUrl * @returns {string[]} */ function keychainAccountsToTry(registryUrl) { - const accounts = [getKeychainAccount(registryUrl)] - if (registryUrl.endsWith("/")) { - accounts.push(accountForKey(registryUrl)) - } - return accounts + const canonical = registryUrl.replace(/\/+$/, "") + return [accountForKey(canonical), accountForKey(`${canonical}/`)] } /**