cli

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmbeddingsCmd = &cobra.Command{
	Use:   "embeddings",
	Short: "Manage semantic embeddings stored in the registry database",
}

EmbeddingsCmd hosts semantic embedding maintenance subcommands.

View Source
var ExportCmd = &cobra.Command{
	Use:    "export",
	Hidden: true,
	Short:  "Export servers from the registry database",
	Long:   "Exports all MCP server entries from the local registry database into a JSON seed file compatible with arctl import.",
	RunE: func(cmd *cobra.Command, args []string) error {
		outputPath := strings.TrimSpace(exportOutput)
		if outputPath == "" {
			return errors.New("--output is required (destination seed file path)")
		}

		cfg := config.NewConfig()

		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()

		authz := auth.Authorizer{Authz: nil}

		db, err := database.NewPostgreSQL(ctx, cfg.DatabaseURL, authz)
		if err != nil {
			return fmt.Errorf("failed to connect to database: %w", err)
		}
		defer func() {
			if closeErr := db.Close(); closeErr != nil {
				log.Printf("Warning: failed to close database: %v", closeErr)
			}
		}()

		registryService := service.NewRegistryService(db, cfg, nil)
		exporterService := exporter.NewService(registryService)

		exportCtx := cmd.Context()
		if exportCtx == nil {
			exportCtx = context.Background()
		}

		exporterService.SetReadmeOutputPath(exportReadmeOutput)

		count, err := exporterService.ExportToPath(exportCtx, outputPath)
		if err != nil {
			return fmt.Errorf("failed to export servers: %w", err)
		}

		fmt.Printf("✓ Exported %d servers to %s\n", count, outputPath)
		return nil
	},
}
View Source
var ImportCmd = &cobra.Command{
	Use:    "import",
	Hidden: true,
	Short:  "Import servers into the registry database",
	Long:   "Imports MCP server entries from a JSON seed file or a registry /v0/servers endpoint into the local registry database.",
	RunE: func(cmd *cobra.Command, args []string) error {
		if strings.TrimSpace(importSource) == "" {
			return errors.New("--source is required (file path, HTTP URL, or /v0/servers endpoint)")
		}

		cfg := config.NewConfig()
		if importSkipValidation {
			cfg.EnableRegistryValidation = false
		}

		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()

		authz := auth.Authorizer{Authz: nil}

		db, err := database.NewPostgreSQL(ctx, cfg.DatabaseURL, authz)
		if err != nil {
			return fmt.Errorf("failed to connect to database: %w", err)
		}
		defer func() {
			if closeErr := db.Close(); closeErr != nil {
				log.Printf("Warning: failed to close database: %v", closeErr)
			}
		}()

		registryService := service.NewRegistryService(db, cfg, nil)

		httpClient := &http.Client{Timeout: importTimeout}
		headerMap := make(map[string]string)
		for _, h := range importHeaders {

			parts := strings.SplitN(h, "=", 2)
			if len(parts) != 2 {
				return fmt.Errorf("invalid --request-header, expected key=value: %s", h)
			}
			key := strings.TrimSpace(parts[0])
			value := strings.TrimSpace(parts[1])
			if key == "" {
				return fmt.Errorf("invalid --request-header, empty key: %s", h)
			}
			headerMap[key] = value
		}

		importerService := importer.NewService(registryService)
		importerService.SetHTTPClient(httpClient)
		importerService.SetRequestHeaders(headerMap)
		importerService.SetUpdateIfExists(importUpdate)
		importerService.SetGitHubToken(importGithubToken)
		importerService.SetReadmeSeedPath(importReadmeSeed)
		importerService.SetProgressCachePath(importProgressCache)
		if importGenerateEmbeddings {
			provider, err := embeddings.Factory(&cfg.Embeddings, httpClient)
			if err != nil {
				return fmt.Errorf("failed to initialize embeddings provider: %w", err)
			}
			importerService.SetEmbeddingProvider(provider)
			importerService.SetEmbeddingDimensions(cfg.Embeddings.Dimensions)
			importerService.SetGenerateEmbeddings(true)
		}

		if err := importerService.ImportFromPath(context.Background(), importSource, enrichServerData); err != nil {

			return err
		}
		return nil
	},
}
View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Show version information",
	Long:  `Displays the version of arctl.`,
	Run: func(cmd *cobra.Command, args []string) {
		output := versionOutput{
			ArctlVersion: version.Version,
			GitCommit:    version.GitCommit,
			BuildDate:    version.BuildDate,
		}

		serverVersion, err := apiClient.GetVersion()
		if err == nil {
			output.ServerVersion = serverVersion.Version
			output.ServerGitCommit = serverVersion.GitCommit
			output.ServerBuildDate = serverVersion.BuildTime

			if semver.IsValid(version.EnsureVPrefix(serverVersion.Version)) && semver.IsValid(version.EnsureVPrefix(version.Version)) {
				compare := semver.Compare(version.EnsureVPrefix(version.Version), version.EnsureVPrefix(serverVersion.Version))
				switch compare {
				case 1:
					output.UpdateRecommendation = "CLI version is newer than server version. Consider updating the server."
				case -1:
					output.UpdateRecommendation = "Server version is newer than CLI version. Consider updating the CLI."
				}
			}
		}

		if jsonOutput {
			jsonBytes, jsonErr := json.MarshalIndent(output, "", "  ")
			if jsonErr != nil {
				fmt.Printf("Error marshaling JSON: %v\n", jsonErr)
				return
			}
			fmt.Println(string(jsonBytes))
			return
		}

		fmt.Printf("arctl version %s\n", output.ArctlVersion)
		fmt.Printf("Git commit: %s\n", output.GitCommit)
		fmt.Printf("Build date: %s\n", output.BuildDate)

		if err != nil {
			fmt.Printf("Error getting server version: %v\n", err)
			return
		}

		fmt.Printf("Server version: %s\n", output.ServerVersion)
		fmt.Printf("Server git commit: %s\n", output.ServerGitCommit)
		fmt.Printf("Server build date: %s\n", output.ServerBuildDate)

		if output.UpdateRecommendation != "" {
			fmt.Println("\n-------------------------------")
			fmt.Println(output.UpdateRecommendation)
		}
	},
}

Functions

func SetAPIClient

func SetAPIClient(client *client.Client)

Types

This section is empty.

Directories

Path Synopsis
tui
gitutil
Package gitutil provides shared utilities for cloning Git repositories and copying their contents to a target directory.
Package gitutil provides shared utilities for cloning Git repositories and copying their contents to a target directory.
mcp

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL