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
36 changes: 36 additions & 0 deletions dashboard/e2e/integrations-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
if (!at("admin")) return forbidden(r);
return json(r, { own_app: { id: `app-${own[1]}`, client_id: body?.client_id, has_secret: true, status: "not_connected", status_reason: "", connected_by: "", connected_at: "", redirect_uri: "http://localhost:3000/settings/integrations/mcp-callback/" } });
}
const ours = p.match(/^\/api\/mcp-servers\/apps\/([a-z]+)\/coderhelm$/);
if (ours && method === "POST") {
if (!at("admin")) return forbidden(r);
return json(r, {
authorize_url: "/settings/integrations/mcp-callback/?state=s2&code=c2",
own_app: { id: `app-${ours[1]}`, source: "coderhelm", client_id: "", has_secret: false, status: "not_connected", status_reason: "", connected_by: "", connected_at: "", redirect_uri: "http://localhost:3000/settings/integrations/mcp-callback/" },
});
}
if (/^\/api\/mcp-servers\/app-[a-z]+\/connect$/.test(p)) return json(r, { authorize_url: "/settings/integrations/mcp-callback/?state=s1&code=c1" });
if (p === "/api/mcp-servers/oauth/callback") return json(r, { server: { id: "app-figma", name: "Figma", catalog_id: "figma" }, tools_error: null, own_app: true });
if (p === "/api/alert-notify" && method === "GET") return at("admin") ? json(r, db.notify) : forbidden(r);
Expand Down Expand Up @@ -650,3 +658,31 @@ test("Figma signs in with the team's own app, its redirect URL and scopes shown,
expect(db.calls.some((c) => c.method === "POST" && c.path === "/api/mcp-servers/app-figma/connect")).toBe(true);
await expect(page).toHaveURL(/\/settings\/integrations\/#integration-figma$/);
});

test("Figma signs in with Coderhelm's app in one click; my own app and a key are the other choices", async ({ page }) => {
const db = await mockApi(page);
const figma = db.items.find((i) => i.id === "figma")!;
const detail = figma.detail as Record<string, unknown> & { plugin: Record<string, unknown> };
detail.own_app_redirect_uri = "https://app.coderhelm.com/settings/integrations/mcp-callback/";
detail.coderhelm_app = true;
detail.plugin.own_app = {
authorize: "https://www.figma.com/oauth",
token: "https://api.figma.com/v1/oauth/token",
refresh: "https://api.figma.com/v1/oauth/refresh",
scopes: ["current_user:read", "file_content:read"],
console: "https://www.figma.com/developers/apps",
guide: "https://developers.figma.com/docs/rest-api/oauth-apps/",
};
await page.goto("/settings/integrations#integration-figma");
const card = row(page, "figma");
const ours = card.getByTestId("coderhelm-app");
await expect(ours).toContainText("current_user:read, file_content:read");
// The own app's steps and the key wait behind their disclosures.
await expect(card.getByText("Use my own Figma app", { exact: true }).first()).toBeVisible();
await expect(card.getByText("Use a key instead", { exact: true })).toBeVisible();
await expect(card.getByTestId("own-app")).toBeHidden();
await ours.getByRole("button", { name: "Sign in with Figma" }).click();
await expect.poll(() => db.calls.some((c) => c.path === "/api/mcp-servers/oauth/callback")).toBe(true);
expect(db.calls.some((c) => c.method === "POST" && c.path === "/api/mcp-servers/apps/figma/coderhelm")).toBe(true);
expect(db.calls.some((c) => c.method === "PUT" && c.path === "/api/mcp-servers/apps/figma")).toBe(false);
});
81 changes: 78 additions & 3 deletions dashboard/src/components/mcp-server-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,53 @@ import { useToast } from "./toast";
import { inputClass, linkButton, primaryButton, secondaryButton } from "./ui";
import { connectCatalogServer, startMcpSignIn } from "./mcp-servers";
import { CopyButton } from "./copy-button";
import { HybridAppChoice } from "./hybrid-app-choice";

// A catalog MCP server (Sentry, Linear, Notion…), opened in place on
// Integrations and on Connections: signing in through the vendor's remote
// server when it has one, or a key, its instructions and turning it off.

