{"record":{"id":"32cb17de54ad574e","repo":"different-ai/openwork","slug":"invalid-mcp-connection-payload","errorCode":"invalid_mcp_connection_payload","errorMessage":"MCP connection connect response was invalid.","messagePattern":"MCP connection connect response was invalid\\.","errorType":"error_code","errorClass":"DenApiError","httpStatus":500,"severity":"error","filePath":"apps/app/src/app/lib/den.ts","lineNumber":3394,"sourceCode":"\n    async listMcpConnectionPresets(orgId: string): Promise<DenExternalMcpPreset[]> {\n      const payload = await requestJson<unknown>(\n        baseUrls,\n        \"/v1/mcp-connections/presets\",\n        { method: \"GET\", token, organizationId: orgId },\n      );\n      return getDenExternalMcpPresets(payload);\n    },\n\n    async startMcpConnectionConnect(orgId: string, connectionId: string): Promise<DenMcpConnectionConnectStart> {\n      const payload = await requestJson<unknown>(\n        baseUrls,\n        `/v1/mcp-connections/${encodeURIComponent(connectionId)}/connect/start`,\n        { method: \"GET\", token, organizationId: orgId },\n      );\n      const result = getDenMcpConnectionConnectStart(payload);\n      if (!result) {\n        throw new DenApiError(500, \"invalid_mcp_connection_payload\", \"MCP connection connect response was invalid.\");\n      }\n      return result;\n    },\n\n    async disconnectOauthProviderAccount(orgId: string, providerId: string): Promise<void> {\n      await requestJson<unknown>(\n        baseUrls,\n        `/v1/oauth-providers/${encodeURIComponent(providerId)}/disconnect`,\n        { method: \"POST\", token, organizationId: orgId },\n      );\n    },\n\n    async disconnectMyMcpConnectionAccount(orgId: string, connectionId: string): Promise<void> {\n      await requestJson<unknown>(\n        baseUrls,\n        `/v1/mcp-connections/${encodeURIComponent(connectionId)}/disconnect-my-account`,\n        { method: \"POST\", token, organizationId: orgId },\n      );","sourceCodeStart":3376,"sourceCodeEnd":3412,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/app/lib/den.ts#L3376-L3412","documentation":"DenApiError thrown by startMcpConnectionConnect in apps/app/src/app/lib/den.ts when the Den API returned a 2xx for GET /v1/mcp-connections/{connectionId}/connect/start, but the response body failed the getDenMcpConnectionConnectStart shape check (missing or malformed connect-start data such as an OAuth authorize URL / session info). The client refuses to return unvalidated data rather than passing a partially-shaped object downstream.","triggerScenarios":"GET /v1/mcp-connections/:id/connect/start returned 200 but the body was an empty object, an error envelope, HTML from a proxy, or lacked the fields getDenMcpConnectionConnectStart requires (e.g. no authorizeUrl/session data); typically when the connectionId exists but the connection is not in a connectable state or the server version's payload schema differs.","commonSituations":"Pointing the app at a self-hosted or older Den server whose /connect/start endpoint predates the current response schema; a reverse proxy or gateway intercepting the request and returning a 200 page; passing a deleted or wrong-organization connectionId; middleware (mock server, service worker) returning a stubbed body.","solutions":["Log the raw response body from /v1/mcp-connections/:id/connect/start and compare it against the fields getDenMcpConnectionConnectStart expects","Verify the Den server version matches the client: a schema mismatch means upgrade the server or align the client","Confirm the connectionId is valid, exists in the org, and is in a connectable state (list via /v1/mcp-connections first)","Check no proxy/gateway/CDN is rewriting the JSON response into HTML or a login page","Retry after re-authenticating if the token silently fell back to an anonymous/limited session"],"exampleFix":"// before\nconst result = getDenMcpConnectionConnectStart(payload);\nif (!result) {\n  throw new DenApiError(500, \"invalid_mcp_connection_payload\", \"MCP connection connect response was invalid.\");\n}\n// after\ndefensive on caller side:\ntry {\n  const start = await client.startMcpConnectionConnect(orgId, connectionId);\n} catch (err) {\n  if (err instanceof DenApiError && err.code === \"invalid_mcp_connection_payload\") {\n    // inspect raw payload / refresh connection list before retrying\n  }\n}","handlingStrategy":"try-catch","validationCode":"// client-side pre-check before starting connect\nconst conns = await client.listMcpConnections(orgId);\nconst conn = conns.find((c) => c.id === connectionId);\nif (!conn) throw new Error(`Unknown MCP connection: ${connectionId}`);","typeGuard":"function isConnectStart(v: unknown): v is DenMcpConnectionConnectStart {\n  return (\n    typeof v === \"object\" && v !== null &&\n    \"authorizeUrl\" in v && typeof (v as { authorizeUrl?: unknown }).authorizeUrl === \"string\"\n  );\n}","tryCatchPattern":"try {\n  const start = await client.startMcpConnectionConnect(orgId, connectionId);\n} catch (err) {\n  if (err instanceof DenApiError && err.code === \"invalid_mcp_connection_payload\") {\n    // surface 'connect flow unavailable' and let the user retry after refreshing connections\n  } else { throw err; }\n}","preventionTips":["Always resolve connectionId from listMcpConnections rather than persisted/stale values","Pin matching client/server versions of the Den API","Log raw response bodies for /connect/start in dev to catch schema drift early","Check for proxies or service workers that can rewrite API responses","Catch DenApiError by code so payload-shape failures degrade gracefully instead of crashing the connect UI"],"tags":["mcp","api-response","schema-mismatch","den-api"],"backgroundTag":"invalid-api-response-shape","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}