()
| 28 | } |
| 29 | |
| 30 | func newDebugOAuthListCmd() *cobra.Command { |
| 31 | var jsonOutput bool |
| 32 | |
| 33 | cmd := &cobra.Command{ |
| 34 | Use: "list", |
| 35 | Short: "List all stored OAuth tokens", |
| 36 | Args: cobra.NoArgs, |
| 37 | RunE: func(cmd *cobra.Command, _ []string) (commandErr error) { |
| 38 | ctx := cmd.Context() |
| 39 | telemetry.TrackCommand(ctx, "debug", []string{"oauth", "list"}) |
| 40 | defer func() { |
| 41 | telemetry.TrackCommandError(ctx, "debug", []string{"oauth", "list"}, commandErr) |
| 42 | }() |
| 43 | |
| 44 | w := cmd.OutOrStdout() |
| 45 | |
| 46 | entries, err := mcp.ListOAuthTokens() |
| 47 | if err != nil { |
| 48 | return fmt.Errorf("failed to list OAuth tokens: %w", err) |
| 49 | } |
| 50 | |
| 51 | if len(entries) == 0 { |
| 52 | if jsonOutput { |
| 53 | return json.NewEncoder(w).Encode([]any{}) |
| 54 | } |
| 55 | fmt.Fprintln(w, "No OAuth tokens stored.") |
| 56 | return nil |
| 57 | } |
| 58 | |
| 59 | if jsonOutput { |
| 60 | return printOAuthListJSON(w, entries) |
| 61 | } |
| 62 | |
| 63 | printOAuthListText(w, entries) |
| 64 | return nil |
| 65 | }, |
| 66 | } |
| 67 | |
| 68 | cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output in JSON format") |
| 69 | |
| 70 | return cmd |
| 71 | } |
| 72 | |
| 73 | type oauthListEntry struct { |
| 74 | ResourceURL string `json:"resource_url"` |
no test coverage detected