{"record":{"id":"2f37947eae97ae1d","repo":"different-ai/openwork","slug":"create-native-provider-connection-response-was-inc","errorCode":null,"errorMessage":"Create native provider connection response was incomplete.","messagePattern":"Create native provider connection response was incomplete\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx","lineNumber":768,"sourceCode":"  return useMutation({\n    mutationFn: async (input: CreateNativeProviderConnectionInput): Promise<CreatedMcpConnection> => {\n      let created: CreatedMcpConnection | null = null;\n      await runReauthableAction(\"create-mcp-connection\", async () => {\n        const { response, payload } = await requestJson(\n          \"/v1/mcp-connections\",\n          {\n            method: \"POST\",\n            headers: getOrgScopeHeaders(requireOrgId(orgId)),\n            body: JSON.stringify({ kind: \"native_provider\", ...input }),\n          },\n          20000,\n        );\n        if (!response.ok) {\n          throw getRequestError(payload, response, `Failed to add native provider connection (${response.status}).`);\n        }\n        created = payload as CreatedMcpConnection;\n      });\n      if (!created) throw new Error(\"Create native provider connection response was incomplete.\");\n      return created;\n    },\n    onSuccess: () => {\n      queryClient.invalidateQueries({ queryKey: mcpConnectionQueryKeys.all });\n    },\n  });\n}\n\nexport function useUpdateMcpConnection() {\n  const queryClient = useQueryClient();\n  const { orgId, runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (input: UpdateMcpConnectionInput): Promise<UpdatedMcpConnection> => {\n      let updated: UpdatedMcpConnection | null = null;\n      await runReauthableAction(\"update-mcp-connection\", async () => {\n        const { connectionId, ...body } = input;\n        const { response, payload } = await requestJson(","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx#L750-L786","documentation":"Same pattern as the external-connection creation but for native provider connections (e.g. Google/Microsoft via native OAuth): the mutation POSTs and expects the created connection object back; if 'created' is still falsy after the request/reauth wrapper completes, this error is thrown. The response body did not yield a usable CreatedMcpConnection.","triggerScenarios":"Native provider connection POST returns ok with empty/malformed body; runReauthableAction re-auth path completed without assigning 'created'; response shape changed server-side so the cast yields an unexpected object that downstream code treats as absent.","commonSituations":"OAuth callback completing but the follow-up connection-create call returning an acknowledgement-only body; provider slug typo causing server to return a minimal error-shaped 200; version drift between dashboard and den-api native-provider routes.","solutions":["Inspect the POST response body for the native provider connection and confirm required fields (id, name, nativeProviderKey)","Replace the `payload as CreatedMcpConnection` cast with a type guard so malformed bodies are caught with a clear message","Verify runReauthableAction retries the create after token refresh and assigns 'created' before resolving","Align server response schema with the dashboard's CreatedMcpConnection type"],"exampleFix":"// before\ncreated = payload as CreatedMcpConnection;\n// after\ncreated = isRecord(payload) && typeof payload.id === \"string\" ? (payload as CreatedMcpConnection) : null;","handlingStrategy":"type-guard","validationCode":"function isCreatedNativeConnection(v: unknown): boolean {\n  return isRecord(v) && typeof v.id === \"string\" && typeof v.nativeProviderKey === \"string\";\n}","typeGuard":"function isCreatedMcpConnection(v: unknown): v is CreatedMcpConnection {\n  return isRecord(v) && typeof v.id === \"string\" && typeof v.name === \"string\";\n}","tryCatchPattern":"try {\n  const conn = await addNativeProviderConnection(providerKey, tokens);\n} catch (err) {\n  if (err.message === \"Create native provider connection response was incomplete.\") {\n    await queryClient.invalidateQueries(mcpConnectionQueryKeys.all); // reconcile server state\n  }\n}","preventionTips":["Validate native-provider create responses with a guard instead of a cast","Contract-test native provider OAuth completion → connection create response","On failure, reconcile by refetching the connections list since the server may have created the row anyway"],"tags":["api","response-shape","oauth","native-provider"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}