Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,18 @@ just test

## Uninstall

Sign out first, then remove the binary with the counterpart of the install
method:
One command removes the agent setup, the Claude Code plugin, the sign-in, the
config and cache folders and the binary. It lists everything and asks first:

```sh
frbit auth logout # repeat with --profile per profile
rm "$(command -v frbit)" # install script or release archive
brew uninstall frbit # Homebrew
npm uninstall --global @fortrabbit/cli # npm
frbit uninstall
```

`frbit mcp remove` and `frbit skills remove` undo `frbit setup agent`. The
[uninstall guide](https://docs.fortrabbit.com/platform/automation/cli#uninstall)
covers the config and cache files that stay behind.
A Homebrew or npm install is removed through `brew` or `npm`. On Windows the
running binary cannot delete itself; the command names the file to delete.
Other profiles than the selected one: `frbit auth logout --profile <name>`
first. To keep the CLI and only undo `frbit setup agent`, run
`frbit setup agent --remove`.

## Development

Expand Down
16 changes: 13 additions & 3 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ printf '%s' "$FRBIT_TOKEN" | frbit auth login --token-stdin

## Uninstall

Sign out while the binary is still in place. `frbit auth logout` revokes a browser sign-in and removes the stored credential for the selected profile; repeat it with `--profile` for every profile in use. An agent setup is undone with `frbit mcp remove` and `frbit skills remove`.
`frbit uninstall` removes everything fortrabbit put on the machine for coding agents: the MCP server and the skill in Claude Code and Codex, the Claude Code plugin, the sign-in of the selected profile, the config and cache folders, and the binary. It lists everything and asks once; `--yes` skips the question. A Homebrew or npm install is removed with `brew uninstall frbit` or `npm uninstall --global @fortrabbit/cli`. On Windows, delete the binary yourself afterwards: a running executable cannot delete itself. Repeat `frbit auth logout --profile <name>` for other profiles before.

Then remove the CLI with the counterpart of the install method:
By hand, with the counterpart of the install method:

```sh
rm "$(command -v frbit)" # install script or release archive
Expand Down Expand Up @@ -366,6 +366,15 @@ the skills, including project-scoped skills or GitHub Copilot skills, use the
When Claude Code has the fortrabbit plugin enabled, `setup agent` and
`mcp install` skip Claude Code: the plugin brings its own skill and MCP server.

Undo the setup with `--remove`. It lists the MCP entries, skills and the CLI
sign-in it will remove and asks before it does; `--yes` skips the question. The
binary and the plugin stay; `frbit uninstall` removes them as well:

```sh
frbit setup agent --remove
frbit setup agent --remove --agent codex --yes
```

## MCP server

Manage the MCP registration independently when you do not want to change the
Expand Down Expand Up @@ -475,7 +484,8 @@ frbit --profile work auth logout
| `frbit people list` / `get <id>` | List or get people. `list` accepts repeatable `--id`. |
| `frbit teams list` / `get <id>` / `delete <id>` | List, get, or delete teams. |
| `frbit payment-methods list` / `get <id>` / `delete <id>` | List, get, or delete payment methods. |
| `frbit setup agent` | Register the remote MCP server and install skills for detected agents. Accepts repeatable `--agent`. |
| `frbit uninstall` | Remove the agent setup, the Claude Code plugin, the sign-in, the config and cache folders and the binary after confirmation. Accepts `--yes`. |
| `frbit setup agent` | Register the remote MCP server and install skills for detected agents. Accepts repeatable `--agent`; `--remove` undoes it and signs out. |
| `frbit mcp install` | Register or update the named fortrabbit MCP entry. Accepts repeatable `--agent`. |
| `frbit mcp list` | List the fortrabbit MCP status, URL, and agent configuration paths. |
| `frbit mcp remove` | List and remove the named fortrabbit MCP entry after confirmation. Accepts `--yes`. |
Expand Down
36 changes: 30 additions & 6 deletions internal/agentmcp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,22 @@ func (s *Service) WithoutClaudePlugin(ctx context.Context, agents []agent.Agent)
}), true
}

// A Claude Code without plugin support, or output that does not parse, counts as no plugin.
func (s *Service) claudePluginEnabled(ctx context.Context) bool {
_, enabled := s.claudePlugin(ctx)
return enabled
}

// ClaudePluginID returns the installed fortrabbit plugin as name@marketplace, enabled or not.
func (s *Service) ClaudePluginID(ctx context.Context) string {
id, _ := s.claudePlugin(ctx)
return id
}

// A Claude Code without plugin support, or output that does not parse, counts as no plugin.
func (s *Service) claudePlugin(ctx context.Context) (string, bool) {
output, err := s.runner.Run(ctx, "claude", "plugin", "list", "--json")
if err != nil {
return false
return "", false
}
if start := strings.Index(output, "["); start > 0 {
output = output[start:]
Expand All @@ -141,15 +152,28 @@ func (s *Service) claudePluginEnabled(ctx context.Context) bool {
Enabled bool `json:"enabled"`
}
if json.Unmarshal([]byte(output), &plugins) != nil {
return false
return "", false
}
for _, plugin := range plugins {
name, _, _ := strings.Cut(plugin.ID, "@")
if plugin.Enabled && name == ClaudePluginName {
return true
if name == ClaudePluginName {
return plugin.ID, plugin.Enabled
}
}
return false
return "", false
}

// RemoveClaudePlugin uninstalls the plugin; only the fortrabbit marketplace goes with it.
func (s *Service) RemoveClaudePlugin(ctx context.Context, pluginID string) error {
if output, err := s.runner.Run(ctx, "claude", "plugin", "uninstall", pluginID); err != nil {
return fmt.Errorf("uninstall the Claude Code plugin %s: %w: %s", pluginID, err, strings.TrimSpace(output))
}
if _, marketplace, _ := strings.Cut(pluginID, "@"); marketplace == ClaudePluginName {
if output, err := s.runner.Run(ctx, "claude", "plugin", "marketplace", "remove", marketplace); err != nil {
return fmt.Errorf("remove the Claude Code marketplace %s: %w: %s", marketplace, err, strings.TrimSpace(output))
}
}
return nil
}

func (s *Service) Inspect(ctx context.Context, agents []agent.Agent) ([]Registration, error) {
Expand Down
29 changes: 29 additions & 0 deletions internal/agentmcp/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,32 @@ func TestPreflightReportsMissingAgentCLI(t *testing.T) {
t.Fatalf("error = %v", err)
}
}

func TestRemoveClaudePlugin(t *testing.T) {
for id, want := range map[string][]string{
"fortrabbit@fortrabbit": {"claude plugin uninstall fortrabbit@fortrabbit", "claude plugin marketplace remove fortrabbit"},
"fortrabbit@claude-plugins-official": {"claude plugin uninstall fortrabbit@claude-plugins-official"},
} {
runner := &fakeRunner{}
if err := testService(runner).RemoveClaudePlugin(context.Background(), id); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(runner.calls, want) {
t.Fatalf("%s: calls = %#v, want %#v", id, runner.calls, want)
}
}
}

func TestClaudePluginIDKeepsTheMarketplace(t *testing.T) {
runner := &fakeRunner{responses: map[string]fakeResponse{"claude plugin list --json": {output: `[{"id":"fortrabbit@claude-plugins-official","enabled":true}]`}}}
if id := testService(runner).ClaudePluginID(context.Background()); id != "fortrabbit@claude-plugins-official" {
t.Fatalf("id = %q", id)
}
}

func TestClaudePluginIDFindsADisabledPlugin(t *testing.T) {
runner := &fakeRunner{responses: map[string]fakeResponse{"claude plugin list --json": {output: `[{"id":"fortrabbit@fortrabbit","enabled":false}]`}}}
if id := testService(runner).ClaudePluginID(context.Background()); id != "fortrabbit@fortrabbit" {
t.Fatalf("id = %q", id)
}
}
5 changes: 5 additions & 0 deletions internal/cmd/auth/logout/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func NewCmdLogout(factory *app.Factory, runF func(*Options) error) *cobra.Comman
}
}

// Run signs the selected profile out the same way frbit auth logout does.
func Run(factory *app.Factory, command *cobra.Command) error {
return run(&Options{Factory: factory, Command: command})
}

func run(options *Options) error {
command := options.Command
profile, err := cmdutil.Profile(command)
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func NewCmdRoot(factory *app.Factory) *cobra.Command {
apps.NewCmdApps(factory),
mcp.NewCmdMCP(factory, nil),
setup.NewCmdSetup(factory, nil, nil),
setup.NewCmdUninstall(factory),
skills.NewCmdSkills(factory, nil),
environments.NewCmdEnvironments(factory),
resource.NewCmdGroup(factory, deploymentSpec()),
Expand Down
165 changes: 164 additions & 1 deletion internal/cmd/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@ package setup

import (
"context"
"errors"
"fmt"
"io"

"github.com/fortrabbit/frbit-cli/internal/agent"
"github.com/fortrabbit/frbit-cli/internal/agentmcp"
"github.com/fortrabbit/frbit-cli/internal/agentskills"
"github.com/fortrabbit/frbit-cli/internal/app"
"github.com/fortrabbit/frbit-cli/internal/cmd/auth/logout"
"github.com/fortrabbit/frbit-cli/internal/cmdutil"
"github.com/fortrabbit/frbit-cli/internal/credentials"
"github.com/spf13/cobra"
)

type mcpService interface {
ResolveAgents([]agent.Agent) ([]agent.Agent, error)
Preflight([]agent.Agent) error
Install(context.Context, []agent.Agent) ([]agentmcp.Result, error)
Inspect(context.Context, []agent.Agent) ([]agentmcp.Registration, error)
Remove(context.Context, []agent.Agent) ([]agentmcp.Result, error)
WithoutClaudePlugin(context.Context, []agent.Agent) ([]agent.Agent, bool)
ClaudePluginID(context.Context) string
RemoveClaudePlugin(context.Context, string) error
}

type skillsService interface {
InstallTargets(bool, []agentskills.Agent) ([]agentskills.Target, error)
LatestRelease(context.Context) (agentskills.Release, error)
InstallRelease(context.Context, agentskills.Release, []agentskills.Target) ([]agentskills.Installation, error)
Removals(bool, []agentskills.Agent) ([]agentskills.Removal, error)
Remove([]agentskills.Removal) error
}

func NewCmdSetup(factory *app.Factory, mcp mcpService, skills skillsService) *cobra.Command {
Expand All @@ -50,10 +59,14 @@ func NewCmdSetup(factory *app.Factory, mcp mcpService, skills skillsService) *co

func newCmdAgent(factory *app.Factory, mcp mcpService, skills skillsService) *cobra.Command {
var agentValues []string
var remove, yes bool
command := &cobra.Command{
Use: "agent",
Short: "Register MCP and install skills for coding agents",
Args: cobra.NoArgs,
Long: `Register the fortrabbit MCP server and install the fortrabbit skill for Claude Code and Codex.

With --remove, undo both and sign the CLI out. The frbit binary stays in place.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
requested, err := agentmcp.ParseAgents(agentValues)
if err != nil {
Expand All @@ -63,6 +76,9 @@ func newCmdAgent(factory *app.Factory, mcp mcpService, skills skillsService) *co
if err != nil {
return err
}
if remove {
return removeAgentSetup(cmd, factory, mcp, skills, agents, yes)
}
// Validate every native agent CLI before writing either integration.
if err := mcp.Preflight(agents); err != nil {
return err
Expand Down Expand Up @@ -103,6 +119,8 @@ func newCmdAgent(factory *app.Factory, mcp mcpService, skills skillsService) *co
},
}
command.Flags().StringArrayVar(&agentValues, "agent", nil, "Target agent (claude-code or codex); repeat to target more than one")
command.Flags().BoolVar(&remove, "remove", false, "Remove the MCP server and the skill, and sign the CLI out")
command.Flags().BoolVarP(&yes, "yes", "y", false, "Remove without prompting for confirmation")
return command
}

