sync-keys.js: write pluginauths.userId as a STRING — image generation was broken for every member

LibreChat's PluginAuth schema keys on a string userId; Key (the chat key
collection) is ObjectId-typed and Mongoose casts for it. The seeder used
`user._id` (an ObjectId) for BOTH, so every MCP auth row it wrote was
invisible to PluginService.getUserPluginAuthValue():

  string lookup  -> 0 rows      (what the app does)
  ObjectId lookup-> 1 row

Consequence: userMCPAuthMap['mcp_inference-image'] was empty for every
member, ToolService skipped the server ("missing user configuration"), and
any agent expecting MCP tools failed with
AgentToolInitializationError: "The agent is configured to use MCP tools, but
none are available" — 7 times since Oct 19, most recently 2026-10-27 22:29.
The image-generation MCP server (generate_image) was unavailable to everyone.
The docs server was unaffected (it declares no customUserVars).

Fix: String(uid) in the two pluginauths upserts only. The keys[] upserts are
deliberately left as ObjectId — chat key lookup works and changing it would
break the working half.

Verified: 54 existing rows migrated ObjectId -> string (backup at
/app/data/backup-pluginauths-userid-2026-10-27T2239Z.json), all 55 image rows
now string-typed, the app-style string lookup returns a row, and a full
seeder run passes its own decrypt guard and encrypt/decrypt round-trip check
(54 seeded, 17 skipped).
This commit is contained in:
inference-bot committed 2026-10-27 22:39:55 +00:00
1 parent ac8c10c1f0
commit d404297a4d
1 file changed
+2 -2
+2 -2
View File
@@ -162,8 +162,8 @@ const mongoose = require("/app/code/librechat/node_modules/mongoose");
// image MCP credential // image MCP credential
const encImage = await encrypt(sk); const encImage = await encrypt(sk);
await auths.updateOne( await auths.updateOne(
{ userId: uid, pluginKey: MCP_PLUGIN_KEY, authField: MCP_AUTH_FIELD }, { userId: String(uid), pluginKey: MCP_PLUGIN_KEY, authField: MCP_AUTH_FIELD },
{ $set: { userId: uid, pluginKey: MCP_PLUGIN_KEY, authField: MCP_AUTH_FIELD, value: encImage } }, { $set: { userId: String(uid), pluginKey: MCP_PLUGIN_KEY, authField: MCP_AUTH_FIELD, value: encImage } },
{ upsert: true } { upsert: true }
); );
seeded++; seeded++;