Skip to content
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

Set CWD of MCP server for single-root workspaces #964

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gusbicalho
Copy link

@gusbicalho gusbicalho commented Feb 12, 2025

Description

It's useful to have the MCP process started in the workspace directory, so the process can rely on local configuration files.

For example, I use ASDF to manage NodeJS version in a project. By setting the CWD to be the current workspace, an MCP that runs npx will use the node version defined for the project.

This is a very recent addition to the @modelcontextprotocol/sdk so I updated it to version 1.5.0.

When we do not specify the CWD, the MCP server is spawned at process.cwd(), which (in my machine at least) returns /.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • ? Breaking change (fix or feature that would cause existing functionality to not work as expected):
    • This has the potential to change behaviour, if some MCP out there was relying on being run at the / path.
    • This seems unlikely, but if we want to be really strict about making this non-breaking, we could keep the current behaviour if config.cwd is undefined. We would then only apply the new behaviour if config.cwd === <some_special_value> e.g. "{workspaceDir}".
  • This change requires a documentation update

How Has This Been Tested?

Tested the extension locally and found that it now starts an MCP with the correct CWD.

Checklist:

  • My code follows the patterns of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Additional context

Related Issues

Reviewers


Important

Sets CWD for MCP servers to workspace directory in single-root workspaces and updates SDK to version 1.5.0.

  • Behavior:
    • Sets CWD for MCP servers to workspace directory in single-root workspaces in McpHub.ts.
    • Defaults to process.cwd() if no workspace or multiple workspaces.
  • Dependencies:
    • Updates @modelcontextprotocol/sdk to version 1.5.0 in package.json.

This description was created by Ellipsis for 00e9c7b. It will automatically update as commits are pushed.

Copy link

changeset-bot bot commented Feb 12, 2025

⚠️ No Changeset found

Latest commit: 56c8619

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -170,6 +170,7 @@ export class McpHub {
// ...(process.env.NODE_PATH ? { NODE_PATH: process.env.NODE_PATH } : {}),
},
stderr: "pipe", // necessary for stderr to be available
cwd: config.cwd ?? this.getDefaultCwd(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider updating the configuration schema to document the new 'cwd' option explicitly.

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.

1 participant