Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
MCP: name other bots only to people who can see them
Bugfixer 232c38fae45d6
diff --git a/server/host/mcp-chat.ts b/server/host/mcp-chat.tsindex 365ff89a02..65285fb666 100644--- a/server/host/mcp-chat.ts+++ b/server/host/mcp-chat.ts@@ -12,7 +12,7 @@ import { mcpOAuthRedirectUri, type McpOAuthManager } from "../mcp-oauth.ts";import type { LentMcp } from "../lent-mcp.ts";import { listMcpServers } from "../mcp-registry.ts";import type { RequestAuth } from "../request-auth.ts";-import { applyMcpChange, showMcpActivity, type InternalMcpDeps } from "../routes/internal-mcp.ts";+import { applyMcpChange, otherBotsGiven, showMcpActivity, type InternalMcpDeps } from "../routes/internal-mcp.ts";import type { BotRecord, Store } from "../store.ts";import { workspaceDir } from "../workspace.ts";import type { McpConfig } from "./mcp-config.ts";@@ -110,8 +110,8 @@ export function createMcpChat(deps: McpChatDeps) {language: () => threadLanguage(threadId),usedBy: (name) => {const lent = deps.lending?.();- const given = (bot: BotRecord) => mcpServersHost.given(bot).includes(name) || Boolean(lent?.given(bot).includes(name));- return store.bots.filter((bot) => bot.id !== sender.id && !bot.hidden && given(bot) && canUseMcpServer(bot.toolScope, name)).map((bot) => bot.name);+ return otherBotsGiven(store.bots, sender, (bot) =>+ (mcpServersHost.given(bot).includes(name) || Boolean(lent?.given(bot).includes(name))) && canUseMcpServer(bot.toolScope, name));},requestApproval: ({ action, name, subtitle, targetHash, fields }) => mcpRequests.propose({ action, name, botId: sender.id, threadId, targetHash }, subtitle, fields, from),requestSignIn: (name, server) => mcpSignInCards.request({ bot: sender, threadId, ...(from ? { from } : {}) }, name, server),diff --git a/server/routes/internal-mcp.test.ts b/server/routes/internal-mcp.test.tsindex 2c3ed667cb..398743ea5e 100644--- a/server/routes/internal-mcp.test.ts+++ b/server/routes/internal-mcp.test.ts@@ -16,8 +16,9 @@ import * as probeModule from "../mcp-probe.ts";import { listMcpServers, parseStoredMcpServer, type StoredMcpServer } from "../mcp-registry.ts";import { SecretVault } from "../secret-vault.ts";import type { OptionCardData, WireMessage } from "../../shared/wire.ts";+import type { BotRecord } from "../store.ts";import { McpRequestService } from "../host/mcp-requests.ts";-import { applyMcpChange, createInternalMcpRoutes, showMcpActivity, type InternalMcpDeps } from "./internal-mcp.ts";+import { applyMcpChange, createInternalMcpRoutes, otherBotsGiven, showMcpActivity, type InternalMcpDeps } from "./internal-mcp.ts";import { PASS, type RouteContext } from "./table.ts";const BOT = "kiwi";@@ -1122,3 +1123,26 @@ describe("the activity line", () => {expect(thread.messages[1]).not.toHaveProperty("turnId");});});++describe("which other bots a server notice names", () => {+ const bot = (id: string, more: Partial<BotRecord> = {}) => ({ id, name: id.toUpperCase(), ...more }) as BotRecord;+ const everyone = (_bot: BotRecord) => true;++ it("names the other bots that get the server, not the sender or hidden ones", () => {+ const sender = bot("a");+ expect(otherBotsGiven([sender, bot("b"), bot("c", { hidden: true }), bot("d")], sender, (b) => b.id !== "d")).toEqual(["B"]);+ });++ it("leaves out a bot only admins see when people who are not admins see the sender", () => {+ const sender = bot("a");+ const bots = [sender, bot("b"), bot("secret", { visibility: "admins" }), bot("few", { visibility: { people: ["[email protected]"] } })];+ expect(otherBotsGiven(bots, sender, everyone)).toEqual(["B"]);+ });++ it("names a restricted bot to a sender whose audience it covers", () => {+ const sender = bot("a", { visibility: { people: ["[email protected]"] } });+ const bots = [sender, bot("b"), bot("secret", { visibility: "admins" }), bot("few", { visibility: { people: ["[email protected]", "[email protected]"] } })];+ expect(otherBotsGiven(bots, sender, everyone)).toEqual(["B", "FEW"]);+ expect(otherBotsGiven(bots, bot("admin", { visibility: "admins" }), everyone)).toEqual(["A", "B", "SECRET", "FEW"]);+ });+});diff --git a/server/routes/internal-mcp.ts b/server/routes/internal-mcp.tsindex 20724c1b08..5a8981cf7b 100644--- a/server/routes/internal-mcp.ts+++ b/server/routes/internal-mcp.ts@@ -4,6 +4,7 @@ import { relative } from "node:path";import type { McpChangeRequest } from "../../shared/mcp-request.ts";import type { WireMessage as Message } from "../../shared/wire.ts";import type { AppConfig } from "../config.ts";+import { audienceWithin } from "../bot-visibility.ts";import { SERVER_PREFIXES } from "../drivers/agents-bridge.ts";import { MCP_CONFIG_BUSY, runsElsewhere, type McpConfig, type McpConfigRefusal } from "../host/mcp-config.ts";import { MCP_KEY_EXPIRED, type McpApplied, type McpCardAction, type McpUpdateFields } from "../host/mcp-requests.ts";@@ -15,6 +16,7 @@ import type { McpProbeResult } from "../mcp-probe.ts";import { publicMcpUrl, type HostLookup } from "../mcp-public-url.ts";import { isRemoteMcpServer, parseMcpServerMutation, parseStoredMcpServer, type StoredMcpServer, type StoredRemoteMcpServer, type StoredStdioMcpServer } from "../mcp-registry.ts";import { serverLine, type ServerLineKey } from "../server-lines.ts";+import type { BotRecord } from "../store.ts";import { PASS, type RouteHandler } from "./table.ts";const PATH = "/api/internal/mcp-servers";@@ -94,6 +96,12 @@ type Outcome = { status: number; text: string; dropped?: string[] } | { status:/** Which call a line is about, to find that call's own row. */export type McpCall = { action: McpAction; name?: string };+/** The names of the other bots `given` holds, leaving out hidden ones and any whose audience is narrower than the+ * sender's: everyone who sees the sender's chat or room may see the names, so a restricted bot's name stays with its own audience. */+export function otherBotsGiven(bots: readonly BotRecord[], sender: BotRecord, given: (bot: BotRecord) => boolean): string[] {+ return bots.filter((bot) => bot.id !== sender.id && !bot.hidden && audienceWithin(sender.visibility, bot.visibility) && given(bot)).map((bot) => bot.name);+}+export function createInternalMcpRoutes(deps: InternalMcpDeps): RouteHandler {return async ({ res, path, method, json }) => {if (path !== PATH || (method !== "GET" && method !== "POST")) return PASS;