different-ai/openwork · warning

Select an organization before managing connections.

Error message

Select an organization before managing connections.

What it means

requireOrgId is a guard used by every MCP-connections query/mutation in the den dashboard. Org-scoped requests must carry the x-openwork-org-id header; if the org dashboard provider has no selected organization (null), the hook throws synchronously instead of issuing a headerless request. It is a client-side precondition error, not a server failure.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx:20

import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { getRequestError, requestJson } from "../../_lib/den-flow";
import { useOrgDashboard } from "../_providers/org-dashboard-provider";
import {
  type ExternalMcpDiagnostic,
  parseExternalMcpDiagnostic,
} from "./mcp-tool-error-attribution";
import type { McpAuthorizationDebugDetails } from "./mcp-authorization-url";

const ORG_SCOPE_HEADER = "x-openwork-org-id";

function getOrgScopeHeaders(orgId: string) {
  return { [ORG_SCOPE_HEADER]: orgId };
}

function requireOrgId(orgId: string | null) {
  if (!orgId) {
    throw new Error("Select an organization before managing connections.");
  }
  return orgId;
}

export type ExternalMcpAuthType = "oauth" | "apikey" | "none";
export type ExternalMcpCredentialMode = "shared" | "per_member";
export type ExternalMcpConnectionScope = "usable" | "manageable";

export type ExternalMcpAccessSummary = {
  orgWide: boolean;
  memberIds: string[];
  teamIds: string[];
};

export type ExternalMcpRequiredBy = {
  pluginId: string;
  name: string;
};

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Ensure the connections UI is only rendered after an organization is selected (gate on orgId truthiness)
  2. Check the org-dashboard provider actually loaded the org list and set a default selection
  3. Verify the user belongs to at least one organization / re-authenticate if the org list fetch failed
  4. Wrap connection hooks' consumers so queries are disabled (enabled: !!orgId) until orgId exists

Example fix

// before
const catalog = useMcpConnectionTools(orgId, connectionId);
// after
const catalog = useMcpConnectionTools(orgId, connectionId, { enabled: Boolean(orgId && connectionId) });
Defensive patterns

Strategy: validation

Validate before calling

if (!orgId) {
  // do not render/manage connections
  return <OrgPickerPrompt />;
}

Type guard

function hasOrgId(orgId: string | null | undefined): orgId is string {
  return typeof orgId === "string" && orgId.length > 0;
}

Try / catch

try {
  await manageConnections();
} catch (err) {
  if (err.message.includes("Select an organization")) {
    promptOrgSelection();
  }
}

Prevention

When it happens

Trigger: Calling useMcpConnections/useMcpConnectionTools/useRunMcpConnectionTool etc. while orgId from useOrgDashboard() is null — e.g. the org context hasn't loaded, the user has no orgs, or a component rendered outside the org dashboard provider.

Common situations: Deep-linking straight to the connections page before org selection resolves; a user account with zero organizations; component mounted outside OrgDashboardProvider; org fetch failed silently leaving selection null.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/11fc924e2ceba4dd. Report an issue: GitHub.