Skip to content

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

Open

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.

Activity

  1. added
    extensionIssues related to the VS Code extension
    mcpIssues related to the use of model context protocol (MCP) servers
    on Sep 26, 2025
  2. self-assigned this
    on Oct 6, 2025
  3. damonto commented on Dec 24, 2025

    @damonto

    Any update on this?

    Still reproducible on my side with the VS Code Codex extension:
    MCP servers always start in HOME and receive no workspace context.
    CLI works fine.

    Happy to provide more details if helpful. Thanks!

  4. drozzy commented on Feb 8, 2026

    @drozzy

    Not working as of Feb 7, 2026. When writing MCP servers for Codex there is no way to get the actual git repo / workspace dir that we're working in, in vscode.

  5. tom-nash commented on Mar 27, 2026

    @tom-nash

    Still not working on the 28th of March using Codex 0.117 and VS-Code Codex Extension 26.5325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions