{"record":{"id":"cb83d8a1151d70d9","repo":"charmbracelet/crush","slug":"failed-to-list-mcp-prompts-status-code-d","errorCode":null,"errorMessage":"failed to list MCP prompts: status code %d","messagePattern":"failed to list MCP prompts: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":331,"sourceCode":"\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to read MCP resource: status code %d\", rsp.StatusCode)\n\t}\n\tvar contents []MCPResourceContents\n\tif err := json.NewDecoder(rsp.Body).Decode(&contents); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode MCP resource: %w\", err)\n\t}\n\treturn contents, nil\n}\n\nfunc (c *Client) ListMCPPrompts(ctx context.Context, id string) ([]proto.MCPPrompt, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/mcp/prompts\", id), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to list MCP prompts: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to list MCP prompts: status code %d\", rsp.StatusCode)\n\t}\n\tvar prompts []proto.MCPPrompt\n\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}","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L313-L349","documentation":"ListMCPPrompts expects HTTP 200 from /workspaces/{id}/mcp/prompts. A non-200 response raises 'failed to list MCP prompts: status code %d'; the body is not surfaced, only the numeric status.","triggerScenarios":"401/403 (expired or missing auth), 404 (bad workspace ID or server lacking this route), 500 (backend failed to query MCP servers), 502 from a proxy.","commonSituations":"Auth token expiry during long sessions; older Coder server without the prompts endpoint; MCP server misconfiguration making the backend return 500.","solutions":["Map the status: 401/403 → re-authenticate; 404 → check workspace ID and API version; 5xx → server logs.","Confirm the client and server API versions match.","Ensure configured MCP servers are healthy so the backend query succeeds.","Retry transient 502/503 with backoff."],"exampleFix":"// before\nprompts, err := client.ListMCPPrompts(ctx, id)\n// after\nprompts, err := client.ListMCPPrompts(ctx, id)\nif err != nil && strings.Contains(err.Error(), \"status code 401\") {\n    if err := refreshSession(ctx); err != nil { return nil, err }\n    prompts, err = client.ListMCPPrompts(ctx, id)\n}","handlingStrategy":"try-catch","validationCode":"// ensure an authenticated session before listing\nif sessionExpired() {\n    if err := relogin(ctx); err != nil {\n        return errors.New(\"authentication required before listing MCP prompts\")\n    }\n}","typeGuard":null,"tryCatchPattern":"prompts, err := client.ListMCPPrompts(ctx, id)\nif err != nil {\n    var code int\n    if n, _ := fmt.Sscanf(err.Error(), \"failed to list MCP prompts: status code %d\", &code); n == 1 {\n        switch {\n        case code == 401 || code == 403:\n            err = retryAfterAuth(ctx)\n        case code >= 500:\n            err = retryWithBackoff(ctx)\n        case code == 404:\n            return nil, fmt.Errorf(\"prompts endpoint unavailable — check server version and workspace ID\")\n        }\n    }\n    if err != nil { return nil, err }\n}","preventionTips":["Refresh auth tokens before they expire in long-running sessions.","Verify the server supports the prompts endpoint (version check).","Retry 5xx and 502/503 with exponential backoff.","Validate workspace IDs before calls to avoid 404s."],"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"}