Expand Down Expand Up @@ -160,3 +178,148 @@ func printSummary(
}
return cmdutil.PrintOAuthHints(writer, agents)
}

const (
claudePluginRemoveNotice = "Claude Code: the fortrabbit plugin brings the skill and the MCP server; frbit uninstall removes it too."
disconnectHint = "Revoke the MCP grants in the dashboard: https://dash.fortrabbit.com/you/ai-agents"
uninstallHint = "Remove the frbit CLI as well: frbit uninstall"
)

// removalPlan is what frbit setup agent put on this machine, found before anything is removed.
type removalPlan struct {
registrations []agentmcp.Registration
registered []agent.Agent
removals []agentskills.Removal
profile string
signedIn bool
}

func planRemoval(cmd *cobra.Command, factory *app.Factory, mcp mcpService, skills skillsService, agents []agent.Agent) (removalPlan, error) {
plan := removalPlan{}
// An empty agent list means all agents to the skills service, so skip both lookups.
if len(agents) > 0 {
var err error
if plan.registrations, err = mcp.Inspect(cmd.Context(), agents); err != nil {
return plan, err
}
if plan.removals, err = skills.Removals(false, agents); err != nil {
return plan, err
}
}
for _, registration := range plan.registrations {
if registration.Installed {
plan.registered = append(plan.registered, registration.Agent)
}
}
profile, err := cmdutil.Profile(cmd)
if err != nil {
return plan, err
}
plan.profile = profile
_, credentialErr := factory.CredentialStore.Get(profile)
if credentialErr != nil && !errors.Is(credentialErr, credentials.ErrNotFound) {
return plan, credentialErr
}
plan.signedIn = credentialErr == nil
return plan, nil
}