/** An MCP server: credentials (entered here, never shown again), its test, its instructions, and turning it off. */
export function PluginPanel({ item, onChanged, onClose }: { item: Integration; onChanged: () => Promise<void>; onClose: () => void }) {
const d = item.detail as { plugin: PluginDef; enabled: boolean; has_credentials: boolean; custom_prompt: string; remote?: McpServer | null; own_app?: OwnAppState | null; own_app_redirect_uri?: string | null };
const d = item.detail as {
plugin: PluginDef;
enabled: boolean;
has_credentials: boolean;
custom_prompt: string;
remote?: McpServer | null;
own_app?: OwnAppState | null;
own_app_redirect_uri?: string | null;
coderhelm_app?: boolean;
};
const p = d.plugin;
const keyForm = <PluginKeyPanel item={item} onChanged={onChanged} onClose={onClose} />;
// The vendor's MCP server takes only apps it approved, but its API takes
// the team's own app: sign in with that, or use a key.
// Coderhelm's app or the team's own: sign in with one, or use a key.
if (p.own_app) {
const signedIn = d.own_app?.status === "connected";
const mine = d.own_app && (d.own_app.source ?? "own") === "own" ? d.own_app : null;
const ownPanel = <OwnAppPanel plugin={p} state={mine} redirectUri={d.own_app_redirect_uri ?? ""} onChanged={onChanged} />;
if (d.coderhelm_app) {
// Coderhelm's app: one sign-in button; the team's own app and a key
// are the other choices, behind their disclosures.
const ours = d.own_app && d.own_app.source === "coderhelm" ? d.own_app : null;
return (
<div className="mt-4 flex flex-col gap-4">
<HybridAppChoice id={p.id} name={p.name} onChanged={() => void onChanged()} />
<CoderhelmAppSignIn plugin={p} state={ours} />
<Disclosure summary={`Use my own ${p.name} app`} defaultOpen={!!mine}>
{ownPanel}
</Disclosure>
<Disclosure summary="Use a key instead" defaultOpen={!signedIn && !mine && d.has_credentials}>
{keyForm}
</Disclosure>
</div>
);
}
return (
<div className="mt-4 flex flex-col gap-4">
<OwnAppPanel plugin={p} state={d.own_app ?? null} redirectUri={d.own_app_redirect_uri ?? ""} onChanged={onChanged} />
<HybridAppChoice id={p.id} name={p.name} onChanged={() => void onChanged()} />
{ownPanel}
<Disclosure summary="Use a key instead" defaultOpen={!signedIn && d.has_credentials}>
{keyForm}
</Disclosure>
Expand Down Expand Up @@ -141,6 +171,51 @@ function OAuthOffer({ plugin }: { plugin: PluginDef }) {
);
}

/** Signing in with Coderhelm's own app with the vendor: nothing to create or paste. */
function CoderhelmAppSignIn({ plugin, state }: { plugin: PluginDef; state: OwnAppState | null }) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
const scopes = plugin.own_app?.scopes ?? [];
const go = async () => {
setBusy(true);
setError("");
try {
const r = await api.connectCoderhelmApp(plugin.id);
window.location.assign(r.authorize_url);
} catch (e) {
setError(errorMessage(e, "Couldn't start the sign-in."));
setBusy(false);
}
};
return (
<div className="flex flex-col gap-2 rounded-lg border border-zinc-800 bg-zinc-900/60 p-3" data-testid="coderhelm-app">
{state?.status === "connected" ? (
<p className="text-sm text-emerald-400" data-testid="coderhelm-app-status">
Signed in{state.connected_by ? ` by ${state.connected_by}` : ""} with Coderhelm&apos;s app. Agents read {plugin.name} with this sign-in.
</p>
) : state?.status_reason ? (
<p role="alert" className="text-sm text-amber-400" data-testid="coderhelm-app-status">
{state.status_reason}
</p>
) : (
<p className="text-sm text-zinc-300">
You sign in at {plugin.name} and allow Coderhelm to read{scopes.length ? ` (${scopes.join(", ")})` : ""}. Nothing is changed in {plugin.name}.
</p>
)}
{error && (
<p role="alert" className="text-sm text-red-400">
{error}
</p>
)}
<div>
<button type="button" disabled={busy} className={primaryButton} onClick={() => void go()} data-testid="coderhelm-app-sign-in">
{busy ? "Opening sign-in…" : state?.status === "connected" ? "Sign in again" : `Sign in with ${plugin.name}`}
</button>
</div>
</div>
);
}

/** The team's own OAuth app with the vendor: where to create it, its client id and secret, and signing in with it. */
function OwnAppPanel({ plugin, state, redirectUri, onChanged }: { plugin: PluginDef; state: OwnAppState | null; redirectUri: string; onChanged: () => Promise<void> }) {
const app = plugin.own_app!;
Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,9 @@ export const api = {
method: "PUT",
body: JSON.stringify({ client_id, client_secret }),
}),
/** Signs in with Coderhelm's own app for a catalog server (Figma): replaces the team's own app, if one was saved, and answers where to send the browser. */
connectCoderhelmApp: (catalogId: string) =>
request<{ authorize_url: string; own_app: OwnAppState }>(`/api/mcp-servers/apps/${encodeURIComponent(catalogId)}/coderhelm`, { method: "POST" }),
setMcpClient: (id: string, client_id: string, client_secret: string) =>
request<{ server: McpServer }>(`/api/mcp-servers/${encodeURIComponent(id)}/client`, {
method: "PUT",
Expand Down Expand Up @@ -3025,6 +3028,9 @@ export interface OwnAppDef {
export interface OwnAppState {
/** The connection's id, for connect, disconnect and remove. */
id: string;
/** Whose app it signs in with: Coderhelm's or the team's own. Missing from older gateways (own). */
source?: "coderhelm" | "own";
/** The team's own app's client id; empty for Coderhelm's app. */
client_id: string;
has_secret: boolean;
status: "connected" | "not_connected" | "needs_reconnect" | "failed";
Expand Down
Loading