{"record":{"id":"bd9695d30d9c64a6","repo":"gitbutlerapp/gitbutler","slug":"the-host-rejected-the-request","errorCode":null,"errorMessage":"The host rejected the request.","messagePattern":"The host rejected the request\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/but-mcp-app/src/WorkspaceApp.tsx","lineNumber":792,"sourceCode":"\t\t\t\t\tawait app.updateModelContext(selectionContext(view, selection));\n\t\t\t\t} catch {\n\t\t\t\t\t// The message below carries the same repository and selection context.\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst identifier = selectionIdentifier(selection);\n\t\t\tconst subject =\n\t\t\t\tselection.kind === \"commit\"\n\t\t\t\t\t? `commit ${identifier}`\n\t\t\t\t\t: `branch ${identifier} against its configured target`;\n\t\t\tconst request =\n\t\t\t\taction === \"explain\"\n\t\t\t\t\t? `Explain ${subject} in repository ${view.repository.path}. Describe its intent and the important changes.`\n\t\t\t\t\t: `Review ${subject} in repository ${view.repository.path} for correctness, regressions, and missing tests.`;\n\t\t\tconst result = await app.sendMessage({\n\t\t\t\trole: \"user\",\n\t\t\t\tcontent: [{ type: \"text\", text: request }],\n\t\t\t});\n\t\t\tif (result.isError) throw new Error(\"The host rejected the request.\");\n\t\t} catch (caught) {\n\t\t\tsetDetailError(\n\t\t\t\tcaught instanceof Error ? caught.message : \"Could not start the agent request.\",\n\t\t\t);\n\t\t} finally {\n\t\t\tsetPendingAction(null);\n\t\t}\n\t}\n\n\tfunction clearSelection() {\n\t\tdetailRequest.current += 1;\n\t\tsetSelection(null);\n\t\tsetDetail(null);\n\t\tsetDetailError(null);\n\t\tsetDetailLoading(false);\n\t\tsetCopied(null);\n\t\tsetPendingAction(null);\n\t\tif (canUpdateContext) {","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/packages/but-mcp-app/src/WorkspaceApp.tsx#L774-L810","documentation":"handleAction sends a chat 'explain'/'review' request to the MCP host via app.sendMessage and throws a generic 'The host rejected the request.' when the returned result.isError is set. Unlike tool errors, the host's reason is not surfaced — the fixed message hides the underlying rejection cause.","triggerScenarios":"The host returns isError for the chat message: no agent/model session available, the host disallows chat for this app state, invalid message content shape, or host-side agent failure.","commonSituations":"Operating the app in a host that has no agent/LLM configured; sending a prompt while the agent session is busy or terminated; the host denying message sends for permissions/quota reasons.","solutions":["Inspect the host/agent logs for the actual rejection reason — the thrown message is generic by design.","Include textFromToolResult(result) (or the result's error content) in the thrown message to surface the real cause.","Confirm the host session has an agent/model configured and is connected.","Retry the send after the agent session is idle; verify the message content matches the host's expected schema.","Disable or hide the Explain/Review actions when the host does not support chat."],"exampleFix":"// before\nif (result.isError) throw new Error(\"The host rejected the request.\");\n// after\nif (result.isError) {\n  const reason = result.content?.map((c) => c.text ?? \"\").join(\"\\n\").trim();\n  throw new Error(reason || \"The host rejected the request.\");\n}","handlingStrategy":"try-catch","validationCode":"if (!app.isConnected?.()) { setDetailError(\"Agent host is not connected.\"); return; }\nif (!chatSupported) { setDetailError(\"Chat is not available in this host.\"); return; }","typeGuard":"function isSendOk(result: unknown): result is { isError: false } {\n  return typeof result === \"object\" && result !== null && (result as any).isError !== true;\n}","tryCatchPattern":"try {\n  const result = await app.sendMessage({ role: \"user\", content: [{ type: \"text\", text: request }] });\n  if (result.isError) throw new Error(extractHostReason(result) ?? \"The host rejected the request.\");\n} catch (caught) {\n  setDetailError(caught instanceof Error ? caught.message : \"Could not start the agent request.\");\n} finally {\n  setPendingAction(null);\n}","preventionTips":["Feature-detect chat/agent support before showing Explain/Review buttons.","Never throw away the host's error details — include them in the thrown message.","Check the agent session state (idle/connected) before sending.","Keep the message payload aligned with the host's expected content schema."],"tags":["mcp","chat","host"],"backgroundTag":"api-error-response","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}