{"record":{"id":"e444db9d02c81188","repo":"charmbracelet/crush","slug":"failed-to-refresh-mcp-prompts-status-code-d","errorCode":null,"errorMessage":"failed to refresh MCP prompts: status code %d","messagePattern":"failed to refresh MCP prompts: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":403,"sourceCode":"\t\t}\n\t\treturn fmt.Errorf(\"failed to authenticate MCP: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// MCPRefreshPrompts refreshes prompts for a named MCP client.\nfunc (c *Client) MCPRefreshPrompts(ctx context.Context, id, name string) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/mcp/refresh-prompts\", id), nil,\n\t\tjsonBody(struct {\n\t\t\tName string `json:\"name\"`\n\t\t}{Name: name}),\n\t\thttp.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to refresh MCP prompts: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to refresh MCP prompts: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// MCPRefreshResources refreshes resources for a named MCP client.\nfunc (c *Client) MCPRefreshResources(ctx context.Context, id, name string) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/mcp/refresh-resources\", id), nil,\n\t\tjsonBody(struct {\n\t\t\tName string `json:\"name\"`\n\t\t}{Name: name}),\n\t\thttp.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to refresh MCP resources: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to refresh MCP resources: status code %d\", rsp.StatusCode)\n\t}","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L385-L421","documentation":"This error is returned by Client.MCPRefreshPrompts when the server responds with a non-200 status code. Unlike MCPAuthenticate, this function does not attempt to decode a proto.Error body, so the caller only receives the raw status: \"failed to refresh MCP prompts: status code %d\". The request reached the server but the refresh was rejected or failed server-side.","triggerScenarios":"Calling MCPRefreshPrompts(ctx, id, name) and the server returns any status other than 200 — 400 for an unknown MCP name, 401/403 for missing credentials/permissions, 404 for a bad workspace id, or 5xx from an internal error contacting the actual MCP server.","commonSituations":"Named MCP client no longer registered on the workspace; token expired after rotation; upstream MCP server down causing the API to return 500; proxy returning 502 during a deploy.","solutions":["Check the numeric status code: 4xx indicates a request/credential problem, 5xx indicates a server-side problem","Verify the MCP name is registered on the workspace and the workspace id is valid","Refresh credentials if the status is 401/403; check server logs if the status is 5xx","Retry with backoff for transient 5xx/429 responses; fix configuration for 4xx responses"],"exampleFix":"// before\nif err := client.MCPRefreshPrompts(ctx, wsID, name); err != nil {\n    log.Printf(\"refresh failed: %v\", err) // only status code known\n}\n\n// after\nif err := client.MCPRefreshPrompts(ctx, wsID, name); err != nil {\n    var statusErr interface{ HTTPStatus() int }\n    _ = statusErr\n    log.Printf(\"refresh failed (status in message): %v — check that MCP %q is registered on %s\", err, name, wsID)\n}","handlingStrategy":"fallback","validationCode":"// Verify the MCP server is registered before attempting a refresh\nfunc mcpRegistered(ctx context.Context, c *Client, wsID, name string) error {\n    servers, err := c.MCPList(ctx, wsID) // or equivalent listing call\n    if err != nil { return err }\n    for _, s := range servers {\n        if s.Name == name { return nil }\n    }\n    return fmt.Errorf(\"mcp %q not registered on workspace %s\", name, wsID)\n}","typeGuard":"// Extract and classify the raw status from the error message\nfunc refreshStatusErr(err error) (code int, transient bool, ok bool) {\n    if err == nil { return 0, false, false }\n    if n, _ := fmt.Sscanf(err.Error(), \"failed to refresh MCP prompts: status code %d\", &code); n == 1 {\n        return code, code == http.StatusTooManyRequests || code >= 500, true\n    }\n    return 0, false, false\n}","tryCatchPattern":"// Fall back to retry for transient statuses, surface otherwise\nif err := client.MCPRefreshPrompts(ctx, wsID, name); err != nil {\n    if code, transient, ok := refreshStatusErr(err); ok {\n        if transient {\n            time.Sleep(2 * time.Second)\n            return client.MCPRefreshPrompts(ctx, wsID, name)\n        }\n        return fmt.Errorf(\"refresh rejected with HTTP %d; verify mcp name and credentials\", code)\n    }\n    return err\n}","preventionTips":["Validate the MCP name against the workspace's registered servers before refreshing","Refresh API tokens before long-running sessions to avoid 401s mid-operation","During deploys, pause or retry refresh calls to ride out proxy 502/503 responses","Check API server logs for 5xx causes when refreshes fail with server-side statuses"],"tags":["http","mcp","status-code","api-error"],"backgroundTag":"unexpected-http-status","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}