1- use clap:: Parser ;
1+ use std:: collections:: HashMap ;
2+
3+ use clap:: {
4+ Args ,
5+ Parser ,
6+ Subcommand ,
7+ ValueEnum ,
8+ } ;
29
310#[ derive( Debug , Clone , PartialEq , Eq , Default , Parser ) ]
411pub struct Chat {
@@ -10,6 +17,9 @@ pub struct Chat {
1017 /// prompt requests permissions to use a tool, unless --trust-all-tools is also used.
1118 #[ arg( long) ]
1219 pub no_interactive : bool ,
20+ /// Start a new conversation and overwrites any previous conversation from this directory.
21+ #[ arg( long) ]
22+ pub new : bool ,
1323 /// The first question to ask
1424 pub input : Option < String > ,
1525 /// Context profile to use
@@ -23,3 +33,127 @@ pub struct Chat {
2333 #[ arg( long, value_delimiter = ',' , value_name = "TOOL_NAMES" ) ]
2434 pub trust_tools : Option < Vec < String > > ,
2535}
36+
37+ #[ derive( Debug , Clone , PartialEq , Eq , Subcommand ) ]
38+ pub enum Mcp {
39+ /// Add or replace a configured server
40+ Add ( McpAdd ) ,
41+ /// Remove a server from the MCP configuration
42+ #[ command( alias = "rm" ) ]
43+ Remove ( McpRemove ) ,
44+ /// List configured servers
45+ List ( McpList ) ,
46+ /// Import a server configuration from another file
47+ Import ( McpImport ) ,
48+ /// Get the status of a configured server
49+ Status {
50+ #[ arg( long) ]
51+ name : String ,
52+ } ,
53+ }
54+
55+ #[ derive( Debug , Clone , PartialEq , Eq , Args ) ]
56+ pub struct McpAdd {
57+ /// Name for the server
58+ #[ arg( long) ]
59+ pub name : String ,
60+ /// The command used to launch the server
61+ #[ arg( long) ]
62+ pub command : String ,
63+ /// Where to add the server to. For profile scope, the name of the profile must specified with
64+ /// --profile.
65+ #[ arg( long, value_enum) ]
66+ pub scope : Option < Scope > ,
67+ /// Name of the profile to add the server config to. Not compatible with workspace scope or
68+ /// global scope.
69+ #[ arg( long) ]
70+ pub profile : Option < String > ,
71+ /// Environment variables to use when launching the server
72+ #[ arg( long, value_parser = parse_env_vars) ]
73+ pub env : Vec < HashMap < String , String > > ,
74+ /// Server launch timeout, in milliseconds
75+ #[ arg( long) ]
76+ pub timeout : Option < u64 > ,
77+ /// Overwrite an existing server with the same name
78+ #[ arg( long, default_value_t = false ) ]
79+ pub force : bool ,
80+ }
81+
82+ #[ derive( Debug , Clone , PartialEq , Eq , Args ) ]
83+ pub struct McpRemove {
84+ #[ arg( long) ]
85+ pub name : String ,
86+ #[ arg( long, value_enum) ]
87+ pub scope : Option < Scope > ,
88+ #[ arg( long) ]
89+ pub profile : Option < String > ,
90+ }
91+
92+ #[ derive( Debug , Clone , PartialEq , Eq , Args ) ]
93+ pub struct McpList {
94+ #[ arg( value_enum) ]
95+ pub scope : Option < Scope > ,
96+ #[ arg( long) ]
97+ pub profile : Option < String > ,
98+ }
99+
100+ #[ derive( Debug , Clone , PartialEq , Eq , Args ) ]
101+ pub struct McpImport {
102+ #[ arg( long) ]
103+ pub file : String ,
104+ #[ arg( value_enum) ]
105+ pub scope : Option < Scope > ,
106+ #[ arg( long) ]
107+ pub profile : Option < String > ,
108+ /// Overwrite an existing server with the same name
109+ #[ arg( long, default_value_t = false ) ]
110+ pub force : bool ,
111+ }
112+
113+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , ValueEnum ) ]
114+ pub enum Scope {
115+ Workspace ,
116+ Profile ,
117+ Global ,
118+ }
119+
120+ impl std:: fmt:: Display for Scope {
121+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
122+ match self {
123+ Scope :: Workspace => write ! ( f, "workspace" ) ,
124+ Scope :: Profile => write ! ( f, "profile" ) ,
125+ Scope :: Global => write ! ( f, "global" ) ,
126+ }
127+ }
128+ }
129+
130+ #[ derive( Debug ) ]
131+ struct EnvVarParseError ( String ) ;
132+
133+ impl std:: fmt:: Display for EnvVarParseError {
134+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
135+ write ! ( f, "Failed to parse environment variables: {}" , self . 0 )
136+ }
137+ }
138+
139+ impl std:: error:: Error for EnvVarParseError { }
140+
141+ fn parse_env_vars ( arg : & str ) -> Result < HashMap < String , String > , EnvVarParseError > {
142+ let mut vars = HashMap :: new ( ) ;
143+
144+ for pair in arg. split ( "," ) {
145+ match pair. split_once ( '=' ) {
146+ Some ( ( key, value) ) => {
147+ vars. insert ( key. trim ( ) . to_string ( ) , value. trim ( ) . to_string ( ) ) ;
148+ } ,
149+ None => {
150+ return Err ( EnvVarParseError ( format ! (
151+ "Invalid environment variable '{}'. Expected 'name=value'" ,
152+ pair
153+ ) ) ) ;
154+ } ,
155+ }
156+ }
157+
158+ Ok ( vars)
159+ }
0 commit comments