Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions apps/desktop/src/acp/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { mockBrowse, mockCreate } from "./mockFolders";
import { ACP_CAPS, HARNESS_MODELS, initialHarnesses, MOCK_CUSTOM_MODELS, withLast } from "./mockHarnesses";
import { MockLoops } from "./mockLoops";
import { MOCK_LOCAL_HOST, mockHostEntry, mockNameWins, mockRemote } from "./mockMachineFixtures";
import { MockAddedMcp } from "./mockMcp";
import { MockOutside } from "./mockOutside";
import {
APP_PATCH,
Expand Down Expand Up @@ -205,7 +206,7 @@ export class MockEngine {
private activeTheme = "rustcode";
/** MCP servers the mock restarted through `_rustcode/capabilities/mcp/restart`. */
private mcpRestarted = new Set<string>();
private sentrySignedIn = false; // the remote `sentry` row's `auth`
private mcpAdded = new MockAddedMcp();
/**
* The timed approvals `_rustcode/permissions` lists: one seeded hour so the
* details panel has "Allowed for 42m · Revoke" to show, and whatever the user
Expand Down Expand Up @@ -279,17 +280,7 @@ export class MockEngine {
tools: 0,
error: "MCP server 'fagbrev' failed to start: spawn npx ENOENT",
},
{
name: "sentry",
transport: "http",
target: "https://mcp.sentry.dev/mcp",
enabled: true,
scope: "user",
connection: this.sentrySignedIn ? "connected" : "not_connected",
tools: this.sentrySignedIn ? 58 : 0,
error: null,
auth: this.sentrySignedIn ? "signed_in" : "signed_out",
},
...this.mcpAdded.servers,
];
}

Expand Down Expand Up @@ -2456,14 +2447,14 @@ export class MockEngine {
}
case "_rustcode/capabilities/set":
return this.handle("_rustcode/capabilities", {});
case "_rustcode/capabilities/mcp/logout": {
if (str(params.name) === "sentry") this.sentrySignedIn = false;
case "_rustcode/capabilities/mcp/logout":
case "_rustcode/capabilities/mcp/add":
case "_rustcode/capabilities/mcp/remove":
this.mcpAdded.apply(method, params);
return this.handle("_rustcode/capabilities", {});
}
case "_rustcode/capabilities/mcp/restart": {
const name = str(params.name) ?? "";
if (name === "sentry") this.sentrySignedIn = true;
else if (name !== "github" && name !== "sqlite" && name !== "fagbrev")
if (!this.mcpAdded.signIn(name) && name !== "github" && name !== "sqlite" && name !== "fagbrev")
throw Object.assign(new Error(`MCP server '${name}' is no longer configured`), {
code: -32602,
});
Expand Down
69 changes: 69 additions & 0 deletions apps/desktop/src/acp/mockMcp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { arr, type JsonObject, str } from "./jsonrpc";

const NO_SIGN_IN = /context7|deepwiki|huggingface/;

const signedOut = (server: JsonObject): JsonObject => ({
...server,
connection: "not_connected",
tools: 0,
auth: "signed_out",
});

/**
* The mock's remote MCP servers that sign in with OAuth: the seeded `sentry` row and any server
* added through `_rustcode/capabilities/mcp/add`, which signs itself in a moment later as the
* engine's browser login would. Reconnecting one signs it in; logging out forgets it.
*/
export class MockAddedMcp {
servers: JsonObject[] = [
signedOut({
name: "sentry",
transport: "http",
target: "https://mcp.sentry.dev/mcp",
enabled: true,
scope: "user",
error: null,
}),
];

apply(method: string, params: JsonObject) {
const name = str(params.name);
if (method.endsWith("/remove")) this.servers = this.servers.filter((server) => str(server.name) !== name);
else if (method.endsWith("/logout"))
this.servers = this.servers.map((server) => (str(server.name) === name ? signedOut(server) : server));
else this.add(params);
}

private add(params: JsonObject) {
const name = str(params.name) ?? "server";
const target = arr(params.target).map(String);
const http = str(params.transport) === "http";
const ready = !http || NO_SIGN_IN.test(target[0] ?? "");
const server: JsonObject = {
name,
transport: http ? "http" : "stdio",
target: target.join(" "),
enabled: true,
scope: "user",
connection: "connected",
tools: 4,
error: null,
};
this.servers = [
...this.servers.filter((entry) => str(entry.name) !== name),
ready ? server : signedOut(server),
];
if (http && !ready) setTimeout(() => this.signIn(name), 2500);
}

/** Signs a server in; `false` when it is not one of these. */
signIn(name: string): boolean {
if (!this.servers.some((server) => str(server.name) === name)) return false;
this.servers = this.servers.map((server) =>
str(server.name) === name
? { ...server, connection: "connected", tools: name === "sentry" ? 58 : 12, auth: "signed_in" }
: server,
);
return true;
}
}
2 changes: 1 addition & 1 deletion apps/desktop/src/fileSize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SLACK = 100;
/** Files over the budget, capped at their size when the budget came in, rounded up to the next hundred. */
const OVERSIZED: Record<string, number> = {
"state/store.ts": 1800,
"acp/mock.ts": 3300,
"acp/mock.ts": 3288,
};

function sources(dir: string): string[] {
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/src/ui/Capabilities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface Skill {
enabled: boolean;
}

interface McpServer {
export interface McpServer {
name: string;
transport: string;
target: string;
Expand All @@ -62,16 +62,16 @@ interface McpServer {
}

/** A browser sign-in waits up to five minutes for the user (the engine's loopback limit). */
const SIGN_IN_TIMEOUT = 310_000;
export const SIGN_IN_TIMEOUT = 310_000;

interface Capabilities {
export interface Capabilities {
skills: Skill[];
mcpServers: McpServer[];
configPath?: string;
}

/** The engine sends `tools` as the tool names; an older mock sent a count. */
const parseCapabilities = (v: Json): Capabilities => {
export const parseCapabilities = (v: Json): Capabilities => {
const root = obj(v) ?? {};
return {
configPath: str(root.configPath),
Expand Down
Loading
Loading