{"record":{"id":"9bd0abb686177738","repo":"charmbracelet/crush","slug":"failed-to-refresh-mcp-resources-status-code-d","errorCode":null,"errorMessage":"failed to refresh MCP resources: status code %d","messagePattern":"failed to refresh MCP resources: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":420,"sourceCode":"\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}\n\treturn nil\n}\n\n// GetAgentSessionQueuedPrompts retrieves the number of queued prompts for a\n// session.\nfunc (c *Client) GetAgentSessionQueuedPrompts(ctx context.Context, id string, sessionID string) (int, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/agent/sessions/%s/prompts/queued\", id, sessionID), nil, nil)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to get session agent queued prompts: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn 0, fmt.Errorf(\"failed to get session agent queued prompts: status code %d\", rsp.StatusCode)\n\t}\n\tvar count int\n\tif err := json.NewDecoder(rsp.Body).Decode(&count); err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to decode session agent queued prompts: %w\", err)","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L402-L438","documentation":"MCPRefreshResources expects the server to answer HTTP 200. Any other status code (4xx/5xx) is converted to this error with the numeric code embedded. It indicates the server processed the request but rejected or failed it.","triggerScenarios":"Calling MCPRefreshResources when the MCP server name does not exist on the server side (404), auth is rejected (401/403), or the server returns 500 while restarting the MCP connection.","commonSituations":"Typo in the MCP server name passed to the call; auth token expired; server-side MCP process crashed so refresh cannot complete.","solutions":["Log/compare the status code in the error message against expected codes (404 => wrong name, 401 => auth)","Confirm the MCP server name matches one registered in the workspace config","Re-authenticate or refresh credentials if status is 401/403","Check server logs for the 5xx root cause"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if !mcpServerNamePattern.MatchString(name) { return fmt.Errorf(\"invalid MCP server name %q\", name) }","typeGuard":"func isNon200(err error) (int, bool) {\n\ts := err.Error()\n\tvar code int\n\tif n, _ := fmt.Sscanf(s, \"failed to refresh MCP resources: status code %d\", &code); n == 1 { return code, true }\n\treturn 0, false\n}","tryCatchPattern":"if err := client.MCPRefreshResources(ctx, wsID, name); err != nil {\n\tvar code int\n\tif _, ok := fmt.Sscanf(err.Error(), \"failed to refresh MCP resources: status code %d\", &code); ok && code == http.StatusNotFound {\n\t\t// wrong MCP server name — fix config\n\t}\n}","preventionTips":["Keep MCP server names in config consistent with the server side","Re-authenticate before long-running sessions","Check server logs when receiving 5xx","Distinguish status-code errors from transport errors by message shape"],"tags":["http","status-code","mcp"],"backgroundTag":"http-non-200-response","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}