Skip to content

feat: add optional working_dir to MCP and LSP toolset configs#2460

Open
simonferquel-clanker wants to merge 3 commits intodocker:mainfrom
simonferquel-clanker:feat/toolset-working-dir
Open

feat: add optional working_dir to MCP and LSP toolset configs#2460
simonferquel-clanker wants to merge 3 commits intodocker:mainfrom
simonferquel-clanker:feat/toolset-working-dir

Conversation

@simonferquel-clanker
Copy link
Copy Markdown
Contributor

Summary

Adds an optional working_dir field to MCP and LSP toolset configurations, allowing these processes to be launched from a directory other than the agent's working directory.

Closes #2459

Changes

  • pkg/config/latest/types.go — New WorkingDir field on Toolset struct
  • pkg/config/latest/validate.go — Validation: working_dir only valid for types mcp and lsp
  • pkg/config/mcps.go — Propagate working_dir from top-level mcps: definitions to referencing agent toolsets (existing toolset value takes precedence)
  • pkg/teamloader/registry.goresolveToolsetWorkingDir helper; createMCPTool and createLSPTool resolve and pass the working directory to the process
  • agent-schema.jsonworking_dir added to Toolset and MCPToolset schema definitions
  • Tests — validate_test.go, mcps_test.go, registry_test.go coverage for the new field
  • examples/toolset-working-dir.yaml — New example demonstrating the feature

Behaviour

  • working_dir is optional; omitting it keeps existing behaviour (process starts from agent's working directory)
  • Relative paths are resolved relative to the agent's working directory
  • Absolute paths are used as-is
  • When using the top-level mcps: section, working_dir is inherited by referencing toolsets; a toolset-level value overrides the definition

- Add WorkingDir field to Toolset struct (pkg/config/latest/types.go)
- Validate that working_dir is only used with type 'mcp' or 'lsp'
- Resolve working_dir relative to agent's working directory at process start
- Propagate working_dir from top-level mcps: definitions to agent toolsets
- Add resolveToolsetWorkingDir helper in registry.go
- Add tests: validate_test.go, mcps_test.go, registry_test.go
- Add example: examples/toolset-working-dir.yaml
- Update agent-schema.json for Toolset and MCPToolset

Closes docker#2459

Assisted-By: docker-agent
@simonferquel-clanker simonferquel-clanker requested a review from a team as a code owner April 17, 2026 14:03
B1: pass resolved CWD to NewGatewayToolset; gateway-based MCPs now
honour working_dir. Remote MCP toolsets reject working_dir at
validation time (no local subprocess).

B2: call path.ExpandPath in resolveToolsetWorkingDir so ~ and
${VAR}/$VAR are expanded before path operations. Use filepath.Abs
when joining a relative path with the agent dir (fixes file://./backend
LSP root URI).

S1: add checkDirExists helper; createMCPTool and createLSPTool now
surface a clear error if working_dir does not exist at tool-creation
time.

S2: doc comment on resolveToolsetWorkingDir explains no-containment-
check posture (working_dir is treated like command/args).

S3: filepath.Abs on relative+non-empty-agentDir path ensures LSP
rootURI is always absolute.

S4: validation rejects working_dir on remote MCP toolsets.

S5: comment in applyMCPDefaults explains empty-string inheritance
semantics.

S6: doc comment covers the empty-agent-dir+relative edge case.

Nits: example model → gpt-5-mini; test name → 'bare relative dir';
schema descriptions aligned; import groups tidied; hard-coded
non-existent path in test → t.TempDir()+'/missing'.

N5: integration tests added:
- TestCreateMCPTool_WorkingDir_ReachesSubprocess
- TestCreateMCPTool_RelativeWorkingDir_ResolvedAgainstAgentDir
- TestCreateMCPTool_NonexistentWorkingDir_ReturnsError
- TestCreateLSPTool_WorkingDir_ReachesHandler

Also add WorkingDir() accessors on *mcp.Toolset and *builtin.LSPTool
to support the above integration tests.

Assisted-By: docker-agent
…epathJoin lint rule

Assisted-By: docker-agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add optional working_dir to MCP and LSP toolset configs

1 participant