{"record":{"id":"da2475c0df67e4db","repo":"charmbracelet/crush","slug":"failed-to-get-mcp-prompt-status-code-d","errorCode":null,"errorMessage":"failed to get MCP prompt: status code %d","messagePattern":"failed to get MCP prompt: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":352,"sourceCode":"\tif err := json.NewDecoder(rsp.Body).Decode(&prompts); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode MCP prompts: %w\", err)\n\t}\n\treturn prompts, nil\n}\n\n// GetMCPPrompt retrieves a prompt from a named MCP server.\nfunc (c *Client) GetMCPPrompt(ctx context.Context, id, clientID, promptID string, args map[string]string) (string, error) {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/mcp/get-prompt\", id), nil, jsonBody(struct {\n\t\tClientID string            `json:\"client_id\"`\n\t\tPromptID string            `json:\"prompt_id\"`\n\t\tArgs     map[string]string `json:\"args\"`\n\t}{ClientID: clientID, PromptID: promptID, Args: args}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get MCP prompt: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"failed to get MCP prompt: status code %d\", rsp.StatusCode)\n\t}\n\tvar result struct {\n\t\tPrompt string `json:\"prompt\"`\n\t}\n\tif err := json.NewDecoder(rsp.Body).Decode(&result); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to decode MCP prompt response: %w\", err)\n\t}\n\treturn result.Prompt, nil\n}\n","sourceCodeStart":334,"sourceCodeEnd":362,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L334-L362","documentation":"GetMCPPrompt requires HTTP 200 from /workspaces/{id}/mcp/get-prompt. Any other status yields 'failed to get MCP prompt: status code %d'. The body (which may contain the server's error explanation, e.g. invalid prompt arguments) is discarded.","triggerScenarios":"401/403 (auth), 404 (unknown prompt ID, client ID, or workspace), 400 (invalid args for the prompt's schema), 500 (MCP server failed to render the prompt).","commonSituations":"Prompt ID typo; passing arguments that violate the prompt's declared schema; MCP server disconnected so the backend cannot render; expired session token.","solutions":["Map status to cause: 404 → verify promptID/clientID; 400 → check args against the prompt's schema (ListMCPPrompts shows required args); 401 → re-authenticate.","Confirm the MCP server is connected and healthy before rendering.","Check server logs for 5xx details.","Re-fetch the prompt list to ensure the prompt still exists."],"exampleFix":"// before\nprompt, err := client.GetMCPPrompt(ctx, id, clientID, promptID, args)\n// after\nprompt, err := client.GetMCPPrompt(ctx, id, clientID, promptID, args)\nif err != nil && strings.Contains(err.Error(), \"status code 400\") {\n    return \"\", fmt.Errorf(\"invalid arguments for prompt %q — verify required args: %w\", promptID, err)\n}","handlingStrategy":"try-catch","validationCode":"// verify the prompt exists and its required args beforehand\nprompts, err := client.ListMCPPrompts(ctx, workspaceID)\nif err != nil {\n    return err\n}\nvar found *proto.MCPPrompt\nfor i := range prompts {\n    if prompts[i].ID == promptID { found = &prompts[i] }\n}\nif found == nil {\n    return fmt.Errorf(\"prompt %q does not exist; cannot call GetMCPPrompt\", promptID)\n}\n// validate args against found schema before calling","typeGuard":null,"tryCatchPattern":"prompt, err := client.GetMCPPrompt(ctx, id, clientID, promptID, args)\nif err != nil {\n    var code int\n    if n, _ := fmt.Sscanf(err.Error(), \"failed to get MCP prompt: status code %d\", &code); n == 1 {\n        switch {\n        case code == 400:\n            return \"\", fmt.Errorf(\"invalid args for prompt %q\", promptID)\n        case code == 401 || code == 403:\n            // re-authenticate and retry\n        case code == 404:\n            return \"\", fmt.Errorf(\"prompt %q or client %q not found\", promptID, clientID)\n        }\n    }\n    return \"\", err\n}","preventionTips":["List prompts first and validate args against the prompt's schema.","Keep sessions authenticated to avoid 401s mid-workflow.","Handle 404 by re-listing prompts — they may have been removed.","For 5xx, check the MCP server's health before retrying."],"tags":["http","status-code","mcp"],"backgroundTag":"unexpected-http-status","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}