7
7
8
8
"github.com/stacklok/toolhive/cmd/thv/app/ui"
9
9
"github.com/stacklok/toolhive/pkg/client"
10
+ "github.com/stacklok/toolhive/pkg/config"
10
11
)
11
12
12
13
var clientCmd = & cobra.Command {
@@ -29,11 +30,51 @@ var clientSetupCmd = &cobra.Command{
29
30
RunE : clientSetupCmdFunc ,
30
31
}
31
32
33
+ var clientRegisterCmd = & cobra.Command {
34
+ Use : "register [client]" ,
35
+ Short : "Register a client for MCP server configuration" ,
36
+ Long : `Register a client for MCP server configuration.
37
+ Valid clients are:
38
+ - claude-code: Claude Code CLI
39
+ - cline: Cline extension for VS Code
40
+ - cursor: Cursor editor
41
+ - roo-code: Roo Code extension for VS Code
42
+ - vscode: Visual Studio Code
43
+ - vscode-insider: Visual Studio Code Insiders edition` ,
44
+ Args : cobra .ExactArgs (1 ),
45
+ RunE : clientRegisterCmdFunc ,
46
+ }
47
+
48
+ var clientRemoveCmd = & cobra.Command {
49
+ Use : "remove [client]" ,
50
+ Short : "Remove a client from MCP server configuration" ,
51
+ Long : `Remove a client from MCP server configuration.
52
+ Valid clients are:
53
+ - claude-code: Claude Code CLI
54
+ - cline: Cline extension for VS Code
55
+ - cursor: Cursor editor
56
+ - roo-code: Roo Code extension for VS Code
57
+ - vscode: Visual Studio Code
58
+ - vscode-insider: Visual Studio Code Insiders edition` ,
59
+ Args : cobra .ExactArgs (1 ),
60
+ RunE : clientRemoveCmdFunc ,
61
+ }
62
+
63
+ var clientListRegisteredCmd = & cobra.Command {
64
+ Use : "list-registered" ,
65
+ Short : "List all registered MCP clients" ,
66
+ Long : "List all clients that are registered for MCP server configuration." ,
67
+ RunE : listRegisteredClientsCmdFunc ,
68
+ }
69
+
32
70
func init () {
33
71
rootCmd .AddCommand (clientCmd )
34
72
35
73
clientCmd .AddCommand (clientStatusCmd )
36
74
clientCmd .AddCommand (clientSetupCmd )
75
+ clientCmd .AddCommand (clientRegisterCmd )
76
+ clientCmd .AddCommand (clientRemoveCmd )
77
+ clientCmd .AddCommand (clientListRegisteredCmd )
37
78
}
38
79
39
80
func clientStatusCmdFunc (_ * cobra.Command , _ []string ) error {
@@ -101,3 +142,76 @@ func registerSelectedClients(cmd *cobra.Command, clientsToRegister []client.MCPC
101
142
102
143
return nil
103
144
}
145
+
146
+ func clientRegisterCmdFunc (cmd * cobra.Command , args []string ) error {
147
+ clientType := args [0 ]
148
+
149
+ // Validate the client type
150
+ switch clientType {
151
+ case "roo-code" , "cline" , "cursor" , "claude-code" , "vscode-insider" , "vscode" :
152
+ // Valid client type
153
+ default :
154
+ return fmt .Errorf (
155
+ "invalid client type: %s (valid types: roo-code, cline, cursor, claude-code, vscode, vscode-insider)" ,
156
+ clientType )
157
+ }
158
+
159
+ ctx := cmd .Context ()
160
+
161
+ manager , err := client .NewManager (ctx )
162
+ if err != nil {
163
+ return fmt .Errorf ("failed to create client manager: %w" , err )
164
+ }
165
+
166
+ err = manager .RegisterClients (ctx , []client.Client {
167
+ {Name : client .MCPClient (clientType )},
168
+ })
169
+ if err != nil {
170
+ return fmt .Errorf ("failed to register client %s: %w" , clientType , err )
171
+ }
172
+
173
+ return nil
174
+ }
175
+
176
+ func clientRemoveCmdFunc (cmd * cobra.Command , args []string ) error {
177
+ clientType := args [0 ]
178
+
179
+ // Validate the client type
180
+ switch clientType {
181
+ case "roo-code" , "cline" , "cursor" , "claude-code" , "vscode-insider" , "vscode" :
182
+ // Valid client type
183
+ default :
184
+ return fmt .Errorf (
185
+ "invalid client type: %s (valid types: roo-code, cline, cursor, claude-code, vscode, vscode-insider)" ,
186
+ clientType )
187
+ }
188
+
189
+ ctx := cmd .Context ()
190
+
191
+ manager , err := client .NewManager (ctx )
192
+ if err != nil {
193
+ return fmt .Errorf ("failed to create client manager: %w" , err )
194
+ }
195
+
196
+ err = manager .UnregisterClients (ctx , []client.Client {
197
+ {Name : client .MCPClient (clientType )},
198
+ })
199
+ if err != nil {
200
+ return fmt .Errorf ("failed to remove client %s: %w" , clientType , err )
201
+ }
202
+
203
+ return nil
204
+ }
205
+
206
+ func listRegisteredClientsCmdFunc (_ * cobra.Command , _ []string ) error {
207
+ cfg := config .GetConfig ()
208
+ if len (cfg .Clients .RegisteredClients ) == 0 {
209
+ fmt .Println ("No clients are currently registered." )
210
+ return nil
211
+ }
212
+ fmt .Println ("Registered clients:" )
213
+ for _ , clientName := range cfg .Clients .RegisteredClients {
214
+ fmt .Printf (" - %s\n " , clientName )
215
+ }
216
+ return nil
217
+ }
0 commit comments