{"record":{"id":"e6d614fed3959c06","repo":"different-ai/openwork","slug":"failed-to-inspect-mcp-tools-response-status","errorCode":null,"errorMessage":"Failed to inspect MCP tools (${response.status}).","messagePattern":"Failed to inspect MCP tools \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx","lineNumber":307,"sourceCode":"    disabledTools: value.disabledTools,\n    updatedBy: value.updatedBy,\n    updatedAt: value.updatedAt,\n  };\n}\n\nexport function useMcpConnectionTools(connectionId: string, enabled: boolean) {\n  const { orgId } = useOrgDashboard();\n  return useQuery({\n    enabled: enabled && Boolean(orgId),\n    queryKey: mcpConnectionQueryKeys.tools(orgId, connectionId),\n    queryFn: async (): Promise<ExternalMcpToolCatalog> => {\n      const { response, payload } = await requestJson(\n        `/v1/mcp-connections/${encodeURIComponent(connectionId)}/tools`,\n        { headers: getOrgScopeHeaders(requireOrgId(orgId)) },\n        30000,\n      );\n      if (!response.ok) {\n        throw getRequestError(payload, response, `Failed to inspect MCP tools (${response.status}).`);\n      }\n      if (!isRecord(payload) || !Array.isArray(payload.tools)) {\n        throw new Error(\"MCP tool catalog response was incomplete.\");\n      }\n      const policy = parseExternalMcpToolPolicy(payload.policy);\n      if (!policy || !payload.tools.every(isExternalMcpTool)) {\n        throw new Error(\"MCP tool catalog response was incomplete.\");\n      }\n      return { tools: payload.tools, policy };\n    },\n  });\n}\n\nexport function useUpdateMcpConnectionToolPolicy(connectionId: string) {\n  const queryClient = useQueryClient();\n  const { orgId } = useOrgDashboard();\n  return useMutation({\n    mutationFn: async (input: Pick<ExternalMcpToolPolicyView, \"allDisabled\" | \"disabledTools\">): Promise<ExternalMcpToolPolicyView> => {","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx#L289-L325","documentation":"Thrown by useMcpConnectionTools when GET /v1/mcp-connections/:id/tools returns a non-ok status (30000ms timeout). getRequestError reports the server's error message or 'Failed to inspect MCP tools (<status>)'. The inspection then cannot produce a tool catalog or a parsed ExternalMcpToolPolicy.","triggerScenarios":"Non-ok response when fetching the tool catalog for a connection: 401/403 when org scope headers (requireOrgId(orgId)) are missing or the user lacks access to the connection, 404 when the connection id is wrong or removed, 408/504 when the remote MCP server is slow to enumerate tools (30s timeout exceeded server-side), 502 when the upstream MCP server is unreachable from Den, 5xx server faults.","commonSituations":"Inspecting a connection whose remote MCP server is offline or slow; deleted/stale connection row in the UI; missing org selection so scope headers are invalid; remote server auth (OAuth) expired so Den cannot list its tools.","solutions":["For 401/403, re-authenticate and ensure a valid org id is passed (requireOrgId throws earlier if absent).","For 404, refresh the connections list; the connection was deleted or the id is stale.","For 502/504/timeout, verify the remote MCP server is reachable/healthy and retry; consider raising the timeout.","For 5xx, retry with backoff and inspect Den server logs.","Handle isReauthRequiredError to start the re-auth flow."],"exampleFix":"// before\nconst { data } = useMcpConnectionTools(orgId, connectionId);\n// after\nconst { data, error } = useMcpConnectionTools(orgId, connectionId);\nif (error) {\n  if (isReauthRequiredError(error)) startReauth();\n  else if (/\\((404)\\)/.test(error.message)) refetchConnections();\n  else showError(error.message);\n}","handlingStrategy":"retry","validationCode":"// before fetching tools\nif (!orgId) throw new Error(\"Select an organization first\");\nif (!connections.some(c => c.id === connectionId)) throw new Error(\"Unknown MCP connection\");","typeGuard":"function isTransientToolError(err: unknown): boolean {\n  return err instanceof Error && /\\((502|503|504|408)\\)/.test(err.message);\n}","tryCatchPattern":"useQuery({\n  queryKey: mcpConnectionQueryKeys.tools(orgId, connectionId),\n  queryFn: () => fetchTools(),\n  retry: (count, err) => count < 2 && isTransientToolError(err),\n});","preventionTips":["Ensure the remote MCP server is healthy before running tool inspection","Keep connection lists fresh so stale ids are not inspected","Always supply the org id for scope headers","Use TanStack Query retry for 5xx/timeout statuses only"],"tags":["http","den-api","mcp"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}