Skip to content

MCP servers are not launched in the VSCode workspace folder #4222

Description

@meanderix

Currently MCP servers are not launched in the workspace folder. This causes multiple issues when MCP tool calls need to resolve relative path arguments. Relative paths are incorrectly resolved to the folder where the MCP server is launched. Codex seem to partially work around this problem by supplying absolute paths if possible, but this is not a fully reliable solution.

Here is further input from Codex:

  • At tool-call time Codex injects CODEX_WORKSPACE_ROOT; server code can capture it lazily the first time it shows up and cache it. When running elsewhere the env var simply won’t exist, so the same binary stays generic—just add realpath = resolve(env('CODEX_WORKSPACE_ROOT') or cwd, user_path).
  • Some MCP runtimes provide the client’s working directory in each call_tool request (e.g. invocation.cwd). If Codex exposes that field, use it in preference to cwd(); otherwise fall back gracefully. This keeps the logic protocol-aligned instead of Codex-specific.
  • If you distribute servers as scripts, have them compute their own root from the script location (SCRIPT_DIR="$(dirname "$(realpath "$0")")"). They can then resolve relative arguments without caring about the process working directory.
  • For a platform fix, the VS Code extension should spawn each MCP server with cwd set to the active workspace (or expose ${workspaceFolder} for the server’s cwd/env config). Worth filing upstream since it eliminates the workaround entirely.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingextensionIssues related to the VS Code extensionmcpIssues related to the use of model context protocol (MCP) servers

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions