different-ai/openwork · error

Create MCP connection response was incomplete.

Error message

Create MCP connection response was incomplete.

What it means

The add-MCP-connection mutation POSTs connection details and expects the created connection back; the body is cast to CreatedMcpConnection and if it is falsy after the request completes, this error is thrown. Because the value is assigned inside runReauthableAction's callback and only checked afterwards, the error also fires when the callback path never assigned a body (e.g. reauth interrupted the flow) — the client got no usable created-connection object.

Source

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

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

  return useMutation({
    mutationFn: async (input: CreateMcpConnectionInput): 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(input) },
          20000,
        );
        if (!response.ok) {
          throw getRequestError(payload, response, `Failed to add MCP connection (${response.status}).`);
        }
        created = payload as CreatedMcpConnection;
      });
      if (!created) throw new Error("Create MCP connection response was incomplete.");
      return created;
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: mcpConnectionQueryKeys.all });
    },
  });
}

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

  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",

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Inspect the POST response body and confirm it is a full connection object
  2. Validate the body with a real guard instead of the `payload as CreatedMcpConnection` cast so malformed bodies surface early
  3. Check runReauthableAction: ensure that after a re-auth the request is retried and 'created' gets assigned
  4. Fix the server route to return the created connection in the 2xx body

Example fix

// before
created = payload as CreatedMcpConnection;
// after
created = isCreatedMcpConnection(payload) ? payload : null;
// with
function isCreatedMcpConnection(v: unknown): v is CreatedMcpConnection {
  return isRecord(v) && typeof v.id === "string" && typeof v.name === "string";
}
Defensive patterns

Strategy: type-guard

Validate before calling

function isCreatedConnection(v: unknown): boolean {
  return isRecord(v) && typeof v.id === "string" && typeof v.name === "string";
}
// call before returning from the mutation

Type guard

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

Try / catch

try {
  const conn = await addMcpConnection(form);
} catch (err) {
  if (err.message === "Create MCP connection response was incomplete.") {
    // refetch connection list to check whether it was actually created server-side
    await queryClient.invalidateQueries(mcpConnectionQueryKeys.all);
  }
}

Prevention

When it happens

Trigger: POST /connections returns ok with empty body; payload parsed to null/undefined; runReauthableAction completed a re-auth path without executing the request callback that assigns 'created'; response body missing required connection fields consumed downstream.

Common situations: Server returning 201 with empty body; TypeScript 'as CreatedMcpConnection' cast masking a malformed body that later fails on required fields; re-auth flow (token refresh) interleaving so the assignment never happens; dashboard/server version drift on the connection schema.

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/0dfc15430bcc23c8. Report an issue: GitHub.