11package commandline
22
33import (
4+ "errors"
45 "flag"
56 "fmt"
67 "os"
78 "strconv"
9+ "strings"
810
911 "github.com/magicdrive/ark/internal/common"
12+ "github.com/magicdrive/ark/internal/model"
1013)
1114
1215// ServeOption defines options for launching the MCP server
1316type ServeOption struct {
14- RootDir string
15- Port string
16- GeneralOption * Option
17+ ThisVersion string
18+ RootDir string
19+ McpServerType model.McpSreverType
20+ McpServerTypeValue string
21+ HttpPort string
22+ GeneralOption * Option
1723}
1824
19- func ServerOptParse (args []string ) (int , * ServeOption , error ) {
25+ func ServerOptParse (version string , args []string ) (int , * ServeOption , error ) {
2026
2127 optLength := len (args )
2228
@@ -28,9 +34,13 @@ func ServerOptParse(args []string) (int, *ServeOption, error) {
2834 rootDirOpt := fs .String ("root" , currentDir , "Specify ark mcp server serv directory." )
2935 fs .StringVar (rootDirOpt , "r" , currentDir , "Specify ark mcp server serv directory." )
3036
31- // --port
32- portOpt := fs .Int ("port" , 8522 , "Specify ark mcp server port." )
33- fs .IntVar (portOpt , "p" , 8522 , "Specify ark mcp server port." )
37+ // --type
38+ mcpServerTypeOpt := fs .String ("type" , "stdio" , "Specify ark mcp server serv type." )
39+ fs .StringVar (mcpServerTypeOpt , "t" , "stdio" , "Specify ark mcp server serv type." )
40+
41+ // --http-port
42+ httpPortOpt := fs .Int ("http-port" , 8522 , "Specify ark mcp server port." )
43+ fs .IntVar (httpPortOpt , "p" , 8522 , "Specify ark mcp server port." )
3444
3545 // --scan-buffer
3646 scanBufferValueOpt := fs .String ("scan-buffer" , "10M" , "Specify the line scan buffer size." )
@@ -120,17 +130,35 @@ func ServerOptParse(args []string) (int, *ServeOption, error) {
120130 FlagSet : fs ,
121131 }
122132
123- if err := generalOpt .Normalize (); err != nil {
124- return optLength , nil , err
133+ result := & ServeOption {
134+ ThisVersion : version ,
135+ RootDir : * rootDirOpt ,
136+ McpServerTypeValue : * mcpServerTypeOpt ,
137+ HttpPort : strconv .Itoa (* httpPortOpt ),
138+ GeneralOption : generalOpt ,
125139 }
126140
127- result := & ServeOption {
128- RootDir : * rootDirOpt ,
129- Port : strconv .Itoa (* portOpt ),
130- GeneralOption : generalOpt ,
141+ if err := common .JoinErrors (result .Normalize (), generalOpt .Normalize ()); err != nil {
142+ return optLength , nil , err
131143 }
132144
133145 OverRideHelp (fs )
134146
135147 return optLength , result , nil
136148}
149+
150+ func (cr * ServeOption ) Normalize () error {
151+
152+ var errorMessages = []string {}
153+
154+ // --type
155+ if err := cr .McpServerType .Set (cr .McpServerTypeValue ); err != nil {
156+ errorMessages = append (errorMessages , fmt .Sprintf ("--type %s" , err .Error ()))
157+ }
158+
159+ if len (errorMessages ) == 0 {
160+ return nil
161+ } else {
162+ return errors .New (strings .Join (errorMessages , "\n " ))
163+ }
164+ }
0 commit comments