Skip to content

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

fix(mcp): accept member key saves that only know the host

Sebastian B90e7906c5829
diff --git a/docs/team-cloud.md b/docs/team-cloud.md
index 564c3f56c7..44c45421b5 100644
--- a/docs/team-cloud.md
+++ b/docs/team-cloud.md
@@ -130,7 +130,7 @@ their team page in MausBot Cloud (the Admin's Cloud page calls the routes below
| `POST /api/team/my-connections/apps/:slug/connect` | the member | `{ url }`, the app's own sign-in (a new tab) |
| `DELETE /api/team/my-connections/apps/:slug` | the member | |
| `POST /api/team/my-connections/mcp/:name/sign-in` | the member | `{ auth }`; it comes back to this server's `/mcp-oauth/callback` |
-| `PUT /api/team/my-connections/mcp/:name/key { value, url }` | the member | write-only; requires the expected server URL; returns 409 if it changed |
+| `PUT /api/team/my-connections/mcp/:name/key { value, url? }` | the member | write-only; with `url`, returns 409 if the server URL changed |
| `DELETE /api/team/my-connections/mcp/:name` | the member | |
The signed read (`GET /api/cloud/team/admin`) adds `scopes: { apps, mcp }` and `people: { apps: { <slug>: [address] },
diff --git a/server/cloud-team-connections.e2e.test.ts b/server/cloud-team-connections.e2e.test.ts
index aa90429909..3e084f6ccd 100644
--- a/server/cloud-team-connections.e2e.test.ts
+++ b/server/cloud-team-connections.e2e.test.ts
@@ -135,7 +135,7 @@ it("lets Ada connect her own Gmail and mail key, and nobody reads them back", as
adaUser = broker.userFor(broker.installationIds().at(-1)!);
expect(adaUser).not.toBe(teamUser);
broker.account(adaUser, "gmail", "[email protected]");
- expect((await team.as(ada, "PUT", "/api/team/my-connections/mcp/mail/key", { value: ADA_KEY, url: mail.url })).body).toEqual({ ok: true });
+ expect((await team.as(ada, "PUT", "/api/team/my-connections/mcp/mail/key", { value: ADA_KEY })).body).toEqual({ ok: true });
// A team app is not hers to connect, and Slack is the team's.
expect((await team.as(ada, "POST", "/api/team/my-connections/apps/slack/connect", {})).status).toBe(409);
diff --git a/server/routes/team-connections.test.ts b/server/routes/team-connections.test.ts
index f46bec360d..f2754718a7 100644
--- a/server/routes/team-connections.test.ts
+++ b/server/routes/team-connections.test.ts
@@ -61,7 +61,13 @@ it("saves a personal key for the matching URL", async () => {
expect(people.key(PERSON, "mail", URL_B)).toBeNull();
});
-it.each([undefined, "", 123])("requires the expected URL instead of pinning a key to the current address (%s)", async (url) => {
+it("pins a key sent without a URL to the current address, as members only see the host", async () => {
+ const { people, save } = setup();
+ expect(await save({ value: KEY })).toEqual({ status: 200, body: { ok: true } });
+ expect(people.key(PERSON, "mail", URL_A)).toEqual({ url: URL_A, header: "Authorization", value: KEY });
+});
+
+it.each(["", 123])("refuses a malformed expected URL (%s)", async (url) => {
const { people, save } = setup();
expect((await save({ value: KEY, url })).status).toBe(400);
expect(people.key(PERSON, "mail", URL_A)).toBeNull();
diff --git a/server/routes/team-connections.ts b/server/routes/team-connections.ts
index 20c8c54ffb..eadae101b4 100644
--- a/server/routes/team-connections.ts
+++ b/server/routes/team-connections.ts
@@ -4,7 +4,7 @@
// POST /api/team/my-connections/apps/:slug/connect → { url } their own sign-in to the app (a new tab)
// DELETE /api/team/my-connections/apps/:slug
// POST /api/team/my-connections/mcp/:name/sign-in → { auth } their own sign-in to the server (a new tab)
-// PUT /api/team/my-connections/mcp/:name/key { value, url } their own key, never read back
+// PUT /api/team/my-connections/mcp/:name/key { value, url? } their own key, never read back
// DELETE /api/team/my-connections/mcp/:name
// The Admin's Cloud page calls these with a session it opened for the person asking (a User's is a client session).
// Every one acts on the session's own person only, and none answers with a key, a token or a path of an address.
@@ -146,9 +146,9 @@ export function createTeamConnectionRoutes(deps: TeamConnectionRouteDeps): Route
const body = await readBody(req, 4096);
const value = typeof body?.value === "string" ? body.value.trim() : "";
if (value.length < 8 || value.length > 512 || !/^[\x21-\x7e]+(?: [\x21-\x7e]+)?$/.test(value)) return json(res, 400, { error: "Paste the key alone." });
- if (typeof body?.url !== "string" || !body.url) return json(res, 400, { error: "Include the MCP server address for this key." });
+ if (body?.url !== undefined && (typeof body.url !== "string" || !body.url)) return json(res, 400, { error: "Send the MCP server address as text." });
const current = server(name);
- if (!current || !isRemoteMcpServer(current) || current.url !== body.url) return json(res, 409, { error: "The MCP server address changed. Reload the server and try again." });
+ if (!current || !isRemoteMcpServer(current) || (body?.url !== undefined && current.url !== body.url)) return json(res, 409, { error: "The MCP server address changed. Reload the server and try again." });
const headerKeys = Object.keys(current.headers);
deps.host.people.putKey(person, email, name, { url: current.url, ...personKeyHeader(headerKeys, value) });
return json(res, 200, { ok: true });