mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
fix(plugins): invalidate MCP sessions on lifecycle and grant changes
The advertised tool surface is frozen at initialize, so anything that changes which plugin tools exist has to end the sessions built before it. tools/list_changed is not an alternative: no event store is configured, and the surface would not be re-read anyway. Unconditional, no diffing. The surface is per-session, since it depends on the caller's scopes and the plugin's grants, so there is no ctx-free set to compare against. Five routes, mirroring what admin.controller.ts already does for addons: activate, deactivate, update, retrust and uninstall. activate(id, consent), update and retrust are also the grant-change paths, so "on an mcp:tools grant change" needs nothing extra. A failed call invalidates nothing, because nothing changed. The addon cascade needed its own call. Disabling an addon can stop a plugin that publishes tools, and the addon doing the cascading is not necessarily one of MCP_RELEVANT_ADDONS, so mcpAffected does not cover it. Still gated on a plugin actually stopping, which keeps the #1414 rule that a config-only save kills nothing. Imported from sessionManager rather than the src/mcp barrel, which evaluates readEnv().mcp at module scope. MCPINV-001 to MCPINV-007.
This commit is contained in:
@@ -260,7 +260,12 @@ export class AdminController {
|
||||
// plugin that transitively depends on them) so a plugin never runs against a
|
||||
// disabled addon (#plugins dependencies).
|
||||
if (result.addon && result.addon.enabled === false && (body as { enabled?: boolean })?.enabled === false) {
|
||||
await this.pluginRuntime.deactivateForDisabledAddon(id);
|
||||
const stopped = await this.pluginRuntime.deactivateForDisabledAddon(id);
|
||||
// A stopped plugin takes its MCP tools off the surface, and the addon that
|
||||
// cascaded here is not necessarily an MCP-relevant one, so mcpAffected
|
||||
// above does not cover this. Still conditional on something actually
|
||||
// stopping, which keeps the #1414 rule that a no-op save kills nothing.
|
||||
if (stopped.length && !result.mcpAffected) this.admin.invalidateMcpSessions();
|
||||
}
|
||||
return { addon: result.addon };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user