-
Notifications
You must be signed in to change notification settings - Fork 340
feat: add optional working_dir to MCP and LSP toolset configs #2460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
simonferquel
merged 5 commits into
docker:main
from
simonferquel-clanker:feat/toolset-working-dir
Apr 20, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3ec5627
feat: add optional working_dir to MCP and LSP toolset configs
simonferquel-clanker 67baf03
fix: address reviewer feedback on working_dir feature
simonferquel-clanker 293e359
fix: use filepath.Join with separate segments to satisfy gocritic fil…
simonferquel-clanker d610013
fix: return explicit error when ref-based MCP resolves to remote serv…
simonferquel-clanker c6bc325
docs: document working_dir field for MCP and LSP toolsets
simonferquel-clanker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env docker agent run | ||
|
|
||
| # Example: using working_dir for MCP and LSP toolsets | ||
| # | ||
| # Some language servers and MCP tools must be started from a specific directory. | ||
| # For example, gopls must be started from the Go module root. Use `working_dir` | ||
| # to configure the launch directory for any MCP or LSP toolset. | ||
| # | ||
| # `working_dir` is: | ||
| # - Optional (defaults to the agent's working directory when omitted) | ||
| # - Resolved relative to the agent's working directory if it is a relative path | ||
|
|
||
| agents: | ||
| root: | ||
| model: openai/gpt-5-mini | ||
| description: Example agent demonstrating working_dir for MCP and LSP toolsets | ||
| instruction: | | ||
| You are a helpful coding assistant with access to language server and MCP tools | ||
| launched from their respective project directories. | ||
| toolsets: | ||
| # LSP server started from a subdirectory (e.g. a Go module in ./backend) | ||
| - type: lsp | ||
| command: gopls | ||
| working_dir: ./backend | ||
|
|
||
| # MCP server started from a specific tools directory | ||
| - type: mcp | ||
| command: my-mcp-server | ||
| working_dir: ./tools/mcp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| version: "8" | ||
| models: | ||
| model: | ||
| provider: openai | ||
| model: gpt-4o | ||
|
|
||
| mcps: | ||
| custom_mcp_with_dir: | ||
| command: my-mcp-server | ||
| working_dir: ./tools/mcp | ||
|
|
||
| agents: | ||
| root: | ||
| model: model | ||
| toolsets: | ||
| - type: mcp | ||
| ref: custom_mcp_with_dir | ||
| override: | ||
| model: model | ||
| toolsets: | ||
| - type: mcp | ||
| ref: custom_mcp_with_dir | ||
| working_dir: ./override/path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package gateway | ||
|
|
||
| // OverrideCatalogForTesting replaces the catalog loader with a fixed function | ||
| // that returns the given catalog. It should only be called from TestMain or | ||
| // equivalent test-setup code, before any call to ServerSpec. | ||
| func OverrideCatalogForTesting(catalog Catalog) { | ||
| catalogOnce = func() (Catalog, error) { | ||
| return catalog, nil | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package teamloader | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/docker/docker-agent/pkg/gateway" | ||
| ) | ||
|
|
||
| // TestMain seeds a fake MCP catalog so that teamloader tests that invoke | ||
| // createMCPTool with a ref can run without a live network call. | ||
| func TestMain(m *testing.M) { | ||
| gateway.OverrideCatalogForTesting(gateway.Catalog{ | ||
| // A local (subprocess-based) server entry. | ||
| "local-server": { | ||
| Type: "server", | ||
| }, | ||
| // A remote (no subprocess) server entry — used to test that | ||
| // working_dir is rejected at runtime for ref-based remote MCPs. | ||
| "remote-server": { | ||
| Type: "remote", | ||
| Remote: gateway.Remote{ | ||
| URL: "https://mcp.example.com/sse", | ||
| TransportType: "sse", | ||
| }, | ||
| }, | ||
| }) | ||
| os.Exit(m.Run()) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MEDIUM: Validation gap —
working_dirnot rejected forref:-based MCPs that may resolve to remote at runtimeThis check only blocks
working_dirwhenRemote.URLis set explicitly:ref:-based MCPs (e.g.ref: docker:context7) are not covered. TheirserverSpec.Typeis only known at runtime (via the MCP Catalog API), so if the catalog entry resolves to a remote server,working_diris silently dropped with no user-visible error.The companion misleading comment in
registry.go("The remote branch never reaches here because working_dir is rejected by validation for toolsets with a remote.url") reinforces this false assumption.Suggested fix: At minimum, update the comment in registry.go to accurately describe that only explicit-
remote.urltoolsets are guarded at validation time, not Ref-based ones. Optionally emit a warning when a Ref-based MCP withworking_dirresolves to remote at runtime.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit
af057f34.remote.urltoolsets; ref-based MCPs are not covered at parse time because their transport type is only known at runtime.serverSpec.Type == "remote"branch insidecreateMCPTool: iftoolset.WorkingDir != "", an explicit error is returned ("working_dir is not supported for MCP toolset ... ref ... resolves to a remote server") instead of silently discarding the field.checkDirExistscall for ref-based toolsets so it only runs after the server spec is resolved (avoids unnecessary work when the ref turns out to be remote).gateway.OverrideCatalogForTestinghelper +TestMaininpkg/teamloaderto enable unit tests without network, plusTestCreateMCPTool_RefRemote_WorkingDir_ReturnsErrorandTestCreateMCPTool_RefRemote_NoWorkingDir_Succeeds.