feat(mcp): start assistant setup from Connections

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-05 16:18:27 -05:00
1 parent e75317fd2e
commit baeb1ffe2e
15 files changed
+373 -231

No files matched your search

+25
View File
@@ -168,14 +168,39 @@ describe.skipIf(!support.supported)("public MCP OAuth and tool boundary", () =>
await expect(oauth.token({ grant_type: "refresh_token", client_id: f.client.client_id, resource: config.resource, refresh_token: f.tokens.refresh_token })).rejects.toMatchObject({ status: 503 });
await expect(execute(f.tokens.access_token, "paperclip_list_agents", { companyId: f.company.id })).rejects.toMatchObject({ status: 503 });
expect(dispatch).not.toHaveBeenCalled();
const setup = await request(app).get("/api/mcp/setup").set("X-Forwarded-Host", "attacker.example");
expect(setup.status).toBe(200);
expect(setup.headers["cache-control"]).toBe("no-store");
expect(setup.body).toEqual({ enabled: false, serverUrl: config.resource });
expect((await request(app).get("/api/mcp/connections")).status).toBe(200);
expect((await request(app).post("/mcp/oauth/revoke").send({ token: revocable.tokens.access_token, client_id: revocable.client.client_id })).status).toBe(200);
} finally { await settings.updateExperimental({ enablePublicMcp: true }); }
expect((await request(app).get("/api/mcp/setup")).body).toEqual({ enabled: true, serverUrl: config.resource });
expect((await request(app).get("/.well-known/oauth-authorization-server")).status).toBe(200);
await expect(oauth.authenticate(f.tokens.access_token)).resolves.toMatchObject({ grant: { userId: f.actor.userId } });
await expect(oauth.authenticate(revocable.tokens.access_token)).rejects.toThrow();
});
it("limits assistant setup metadata to signed-in humans", async () => {
const app = express();
let actor: Request["actor"] = { type: "none" };
app.use((req, _res, next) => { req.actor = actor; next(); });
app.use("/api", publicMcpManagementRoutes(oauth));
for (const candidate of [
{ type: "none" },
{ type: "agent", agentId: randomUUID(), companyId: randomUUID() },
{ type: "board", source: "local_implicit", userId: "board" },
{ type: "board", source: "mcp_oauth", userId: randomUUID() },
] as Request["actor"][]) {
actor = candidate;
expect((await request(app).get("/api/mcp/setup")).status).toBe(401);
}
for (const source of ["session", "cloud_tenant"] as const) {
actor = { type: "board", source, userId: randomUUID() };
expect((await request(app).get("/api/mcp/setup")).body).toEqual({ enabled: true, serverUrl: config.resource });
}
});
it("rotates refresh tokens and persists revocation on replay", async () => {
const f = await fixture();
const refresh = { grant_type: "refresh_token", client_id: f.client.client_id, resource: config.resource, refresh_token: f.tokens.refresh_token };
+4 -1
View File
@@ -51,7 +51,7 @@ export function publicMcpIngressRoutes(oauth: PublicMcpOAuth, execute: ReturnTyp
});
router.get(["/.well-known/oauth-protected-resource", "/.well-known/oauth-protected-resource" + PUBLIC_MCP_PATH], (_req, res) => res.json({
resource, authorization_servers: [origin], scopes_supported: PUBLIC_MCP_SCOPES, bearer_methods_supported: ["header"],
resource_name: "Paperclip team",
resource_name: "Paperclip",
}));
router.get("/.well-known/oauth-authorization-server", (_req, res) => res.json({
issuer: origin, authorization_endpoint: prefix + "/authorize", token_endpoint: prefix + "/token",
@@ -183,6 +183,9 @@ export function publicMcpManagementRoutes(oauth: PublicMcpOAuth) {
if (!parsed.success) throw new McpOAuthError("invalid_request", "Choose a company and the requested access.");
res.json(await oauth.consent(String(req.params.id), req.actor, parsed.data));
});
router.get("/mcp/setup", realUser, async (_req, res) => res.json({
enabled: await oauth.isEnabled(), serverUrl: oauth.config.resource,
}));
router.get("/mcp/connections", realUser, async (req, res) => res.json(await oauth.listConnections(req.actor.userId!)));
router.delete("/mcp/connections/:id", realUser, sameOrigin, async (req, res) => {
if (!z.uuid().safeParse(req.params.id).success) throw new McpOAuthError("invalid_request", "Invalid connection ID.");