func (p removalPlan) empty() bool {
return len(p.registered) == 0 && len(p.removals) == 0 && !p.signedIn
}

func (p removalPlan) print(writer io.Writer) error {
for _, registration := range p.registrations {
if !registration.Installed {
continue
}
if _, err := fmt.Fprintf(writer, " %-14s MCP server in %s\n", registration.Agent.Label()+":", registration.ConfigPath); err != nil {
return err
}
}
for _, removal := range p.removals {
if _, err := fmt.Fprintf(writer, " %-14s skill at %s\n", removal.Agent.Label()+":", removal.Path); err != nil {
return err
}
}
if p.signedIn {
if _, err := fmt.Fprintf(writer, " %-14s sign-in of profile %q\n", "frbit CLI:", p.profile); err != nil {
return err
}
}
return nil
}

func (p removalPlan) execute(cmd *cobra.Command, factory *app.Factory, mcp mcpService, skills skillsService) error {
writer := cmd.OutOrStdout()
if len(p.registered) > 0 {
results, err := mcp.Remove(cmd.Context(), p.registered)
if err != nil {
return err
}
for _, result := range results {
if _, err := fmt.Fprintf(writer, "Removed the MCP server from %s\n", result.Agent.Label()); err != nil {
return err
}
}
}
if err := skills.Remove(p.removals); err != nil {
return err
}
for _, removal := range p.removals {
if _, err := fmt.Fprintf(writer, "Removed %s\n", removal.Path); err != nil {
return err
}
}
if p.signedIn {
return logout.Run(factory, cmd)
}
return nil
}

