Add MCP servers and custom tools for bots

Two new settings pages, MCPs and Tools. Super admins define them; super
admins and admins attach them to bots, to workspaces (every bot there),
or to every bot. Bots get them in chat replies and tasks.

- Custom tools: a JSON-schema of arguments plus an HTTP request, a script
  on the bot's computer, or a prompt, templated with {{args.x}} and
  {{env.KEY}}, secrets redacted from results.
- MCP servers: remote (URL and headers) or stdio commands run on the host
  with a setup command and an isolated env, in a per-process pool. Tools
  are listed into a cache and connect on first call.
- Add, edit, access and try open in modals.
- Markdown, JSON and command fields use twui's AceEditor (CodeEditor),
  its scripts loaded on demand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-19 15:01:39 +01:00
co-authored by Claude Opus 5.5
parent 550aaeabac
commit c6ec7d77a2
95 changed files with 4733 additions and 164 deletions
+44
View File
@@ -0,0 +1,44 @@
type Params = {
/**
* Which kind: MCP servers or custom tools.
*/
kind: "mcp" | "tool";
bot_id: number | string;
/**
* The workspace the run is in: what's attached to it counts too.
*/
workspace_id?: number | string | null;
};
const Tables = {
mcp: {
table: "mcp_servers",
bot_link: "bot_mcp_servers",
workspace_link: "workspace_mcp_servers",
column: "mcp_server_id",
},
tool: {
table: "custom_tools",
bot_link: "bot_custom_tools",
workspace_link: "workspace_custom_tools",
column: "custom_tool_id",
},
} as const;
/**
* The enabled MCP servers or custom tools a bot gets on one run: those
* for every bot, those attached to the bot, and in a workspace those
* attached to the workspace.
*/
export default function botExtensionsSql({ kind, bot_id, workspace_id }: Params) {
const { table, bot_link, workspace_link, column } = Tables[kind];
return {
sql: `SELECT x.* FROM ${table} x WHERE x.enabled = 1 AND (
x.all_bots = 1
OR x.id IN (SELECT ${column} FROM ${bot_link} WHERE bot_id = ?)
${workspace_id ? `OR x.id IN (SELECT ${column} FROM ${workspace_link} WHERE workspace_id = ?)` : ""}
) ORDER BY x.id ASC`,
values: workspace_id ? [Number(bot_id), Number(workspace_id)] : [Number(bot_id)],
};
}