CodeGraph MCP tools fail with "CodeGraph not initialized" when projectPath is omitted, even though index exists
Problem
When using CodeGraph MCP tools without specifying the projectPath parameter, the tools fail with the error: Error: Tool execution failed: CodeGraph not initialized for this project. Run 'codegraph init' first. However, the CodeGraph index does exist in the project directory at .codegraph/codegraph.db (49.46 MB), and codegraph status command works correctly.
Environment
- Project Directory: /Users/20250310/IdeaProjects/test1
- Working Directory: Same as project directory
- CodeGraph Index: Exists at .codegraph/codegraph.db
- Index Status: Valid (1,152 files, 15,420 nodes, 26,260 edges)
Please try installing bettersqlite3 npm install better-sqlite3 and try again , sometimes sqlite db is locked
execute npm install better-sqlite3 and try again, it was still failed.After consulting AI,I wrote a rule,when call mcp, add projectPath, for example:mcp_codegraph_codegraph_status({
"projectPath": "/Users/20250310/IdeaProjects/tes1"
}),then it was successful
Fixed in #214 (merged to main) — thanks @zhangyu1197 for the clear report, the diagnosis, and the projectPath workaround that pinpointed it. 🙏
Root cause: when a client launches the MCP server outside the project and doesn't report a workspace root in initialize, the server was falling back to its own working directory and missing your .codegraph/. It now asks the client for its workspace root via the standard MCP roots/list request before falling back — so detection works without you having to pass projectPath by hand. And if it still can't resolve a project, the error now tells you exactly how to fix it (pass projectPath, or add --path /abs/project to the server's MCP config args) instead of the misleading "run codegraph init".
This will go out in the next npm release. If your client doesn't implement the MCP roots capability, the --path flag in your MCP config is the reliable fallback.