You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MCP] Server relies on process cwd for project discovery, causing "Nimsuggest is unavailable" when spawned from global config #536
When running nimlangserver --mcp via a global MCP client configuration, tool calls like nimCheckFile and nimCheckProject consistently fail with "Nimsuggest is unavailable".
Root Cause
In routes/mcp.nim (around line 577), the MCP server initializes nimsuggest instances strictly based on the process's current working directory (getCurrentDir()):
The process cwd defaults to the user's home directory (C:\Users\<username>) rather than the actual Nim project directory.
Because there is no .nimble file in the home directory, ls.initNimsuggestInstances(rootPath) finds zero projects (ls.projectFiles.len == 0). Later, when nimCheckFile or nimCheckProject is invoked, ls.tryGetNimsuggest(uri) fails to match any active instance and falls into the error branch at line 506:
# routes/mcp.nim:506else:
McpCallToolResult(content: @[McpContentBlock(text: "Nimsuggest is unavailable")], isError: true)
Steps to Reproduce
Add nimlangserver --mcp to a global MCP client configuration without hardcoding a project-specific cwd.
Open a Nim project with a .nimble file in a different directory.
Trigger nimCheckFile or nimCheckProject via the MCP client.
Observe the "Nimsuggest is unavailable" error.
Expected Behavior / Possible Fixes
nimlangserver in MCP mode shouldn't assume getCurrentDir() at startup is the target workspace. A few ways this could be handled:
Lazy project resolution: When nimCheckFile(uri) is called and no matching nimsuggest instance exists, walk up the directory tree from the file's uri to locate the nearest .nimble file / project root, and initialize the nimsuggest instance on demand.
Support MCP roots capability: Query workspace roots from the MCP client during initialization instead of falling back to getCurrentDir().
CLI flag: Allow passing an explicit --project or --root path flag alongside --mcp as a fallback.
Try v1.18.0; both APIs take a path/uri and the project is resolved similarly to fix 1. That code snippet you posted is from v1.16.0. If still fails, post your project layout and I'll try to reproduce it.
Try v1.18.0; both APIs take a path/uri and the project is resolved similarly to fix 1. That code snippet you posted is from v1.16.0. If still fails, post your project layout and I'll try to reproduce it.
Thanks for the quick response, and apologies for the confusion! You are completely right—I inadvertently referenced the older v1.16.0 codebase when analyzing the error snippet.
We have confirmed our environment is running nimlangserver 1.18.0 with Nim 2.4.2 on Windows:
> nimlangserver --version
1.18.0
After testing further with v1.18.0:
Lazy Resolution Works: We confirmed that the lazy project resolution via uri / path works properly—testing on a clean, isolated project returned diagnostics without needing cwd to be hardcoded to the workspace.
Cold-start Timeout on Large Codebases: In our failing project (rika, a 2D game engine), the codebase is quite large (940 .nim files, ~230,000 lines of code):
nimble dump takes ~25–30 seconds to evaluate for this project.
nimsuggest then requires another 30–50 seconds to complete the initial semantic pass, consuming ~1.14 GB of RAM.
In cold-start conditions, total initialization time easily exceeds the 60-second NIMSUGGEST_STARTUP_TIMEOUT (or the MCP client request timeout), triggering an AsyncTimeoutError.
Failure State Caching: Once the initial startup times out or fails, nimlangserver marks project.failed = true in memory. Subsequent MCP tool calls immediately return "Nimsuggest is unavailable" without retrying. (When we gave it a fresh session and ~80s of startup margin, nimsuggest did eventually start up and returned diagnostics successfully).
Thanks again for clarifying the v1.18.0 behavior! For large projects in MCP mode, it might be helpful if the startup timeout could be made configurable or if failed initialization could be retried on subsequent requests.
Activity
nitely commentedon Nov 17, 2026
Try v1.18.0; both APIs take a path/uri and the project is resolved similarly to fix 1. That code snippet you posted is from v1.16.0. If still fails, post your project layout and I'll try to reproduce it.
Yakumo-Yukari commentedon Nov 17, 2026
Thanks for the quick response, and apologies for the confusion! You are completely right—I inadvertently referenced the older v1.16.0 codebase when analyzing the error snippet.
We have confirmed our environment is running
nimlangserver 1.18.0with Nim 2.4.2 on Windows:After testing further with v1.18.0:
uri/pathworks properly—testing on a clean, isolated project returned diagnostics without needingcwdto be hardcoded to the workspace.rika, a 2D game engine), the codebase is quite large (940.nimfiles, ~230,000 lines of code):nimble dumptakes ~25–30 seconds to evaluate for this project.nimsuggestthen requires another 30–50 seconds to complete the initial semantic pass, consuming ~1.14 GB of RAM.NIMSUGGEST_STARTUP_TIMEOUT(or the MCP client request timeout), triggering anAsyncTimeoutError.nimlangservermarksproject.failed = truein memory. Subsequent MCP tool calls immediately return"Nimsuggest is unavailable"without retrying. (When we gave it a fresh session and ~80s of startup margin,nimsuggestdid eventually start up and returned diagnostics successfully).Here is our project layout for reference:
Thanks again for clarifying the v1.18.0 behavior! For large projects in MCP mode, it might be helpful if the startup timeout could be made configurable or if failed initialization could be retried on subsequent requests.
nitely commentedon Nov 19, 2026
this would require the content of
rika.nimbleand maybeconfig.nimsto reproduce.nimble dumpshould not take multiple seconds.the rest will be fixed in nimsuggest2 ; including removing the startup timeout.