{"record":{"id":"11fc924e2ceba4dd","repo":"different-ai/openwork","slug":"select-an-organization-before-managing-connections","errorCode":null,"errorMessage":"Select an organization before managing connections.","messagePattern":"Select an organization before managing connections\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx","lineNumber":20,"sourceCode":"\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { getRequestError, requestJson } from \"../../_lib/den-flow\";\nimport { useOrgDashboard } from \"../_providers/org-dashboard-provider\";\nimport {\n  type ExternalMcpDiagnostic,\n  parseExternalMcpDiagnostic,\n} from \"./mcp-tool-error-attribution\";\nimport type { McpAuthorizationDebugDetails } from \"./mcp-authorization-url\";\n\nconst ORG_SCOPE_HEADER = \"x-openwork-org-id\";\n\nfunction getOrgScopeHeaders(orgId: string) {\n  return { [ORG_SCOPE_HEADER]: orgId };\n}\n\nfunction requireOrgId(orgId: string | null) {\n  if (!orgId) {\n    throw new Error(\"Select an organization before managing connections.\");\n  }\n  return orgId;\n}\n\nexport type ExternalMcpAuthType = \"oauth\" | \"apikey\" | \"none\";\nexport type ExternalMcpCredentialMode = \"shared\" | \"per_member\";\nexport type ExternalMcpConnectionScope = \"usable\" | \"manageable\";\n\nexport type ExternalMcpAccessSummary = {\n  orgWide: boolean;\n  memberIds: string[];\n  teamIds: string[];\n};\n\nexport type ExternalMcpRequiredBy = {\n  pluginId: string;\n  name: string;\n};","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the connections UI is only rendered after an organization is selected (gate on orgId truthiness)","Check the org-dashboard provider actually loaded the org list and set a default selection","Verify the user belongs to at least one organization / re-authenticate if the org list fetch failed","Wrap connection hooks' consumers so queries are disabled (enabled: !!orgId) until orgId exists"],"exampleFix":"// before\nconst catalog = useMcpConnectionTools(orgId, connectionId);\n// after\nconst catalog = useMcpConnectionTools(orgId, connectionId, { enabled: Boolean(orgId && connectionId) });","handlingStrategy":"validation","validationCode":"if (!orgId) {\n  // do not render/manage connections\n  return <OrgPickerPrompt />;\n}","typeGuard":"function hasOrgId(orgId: string | null | undefined): orgId is string {\n  return typeof orgId === \"string\" && orgId.length > 0;\n}","tryCatchPattern":"try {\n  await manageConnections();\n} catch (err) {\n  if (err.message.includes(\"Select an organization\")) {\n    promptOrgSelection();\n  }\n}","preventionTips":["Gate all org-scoped hooks behind an orgId-exists check or enabled flag","Set a default org on login so orgId is rarely null","Show an org picker when the org list loads empty instead of rendering action UIs"],"tags":["guard","org-scope","react-query","precondition"],"backgroundTag":"missing-org-context","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}