LibreChat/api/server/controllers/agents
Danny Avila d875425ed2
🔐 fix: Authorize Restored MCP Tools Before Agent Revert Writes Them (#17843)
* 🔐 fix: Authorize Restored MCP Tools Before Agent Revert Writes Them

Reverting wrote the version snapshot, including its mcpServerNames, before
filterAuthorizedTools ran. Agent-scoped MCP access is granted from that index,
so a restored server vouched for itself and an editor without access to it
could re-attach it. A snapshot without mcpServerNames also left the current
index in place, keeping agent-scoped access to servers no tool used.

The handler now authorizes the restored tools against the agent as it stands,
treating only its current tools as existing, and passes the authorized tools
and rebuilt index to revertAgentVersion so the restore is one write pinned to
the revision it was checked against. revertAgentVersion always rewrites the
index for the restored tools.

* 🔐 fix: Exclude the Target Agent's Own Grant When Authorizing a Revert

Moves the restore authorization into authorizeAgentRestore in packages/api,
leaving the revert controller as wiring.

A newly restored MCP tool whose server the user reaches only through agents
must now be reachable through an agent other than the one being reverted,
checked fresh against the database. The target's current or cached index
(including one left stale by an earlier revert) no longer vouches for it.

Prior server names are matched through their normalized aliases, and only for
tools the agent already had. When nothing resolves, the pre-restore index is
kept instead of deriving names from tool keys.

A revision-filtered restore that misses is reported as a 409 conflict.

The route spec restores the real ~/config so the MCP registry is consulted
rather than reported unavailable.

* 🔐 fix: Check Newly Restored MCP Servers Against Live Grants

The restore gate now runs for every approved MCP tool, not only consumeOnly
ones. A tool the agent doesn't already have, on a DB-backed server, is
admitted when a current tool still uses that server, or on a live direct
server grant, or through another viewable agent. A grant the registry still
caches after revocation no longer becomes durable through the restored index.

Admission is memoized per server. A snapshot tools array that sanitizes to
nothing restores an explicit empty set. Active-server matching no longer
reuses the index fallback, so a stale entry is never read as in use.

* 🔐 fix: Treat Legacy Cached DB Configs as User-Sourced in the Restore Gate

A config cached before an upgrade may carry a dbId without source. The
restore gate now uses isUserSourced, so such configs get the live access
check instead of passing as operator-managed.

* 🔐 fix: Recheck Unindexed Existing MCP Tools in the Restore Gate

Holding a tool no longer exempts it from the live check. Only a current tool
whose server the agent's index already lists skips it. Otherwise an unindexed
tool on a legacy agent could pass on a revoked grant the registry still
caches, and the restore would add its server to the index.

* ⚡ perf: Run Restore Admission Checks for Distinct Servers Concurrently

filterAuthorizedTools now starts every admission check during its single pass
and awaits them together, so each distinct DB-backed server no longer adds a
serial lookup wave to the revert. Tool order is preserved and server names
are recorded only for admitted tools.
2026-11-09 07:20:31 -05:00
..
__tests__ 🧩 fix: Accept Content-Array Tool Outputs in the Responses API (#17900) 2026-11-08 19:22:29 +01:00
callbacks.background.spec.js
callbacks.js 🧯 fix: Guard SSE Writes and Interval Cleanups Against Crashes (#17462) 2026-10-27 23:06:58 +01:00
client.codeDecision.spec.js 🍯 fix: Stop Approval Pauses From Unsealing Code Environments (#15963) 2026-09-15 12:30:37 -04:00
client.imageDetail.spec.js
client.js 🗄️ fix: Skip Attachments Deleted by Storage Retention Instead of Failing the Turn (#17910) 2026-11-08 23:38:47 +01:00
client.test.js 🗄️ fix: Skip Attachments Deleted by Storage Retention Instead of Failing the Turn (#17910) 2026-11-08 23:38:47 +01:00
filterAuthorizedTools.spec.js 🔐 fix: Authorize Restored MCP Tools Before Agent Revert Writes Them (#17843) 2026-11-09 07:20:31 -05:00
openai.js 🔑 perf: Cache JWT Users and Batch Auth-Path Reads (#17466) 2026-10-30 00:24:08 +01:00
protocol.js
queuedTurns.js 🍱 fix: Carry Coding Approval Mode With Queued Turns (#16326) 2026-09-25 07:28:43 -04:00
recordCollectedUsage.spec.js 🥢 fix: Fit MCP App Snapshots Within Message Documents (#16299) 2026-10-01 03:46:17 +00:00
request.js 🛟 fix: Promote Reconciled Compaction Snapshots to the Terminal Row (#16553) 2026-10-28 11:13:50 +01:00
responses.js 🧩 fix: Accept Content-Array Tool Outputs in the Responses API (#17900) 2026-11-08 19:22:29 +01:00
resume.js 🐘 fix: Preserve Authored Skills Across Approval Resumes (#17630) 2026-10-29 22:17:03 +01:00
steer.js
v1.js 🔐 fix: Authorize Restored MCP Tools Before Agent Revert Writes Them (#17843) 2026-11-09 07:20:31 -05:00
v1.spec.js 🔗 feat: Link Langfuse Prompts as Agent Instructions (#17294) 2026-10-30 17:28:37 +01:00