Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge pull request #4744 from milind-soni/fix/lent-mcp-own-ports
milind-sonid765d70f750c
diff --cc electron/computer-sharing.mjsindex 0713a97c90,e8cd5a9f4b..96cd571d6f--- a/electron/computer-sharing.mjs+++ b/electron/computer-sharing.mjs@@@ -4,9 -4,8 +4,9 @@@ import path from "node:path"import os from "node:os";import { randomBytes, randomUUID } from "node:crypto";import { setTimeout as delay } from "node:timers/promises";+import { allowedServerOrigin } from "./server-address.mjs";import { createSharedCua, executeSharedOperation, personalSecretPaths, sharedComputerError, validCommandSeconds } from "./shared-computer-access.mjs";- import { createLentMcp, LENT_MCP_ACTIONS, validLentMcpServer } from "./lent-mcp.mjs";+ import { createLentMcp, LENT_MCP_ACTIONS, ownPorts, validLentMcpServer } from "./lent-mcp.mjs";import { sharedCuaConnection } from "./shared-cua-connection.mjs";export { sharedCuaConnection };import { createLendingActivity, describeSharedOperation } from "./lending-activity.mjs";diff --cc server/lent-mcp.test.tsindex 4f48034c52,cc321f5428..e6990a9c6a--- a/server/lent-mcp.test.ts+++ b/server/lent-mcp.test.ts@@@ -200,20 -212,17 +212,28 @@@ describe("Test, and adding a server thaexpect(await one.lent.place(address, { principal: null }), "a team Cloud, or a turn that can't use the computer").toEqual({ ok: true, server: address });const kept = { ...address, runsOn: { environmentId: "22222222-2222-4222-8222-222222222222", label: "Studio" } };expect(await one.lent.place(kept, { principal: "cloud-home" })).toEqual({ ok: true, server: kept });- expect(await fixture().lent.place(address, { principal: "cloud-home" }), "nothing lent now: it stays as added").toEqual({ ok: true, server: address });+ });++ it("with no computer lent, refuses a server that needs one and still saves one My Cloud answers", async () => {+ const none = fixture();+ expect(await none.lent.place(address, { principal: "cloud-home" })).toEqual({ ok: false, error: "That address is on the person's own computer, and no computer is lent to My Cloud now. Ask them to lend their Mac or PC, then add it again." });+ const command = { command: "notes-mcp", args: [], env: {}, enabled: true };+ const missing = fixture({ here: here({ program: () => false }) });+ expect(await missing.lent.place(command, { principal: "cloud-home" })).toEqual({ ok: false, error: "This command runs on the person's own computer, and no computer is lent to My Cloud now. Ask them to lend their Mac or PC with its terminal, then add it again." });+ const answered = fixture({ here: here({ answers: async () => true }) });+ expect(await answered.lent.place(address, { principal: "cloud-home" })).toEqual({ ok: true, server: address });+ const server = fixture({ personal: false, place: "this server" });+ expect(await server.lent.place(address, { principal: "cloud-home" }), "a desktop or self-hosted server runs on a computer of its own").toEqual({ ok: true, server: address });});+ it("refuses a loopback address for the lent computer on a port below 1024 or with none, saying how to add it", async () => {+ const one = fixture({ lenders: [lender("Ada's Mac", "s-mac", MAC.environmentId, 2)] });+ for (const url of ["http://127.0.0.1/mcp", "http://localhost:80/mcp", "https://[::1]/mcp", "http://127.0.0.1:1023/mcp"]) {+ expect(await one.lent.place({ ...address, url }, { principal: "cloud-home" }), url).toEqual({ ok: false, error: "This server runs on the person's own computer, which reaches only an MCP server on its own port, 1024 or higher: add it again with the port its server listens on in its address." });+ }+ expect(await one.lent.place({ ...address, url: "http://localhost:19501/mcp" }, { principal: "cloud-home" })).toMatchObject({ ok: true, server: { runsOn: MAC } });+ });+it("with several lent: the one named, else the one the adder is on, else the newest for the person, else the bot asks", async () => {const studio = "33333333-3333-4333-8333-333333333333";const { lent } = fixture({ lenders: [lender("Studio", "s-studio", studio, 3), lender("Ada's Mac", "s-mac", MAC.environmentId, 2)] });diff --cc server/lent-mcp.tsindex cd65b610d6,b68406f825..052bcd1ee7--- a/server/lent-mcp.ts+++ b/server/lent-mcp.ts@@@ -277,13 -284,8 +285,14 @@@ export function createLentMcp(deps: Lenasync place(server: StoredMcpServer, who: { principal: string | null; session?: string; computer?: string; newest?: boolean }): Promise<{ ok: true; server: StoredMcpServer } | { ok: false; error: string }> {if (server.runsOn || !who.principal) return { ok: true, server };const lenders = deps.computers.mcpLenders(who.principal);- if (!lenders.length || !(await needsTheirComputer(server, here))) return { ok: true, server };+ if (!(await needsTheirComputer(server, here))) return { ok: true, server };+ if (!lenders.length) {+ // Only My Cloud has no computer of its own: elsewhere the server runs on one, so a missing program is just missing.+ if (!deps.personal) return { ok: true, server };+ const remote = isRemoteMcpServer(server);+ return { ok: false, error: `${remote ? "That address is" : "This command runs"} on the person's own computer, and no computer is lent to ${deps.place} now. Ask them to lend their Mac or PC${remote ? "" : " with its terminal"}, then add it again.` };+ }+ if (isRemoteMcpServer(server) && !onItsOwnPort(server.url)) return { ok: false, error: "This server runs on the person's own computer, which reaches only an MCP server on its own port, 1024 or higher: add it again with the port its server listens on in its address." };const asked = who.computer?.trim().toLowerCase();const named = asked ? lenders.find((lender) => lender.name.toLowerCase() === asked) : undefined;const names = lenders.map((lender) => lender.name).join(", ");