different-ai/openwork · error

Create native provider connection response was incomplete.

Error message

Create native provider connection response was incomplete.

What it means

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.

Source

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

  return useMutation({
    mutationFn: async (input: CreateNativeProviderConnectionInput): Promise<CreatedMcpConnection> => {
      let created: CreatedMcpConnection | null = null;
      await runReauthableAction("create-mcp-connection", async () => {
        const { response, payload } = await requestJson(
          "/v1/mcp-connections",
          {
            method: "POST",
            headers: getOrgScopeHeaders(requireOrgId(orgId)),
            body: JSON.stringify({ kind: "native_provider", ...input }),
          },
          20000,
        );
        if (!response.ok) {
          throw getRequestError(payload, response, `Failed to add native provider connection (${response.status}).`);
        }
        created = payload as CreatedMcpConnection;
      });
      if (!created) throw new Error("Create native provider connection response was incomplete.");
      return created;
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: mcpConnectionQueryKeys.all });
    },
  });
}

export function useUpdateMcpConnection() {
  const queryClient = useQueryClient();
  const { orgId, runReauthableAction } = useOrgDashboard();

  return useMutation({
    mutationFn: async (input: UpdateMcpConnectionInput): Promise<UpdatedMcpConnection> => {
      let updated: UpdatedMcpConnection | null = null;
      await runReauthableAction("update-mcp-connection", async () => {
        const { connectionId, ...body } = input;
        const { response, payload } = await requestJson(

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Inspect the POST response body for the native provider connection and confirm required fields (id, name, nativeProviderKey)
  2. Replace the `payload as CreatedMcpConnection` cast with a type guard so malformed bodies are caught with a clear message
  3. Verify runReauthableAction retries the create after token refresh and assigns 'created' before resolving
  4. Align server response schema with the dashboard's CreatedMcpConnection type

Example fix

// before
created = payload as CreatedMcpConnection;
// after
created = isRecord(payload) && typeof payload.id === "string" ? (payload as CreatedMcpConnection) : null;
Defensive patterns

Strategy: type-guard

Validate before calling

function isCreatedNativeConnection(v: unknown): boolean {
  return isRecord(v) && typeof v.id === "string" && typeof v.nativeProviderKey === "string";
}

Type guard

function isCreatedMcpConnection(v: unknown): v is CreatedMcpConnection {
  return isRecord(v) && typeof v.id === "string" && typeof v.name === "string";
}

Try / catch

try {
  const conn = await addNativeProviderConnection(providerKey, tokens);
} catch (err) {
  if (err.message === "Create native provider connection response was incomplete.") {
    await queryClient.invalidateQueries(mcpConnectionQueryKeys.all); // reconcile server state
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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