Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

MCP Sign in card: say why a server that registers no apps can't sign in

AdityaUmalefb16c3f2a23f
diff --git a/server/host/mcp-sign-in-cards.ts b/server/host/mcp-sign-in-cards.ts
index 54914907d4..6b62681389 100644
--- a/server/host/mcp-sign-in-cards.ts
+++ b/server/host/mcp-sign-in-cards.ts
@@ -168,7 +168,12 @@ export function createMcpSignInCards(deps: McpSignInCardDeps) {
started = await manager.start(name, server.url, undefined, owner, browser);
} catch (error) {
if (error instanceof McpSignInError) return { status: error.status, body: { error: error.message } };
- if (error instanceof McpOAuthError) return { status: 400, body: { error: error.message, code: error.code } };
+ if (error instanceof McpOAuthError) {
+ // A busy port frees up; the other failures last until the server is set up differently.
+ const now = find(threadId, card.id);
+ if (error.code === "port-busy" || !now || now.connector.dismissed) return { status: 400, body: { error: error.message, code: error.code } };
+ return unreachable(threadId, now, { status: 400, reason: () => error.message }, { code: error.code });
+ }
return { status: 502, body: { error: error instanceof Error ? error.message : "Sign-in could not start." } };
}
// The provider refused to register this home's https address.
@@ -181,14 +186,14 @@ export function createMcpSignInCards(deps: McpSignInCardDeps) {
return { status: 200, body: { url: started.authorizationUrl } };
}
- /** A card whose server went away (removed, or no longer one a sign-in reaches) can never finish: it says why, and the
- * bot hears it once. */
- function unreachable(threadId: string, card: McpCard, server: Unreachable): Reply {
+ /** A card whose server went away (removed, or no longer one a sign-in reaches) or can't sign in as it is set up can
+ * never finish: it says why, and the bot hears it once. */
+ function unreachable(threadId: string, card: McpCard, server: Unreachable, extra: Record<string, unknown> = {}): Reply {
const error = server.reason(deps.language(threadId));
patch(threadId, card.id, { status: "failed", error });
const said = `OpenMausBot MCP sign-in for ${card.connector.slug}: ${server.reason(undefined)} Nothing was signed in.`;
if (!find(threadId, card.id)!.connector.resumed && deps.answer(threadId, card.id, said)) patch(threadId, card.id, { resumed: true });
- return { status: server.status, body: { error } };
+ return { status: server.status, body: { error, ...extra } };
}
/** Idempotent: a card already resumed, or one no turn waits on yet, is left as it is. False: nothing to resume. */
diff --git a/server/mcp-sign-in-card.test.ts b/server/mcp-sign-in-card.test.ts
index a165a13fdb..62a62e191e 100644
--- a/server/mcp-sign-in-card.test.ts
+++ b/server/mcp-sign-in-card.test.ts
@@ -20,6 +20,8 @@ import type { RequestAuth } from "./request-auth.ts";
import { createInternalMcpRoutes, type InternalMcpDeps } from "./routes/internal-mcp.ts";
import type { RouteContext } from "./routes/table.ts";
import type { Scope, SessionRecord } from "./sessions.ts";
+import { startFakeHttpMcp } from "./testing/fake-http-mcp-server.ts";
+import { startFakeOAuth } from "./testing/fake-oauth-server.ts";
import { startFakePostiz, type FakePostiz } from "./testing/fake-postiz.ts";
const SIGN_IN_PAGE = "https://postiz.example";
@@ -382,6 +384,21 @@ describe("the Sign in card", () => {
expect(f.provider.counts.register).toBe(0);
});
+ it("a server that registers no apps fails the card with the reason, and the bot hears it once", async () => {
+ const f = await setup();
+ const oauth = await startFakeOAuth({ noRegistration: true });
+ const mcp = await startFakeHttpMcp({ acceptBearer: oauth.isValid, wwwAuthenticate: oauth.challenge });
+ fixtures.push(oauth, mcp);
+ f.cfg.mcpServers!.linear = { type: "http", url: mcp.url, headers: {}, enabled: true } as never;
+ const { card } = await f.signIn();
+ const refused = await f.authorize(card);
+ expect(refused).toMatchObject({ status: 400, body: { code: "no-registration", error: expect.stringContaining("only signs in apps registered with it in advance") } });
+ expect(f.current(card).connector).toMatchObject({ status: "failed", error: refused.body.error, resumed: true });
+ expect(f.answers).toEqual([{ messageId: card.id, text: `OpenMausBot MCP sign-in for linear: ${refused.body.error as string} Nothing was signed in.` }]);
+ await f.authorize(card);
+ expect(f.answers).toHaveLength(1);
+ });
+
it("dismiss cancels the flow and resumes with the not-signed-in text", async () => {
const f = await setup();
const { card } = await f.signIn();