This guide shows how to properly configure the Qdrant RAG MCP server in Claude Code to ensure correct working directory context.
Add to your Claude Code configuration (~/.claude-code/config.json or claude_desktop_config.json):
{
"mcpServers": {
"qdrant-rag": {
"command": "python",
"args": [
"/path/to/qdrant-rag/src/qdrant_mcp_context_aware.py"
],
"env": {
"MCP_CLIENT_CWD": "${workspaceFolder}",
"QDRANT_HOST": "localhost",
"QDRANT_PORT": "6333",
"EMBEDDING_MODEL": "all-MiniLM-L12-v2"
}
}
}
}The key is setting MCP_CLIENT_CWD to ${workspaceFolder}, which Claude Code will replace with the actual workspace directory.
{
"mcpServers": {
"qdrant-rag": {
"command": "python",
"args": [
"/path/to/qdrant-rag/src/qdrant_mcp_context_aware.py"
],
"cwd": "${workspaceFolder}",
"env": {
"QDRANT_HOST": "localhost",
"QDRANT_PORT": "6333"
}
}
}
}However, this changes the server's working directory, which might affect where it finds its configuration files.
We could modify the server to accept working directory as a command-line argument:
{
"mcpServers": {
"qdrant-rag": {
"command": "python",
"args": [
"/path/to/qdrant-rag/src/qdrant_mcp_context_aware.py",
"--client-cwd",
"${workspaceFolder}"
]
}
}
}Claude Code supports these variables in configuration:
${workspaceFolder}- The path of the folder opened in Claude Code${workspaceFolderBasename}- The name of the folder opened in Claude Code without any slashes${file}- The current opened file${fileBasename}- The current opened file's basename${fileDirname}- The current opened file's dirname${fileExtname}- The current opened file's extension${cwd}- The task runner's current working directory on startup${lineNumber}- The current selected line number in the active file${selectedText}- The current selected text in the active file${execPath}- The location of the Claude Code executable${pathSeparator}-/on macOS or linux,\on Windows
-
Run a health check and look for the
client_cwdfield:> run health check -
Check if the project detection is correct:
> get context
- Wrong project detected: Ensure
MCP_CLIENT_CWDis set to${workspaceFolder} - Server can't find config files: Use absolute paths in the configuration
- Environment variables not working: Check Claude Code logs for variable expansion
- Always use
${workspaceFolder}for theMCP_CLIENT_CWDenvironment variable - Use absolute paths for the server command and arguments
- Test the configuration with a health check after changes
- Keep server configuration files in a fixed location (not relative to working directory)
If you work with multiple projects, you can create project-specific configurations:
{
"mcpServers": {
"qdrant-rag-projectA": {
"command": "python",
"args": ["/path/to/qdrant-rag/src/qdrant_mcp_context_aware.py"],
"env": {
"MCP_CLIENT_CWD": "/path/to/projectA",
"QDRANT_HOST": "localhost",
"QDRANT_PORT": "6333"
}
},
"qdrant-rag-projectB": {
"command": "python",
"args": ["/path/to/qdrant-rag/src/qdrant_mcp_context_aware.py"],
"env": {
"MCP_CLIENT_CWD": "/path/to/projectB",
"QDRANT_HOST": "localhost",
"QDRANT_PORT": "6333"
}
}
}
}This ensures each project has its own properly scoped MCP server instance.