@@ -87,3 +87,83 @@ func (b *SettingsBuilder) WriteToFile(path string) error {
8787
8888 return nil
8989}
90+
91+ type MCPConfig struct {
92+ MCPServers map [string ]MCPServer `json:"mcpServers"`
93+ }
94+
95+ type MCPServer struct {
96+ Command string `json:"command"`
97+ Args []string `json:"args,omitempty"`
98+ Env map [string ]string `json:"env,omitempty"`
99+ }
100+
101+ type MCPConfigBuilder struct {
102+ cfg MCPConfig
103+ }
104+
105+ func NewMCPConfigBuilder () * MCPConfigBuilder {
106+ return & MCPConfigBuilder {
107+ cfg : MCPConfig {
108+ MCPServers : make (map [string ]MCPServer ),
109+ },
110+ }
111+ }
112+
113+ func (b * MCPConfigBuilder ) AddServer (name , command string ) * MCPServerBuilder {
114+ return & MCPServerBuilder {
115+ parent : b ,
116+ name : name ,
117+ server : MCPServer {Command : command , Env : map [string ]string {}},
118+ }
119+ }
120+
121+ func (b * MCPConfigBuilder ) Build () MCPConfig {
122+ return b .cfg
123+ }
124+
125+ func (b * MCPConfigBuilder ) ToJSON () ([]byte , error ) {
126+ return json .MarshalIndent (b .cfg , "" , " " )
127+ }
128+
129+ func (b * MCPConfigBuilder ) WriteToFile (path string ) error {
130+ // Create directory if needed
131+ dir := filepath .Dir (path )
132+ if err := os .MkdirAll (dir , 0755 ); err != nil {
133+ return fmt .Errorf ("failed to create directory: %w" , err )
134+ }
135+
136+ // Marshal with indentation
137+ data , err := json .MarshalIndent (b .cfg , "" , " " )
138+ if err != nil {
139+ return fmt .Errorf ("failed to marshal settings: %w" , err )
140+ }
141+
142+ // Write to file
143+ if err := os .WriteFile (path , data , 0644 ); err != nil {
144+ return fmt .Errorf ("failed to write file: %w" , err )
145+ }
146+
147+ return nil
148+ }
149+
150+ type MCPServerBuilder struct {
151+ parent * MCPConfigBuilder
152+ name string
153+ server MCPServer
154+ }
155+
156+ func (sb * MCPServerBuilder ) Args (args ... string ) * MCPServerBuilder {
157+ sb .server .Args = args
158+ return sb
159+ }
160+
161+ func (sb * MCPServerBuilder ) Env (key , value string ) * MCPServerBuilder {
162+ sb .server .Env [key ] = value
163+ return sb
164+ }
165+
166+ func (sb * MCPServerBuilder ) Done () * MCPConfigBuilder {
167+ sb .parent .cfg .MCPServers [sb .name ] = sb .server
168+ return sb .parent
169+ }
0 commit comments