Let the coordinator manage skills, MCP servers and tools, behind a confirm card

- Coordinator tools in its own chat (super admin only): list_extensions,
  set_extension_access, delete_extension, and update_skill /
  update_mcp_server / update_custom_tool for what can't change where
  anything is sent (on/off, names, arguments, left-out tools)
- Adding a skill, MCP server or tool, or changing a skill's words, a
  server's URL or headers or a tool's kind or config, goes through
  propose_skill / propose_mcp_server / propose_custom_tool: stored in
  extension_proposals with the bot's background check, shown as a
  [proposal:ID] chip that opens a card with Confirm and Reject
- The card's facts are worked out by the app from what Confirm saves: the
  host, every {{env.KEY}} and whether it's saved, the config; for a skill
  its links, hosts, tool names, mentions of secrets and a diff against
  the saved runbook
- Confirming decides once and checks again; a server or tool missing a key
  is saved switched off, and the outcome is posted to the bot in chat
- Never from a bot: stdio servers, a URL whose host a template decides,
  envs in a prompt tool, a key's value

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 06:08:09 +01:00
co-authored by Claude Opus 5.5
parent e6c278198b
commit fefc295d15
77 changed files with 3307 additions and 12 deletions
@@ -0,0 +1,47 @@
import grabSuperAdminUser from "@/src/functions/backend/backups/grab-super-admin-user";
import confirmExtensionProposal from "@/src/functions/backend/db/extension-proposals/confirm-extension-proposal";
import grabExtensionProposalView from "@/src/functions/backend/db/extension-proposals/grab-extension-proposal-view";
import logEvent, { grabRequestIP } from "@/src/functions/backend/logger";
import { ExtensionProposalIdRequestSchema } from "@/src/schemas/extension-schema";
import type { ExtensionProposalView } from "@/src/types";
import AppError from "@/src/utils/app-error";
import parseWithSchema from "@/src/utils/parse-with-schema";
import safeErrorMessage from "@/src/utils/safe-error-message";
import type { APIResponseObject, BunextAPIRouteHandler } from "@moduletrace/bunext/types";
/**
* Super admin only: confirms an MCP server or tool the coordinator
* proposed, which saves it (switched off while a key it sends is missing)
* and connects a server. Returns the proposal with its outcome, which the
* card then tells the bot in chat.
*/
export const handler: BunextAPIRouteHandler<APIResponseObject<ExtensionProposalView>> = async ({ req, body }) => {
try {
if (req.method != "POST") {
throw new AppError(`Method not allowed`);
}
const user = await grabSuperAdminUser({ req });
if (!user?.id) {
throw new AppError(`Only a super admin can do that.`);
}
const { proposal_id } = parseWithSchema({ schema: ExtensionProposalIdRequestSchema, data: body });
const proposal = await confirmExtensionProposal({ user_id: user.id, proposal_id });
const view = await grabExtensionProposalView({ proposal_id, user_id: user.id });
await logEvent({
title: view.status == "failed" ? "Proposal failed" : "Proposal confirmed",
category: "system",
user_id: user.id,
plain_text: `User #${user.id} confirmed the proposal #${proposal.id} (${proposal.kind} ${proposal.name}): ${view.outcome}`,
metadata: { proposal_id: proposal.id, kind: proposal.kind, result_id: view.result_id, host: view.host },
ip_address: grabRequestIP(req),
});
return { success: true, msg: view.outcome, singleRes: view };
} catch (error: unknown) {
return { success: false, msg: safeErrorMessage({ error }) };
}
};
@@ -0,0 +1,32 @@
import grabSuperAdminUser from "@/src/functions/backend/backups/grab-super-admin-user";
import grabExtensionProposalView from "@/src/functions/backend/db/extension-proposals/grab-extension-proposal-view";
import { ExtensionProposalIdRequestSchema } from "@/src/schemas/extension-schema";
import type { ExtensionProposalView } from "@/src/types";
import AppError from "@/src/utils/app-error";
import parseWithSchema from "@/src/utils/parse-with-schema";
import safeErrorMessage from "@/src/utils/safe-error-message";
import type { APIResponseObject, BunextAPIRouteHandler } from "@moduletrace/bunext/types";
/**
* `GET ?proposal_id=`, super admin only: an MCP server or tool the
* coordinator proposed to them, as its chip and confirm card show it.
*/
export const handler: BunextAPIRouteHandler<APIResponseObject<ExtensionProposalView>> = async ({ req, query }) => {
try {
if (req.method != "GET") {
throw new AppError(`Method not allowed`);
}
const user = await grabSuperAdminUser({ req });
if (!user?.id) {
throw new AppError(`Only a super admin can do that.`);
}
const { proposal_id } = parseWithSchema({ schema: ExtensionProposalIdRequestSchema, data: query });
return { success: true, singleRes: await grabExtensionProposalView({ proposal_id, user_id: user.id }) };
} catch (error: unknown) {
return { success: false, msg: safeErrorMessage({ error }) };
}
};
@@ -0,0 +1,44 @@
import grabSuperAdminUser from "@/src/functions/backend/backups/grab-super-admin-user";
import grabExtensionProposalView from "@/src/functions/backend/db/extension-proposals/grab-extension-proposal-view";
import rejectExtensionProposal from "@/src/functions/backend/db/extension-proposals/reject-extension-proposal";
import logEvent, { grabRequestIP } from "@/src/functions/backend/logger";
import { ExtensionProposalIdRequestSchema } from "@/src/schemas/extension-schema";
import type { ExtensionProposalView } from "@/src/types";
import AppError from "@/src/utils/app-error";
import parseWithSchema from "@/src/utils/parse-with-schema";
import safeErrorMessage from "@/src/utils/safe-error-message";
import type { APIResponseObject, BunextAPIRouteHandler } from "@moduletrace/bunext/types";
/**
* Super admin only: rejects an MCP server or tool the coordinator
* proposed. Nothing is saved.
*/
export const handler: BunextAPIRouteHandler<APIResponseObject<ExtensionProposalView>> = async ({ req, body }) => {
try {
if (req.method != "POST") {
throw new AppError(`Method not allowed`);
}
const user = await grabSuperAdminUser({ req });
if (!user?.id) {
throw new AppError(`Only a super admin can do that.`);
}
const { proposal_id } = parseWithSchema({ schema: ExtensionProposalIdRequestSchema, data: body });
const proposal = await rejectExtensionProposal({ user_id: user.id, proposal_id });
await logEvent({
title: "Proposal rejected",
category: "system",
user_id: user.id,
plain_text: `User #${user.id} rejected the proposal #${proposal.id} (${proposal.kind} ${proposal.name}).`,
metadata: { proposal_id: proposal.id, kind: proposal.kind },
ip_address: grabRequestIP(req),
});
return { success: true, singleRes: await grabExtensionProposalView({ proposal_id, user_id: user.id }) };
} catch (error: unknown) {
return { success: false, msg: safeErrorMessage({ error }) };
}
};