@@ -202,48 +202,57 @@ func getToolsForAgent(ctx context.Context, a *latest.AgentConfig, parentDir stri
202202 } else {
203203 t = append (t , builtin .NewTodoTool ())
204204 }
205+
205206 case toolset .Type == "memory" :
206- if toolset .Path != "" {
207- var memoryPath string
208- if filepath .IsAbs (toolset .Path ) {
209- memoryPath = ""
210- } else {
211- if wd , err := os .Getwd (); err == nil {
212- memoryPath = wd
213- } else {
214- memoryPath = parentDir
215- }
216- }
207+ if toolset .Path == "" {
208+ continue
209+ }
217210
218- validatedMemoryPath , err := config .ValidatePathInDirectory (toolset .Path , memoryPath )
219- if err != nil {
220- return nil , fmt .Errorf ("invalid memory database path: %w" , err )
221- }
222- if err := os .MkdirAll (filepath .Dir (validatedMemoryPath ), 0o700 ); err != nil {
223- return nil , fmt .Errorf ("failed to create memory database directory: %w" , err )
211+ var memoryPath string
212+ if filepath .IsAbs (toolset .Path ) {
213+ memoryPath = ""
214+ } else {
215+ if wd , err := os .Getwd (); err == nil {
216+ memoryPath = wd
217+ } else {
218+ memoryPath = parentDir
224219 }
220+ }
225221
226- db , err := sqlite .NewMemoryDatabase (validatedMemoryPath )
227- if err != nil {
228- return nil , fmt .Errorf ("failed to create memory database: %w" , err )
229- }
222+ validatedMemoryPath , err := config .ValidatePathInDirectory (toolset .Path , memoryPath )
223+ if err != nil {
224+ return nil , fmt .Errorf ("invalid memory database path: %w" , err )
225+ }
226+ if err := os .MkdirAll (filepath .Dir (validatedMemoryPath ), 0o700 ); err != nil {
227+ return nil , fmt .Errorf ("failed to create memory database directory: %w" , err )
228+ }
230229
231- mm := memory .NewManager (db , model )
232- t = append (t , builtin .NewMemoryTool (mm ))
230+ db , err := sqlite .NewMemoryDatabase (validatedMemoryPath )
231+ if err != nil {
232+ return nil , fmt .Errorf ("failed to create memory database: %w" , err )
233233 }
234+
235+ mm := memory .NewManager (db , model )
236+ t = append (t , builtin .NewMemoryTool (mm ))
237+
234238 case toolset .Type == "think" :
235239 t = append (t , builtin .NewThinkTool ())
240+
236241 case toolset .Type == "shell" :
242+ // TODO: the tool's config can set env variables
237243 t = append (t , builtin .NewShellTool ())
238244
239245 case toolset .Type == "script" :
246+ // TODO: the tool's config can set env variables
240247 _ , _ = json .Marshal (a )
241248 if len (toolset .Shell ) == 0 {
242249 return nil , fmt .Errorf ("shell is required for script toolset" )
243250 }
244251
245252 t = append (t , builtin .NewScriptShellTool (toolset .Shell ))
253+
246254 case toolset .Type == "filesystem" :
255+ // TODO: the tool's config can set env variables
247256 wd , err := os .Getwd ()
248257 if err != nil {
249258 return nil , fmt .Errorf ("failed to get working directory: %w" , err )
@@ -277,26 +286,26 @@ func getToolsForAgent(ctx context.Context, a *latest.AgentConfig, parentDir stri
277286 // This improves shareability of agent configs.
278287 args = append (args , "--catalog=https://desktop.docker.com/mcp/catalog/v2/catalog.yaml" )
279288
289+ // TODO: the MCP Gateway doesn't know how to read secrets from env variables.
280290 envVars , err := environment .ExpandAll (ctx , environment .ToValues (toolset .Env ), env )
281291 if err != nil {
282292 return nil , fmt .Errorf ("failed to expand the tool's environment variables: %w" , err )
283293 }
284294
285295 // TODO(dga): If the server's docker image had the right annotations, we could run it directly with `docker run` or with the MCP gateway as a go library.
286- t = append (t , mcp .NewToolsetCommand ("docker" , args , envVars , toolset .Tools , cleanUp ))
296+ t = append (t , mcp .NewToolsetCommand ("docker" , args , append ( os . Environ (), envVars ... ) , toolset .Tools , cleanUp ))
287297
288298 case toolset .Type == "mcp" && toolset .Command != "" :
289299 envVars , err := environment .ExpandAll (ctx , environment .ToValues (toolset .Env ), env )
290300 if err != nil {
291301 return nil , fmt .Errorf ("failed to expand the tool's environment variables: %w" , err )
292302 }
293303
294- t = append (t , mcp .NewToolsetCommand (toolset .Command , toolset .Args , envVars , toolset .Tools , nil ))
304+ t = append (t , mcp .NewToolsetCommand (toolset .Command , toolset .Args , append ( os . Environ (), envVars ... ) , toolset .Tools , nil ))
295305
296306 case toolset .Type == "mcp" && toolset .Remote .URL != "" :
297- // TODO: the tool can have env variables too
298-
299307 // Expand env vars in headers.
308+ // TODO: the tool can have env variables that end up being referenced in headers.
300309 headers := map [string ]string {}
301310 for k , v := range toolset .Remote .Headers {
302311 expanded , err := environment .Expand (ctx , v , env )
0 commit comments