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
- Inspect the POST response body and confirm it is a full connection object
- Validate the body with a real guard instead of the `payload as CreatedMcpConnection` cast so malformed bodies surface early
- Check runReauthableAction: ensure that after a re-auth the request is retried and 'created' gets assigned
- 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
- Never use `as` casts on response bodies; validate with a type guard
- Ensure re-auth wrappers retry-and-assign rather than resolving without the request result
- Return the created resource in 2xx bodies, never an empty body
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
- Collection update response was incomplete.
- MCP tool catalog response was incomplete.
- MCP tool policy response was incomplete.
- MCP tool result was incomplete.
- invalid_mcp_token_payload
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/0dfc15430bcc23c8.
Report an issue: GitHub.