Starting MCP is unstable due to race conditions in setting env variable #36757
Replies: 8 comments
This comment has been hidden.
This comment has been hidden.
-
doesn't work with "mcp-hello-world": {
"command": {
"path": "bunx",
"args": ["-y", "[email protected]"]
}
} would be good to have more logs when error occurs.
Few things that could be added - exit code, env path, is there more detail than This could be very specific to the default shell. When my shell is zsh it seems to work.
but when it is fish it doesn't work.
|
Beta Was this translation helpful? Give feedback.
-
(not familiar with zed code but looked around on how start server and set env is impelmented). looking at the PR and code in zed at how env is set and the mcp server is started, I don't think the PR would solve. At least based on my logs it seems like it is setting the env correctly but after the mcp server has started thus causing the binary to not be found and failing. Env seems to be set in the background and context server also seems to be set in the background so there is a potential race condition. I think the right solution is to wait for the env to be set before starting the mcp server. or when mcp server is starting always read the env path and pass it to the process so it gets loaded correctly. |
Beta Was this translation helpful? Give feedback.
-
I was about to submit an issue and searching led me here. (yes it happens on The issue I'm experiencing is similar but not exactly the same. It doesn't matter whether Zed is started from the launcher or terminal, it always ends up with this behavior:
Notably, flipping the switch off and on again solves it 100%. The tools are always loaded. I have a local patch that solves it. I'm polishing it before sending a PR but so far it works perfectly for me. With the patch on I get the tools loaded 100% of the time. The race condition is gone. While the symptoms are different, I believe the patch would solve this as well, so I'm not submitting a separate issue but commenting here instead. |
Beta Was this translation helpful? Give feedback.
-
Never mind. Looking more closely at your issue it seems to be unrelated and my patch won't solve it. In my case context servers never have issues starting up. They just start up too soon to get registered. Your logs show a spawn failure instead. I will submit another issue. Edit: submitted #32132. |
Beta Was this translation helpful? Give feedback.
-
I'm experiencing a similar issue on 0.190.5 (linux). I have an mcp server (mcp-nixos) working in claude code; when I set it up in zed, it's recognized by zed the agent panel (it shows 18 new properly named tools), but they are not communicated to/not visible to the agent. The failure is silent in that there seems to be no detection that there's a rather important context (mcp tools) which exist according to zed, but are not being passed to agents at all. |
Beta Was this translation helpful? Give feedback.
-
@ammkrn not sure if this will help but suggest using visual studio code to see if it works there. few things i have noticed is different clients have different way of handling. i have noticied some client only handle strict agent names ie a-zA-Z-_ and not other chars, some may silently ignore, some will throw errors. Until Zed logging improves related to mcp servers it is very hard to figure out what is wrong. I probably need to start having this list and file another bug to improve the experience of MCP server development from Zed. |
Beta Was this translation helpful? Give feedback.
-
I moved this to a discussion because there's insufficient info to reproduce. It's absolutely possible there is a race condition with environment loading vs mcp spawning, but it's not something that can be tracked down easily without a way to (even inconsistently) trigger the behavior. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm on a Mac and have configured mise to setup my tools such as node, npm, python and use fish shell. I have noticed that using mcp in zed is a hit or miss when starting it with the spotlight but always works when i start it from the terminal using
zed
cli. Looking closely at the logs I belive their is a race condition on setting the environment variable.Here is a simple config for setting up a hello world mcp server.
Here is a log of it failing to start.
Using
"path": "/opt/homebrew/opt/mise/bin/mise",
always works.Ideally using
bunx
directly without any references to mise should work.more zed log
Zed Version and System Specs
Zed: v0.189.5 (Zed Preview)
OS: macOS 15.5.0
Memory: 36 GiB
Architecture: aarch64
Beta Was this translation helpful? Give feedback.
All reactions