func confirmRemoval(factory *app.Factory, writer io.Writer, yes bool) (bool, error) {
if yes {
return true, nil
}
confirmed, err := cmdutil.Confirm(factory.IOStreams.In, writer, "Continue? [y/N] ")
if err != nil || confirmed {
return confirmed, err
}
_, err = fmt.Fprintln(writer, "Aborted.")
return false, err
}

func removeAgentSetup(cmd *cobra.Command, factory *app.Factory, mcp mcpService, skills skillsService, agents []agent.Agent, yes bool) error {
writer := cmd.OutOrStdout()
if err := mcp.Preflight(agents); err != nil {
return err
}
agents, pluginEnabled := mcp.WithoutClaudePlugin(cmd.Context(), agents)
if pluginEnabled {
if _, err := fmt.Fprintln(writer, claudePluginRemoveNotice); err != nil {
return err
}
}
plan, err := planRemoval(cmd, factory, mcp, skills, agents)
if err != nil {
return err
}
if plan.empty() {
_, err := fmt.Fprintln(writer, "Nothing to remove: no fortrabbit MCP server, skill or sign-in found.")
return err
}
if _, err := fmt.Fprintln(writer, "This removes:"); err != nil {
return err
}
if err := plan.print(writer); err != nil {
return err
}
if confirmed, err := confirmRemoval(factory, writer, yes); err != nil || !confirmed {
return err
}
if err := plan.execute(cmd, factory, mcp, skills); err != nil {
return err
}
_, err = fmt.Fprintf(writer, "Agent setup removed.\n\n%s\n%s\n", disconnectHint, uninstallHint)
return err
}
Loading