Problem
The server uses process.cwd() to find the .knowledge/ directory, which fails when launched from GUI applications:
- Claude Desktop on macOS: CWD =
/Applications
- VS Code on macOS: CWD =
/Applications/Visual Studio Code.app/Contents/Resources/app
This makes it impossible for users to use project-specific .knowledge/ docsets.
Solution
A reusable directory-discovery utility has been implemented in prompts-mcp (commit 21c3830) that solves this problem.
Implementation Guide
See complete instructions: https://github.com/mrsimpson/prompts-mcp/blob/preconfigured-prompts/DIRECTORY_DISCOVERY_ISSUE.md
Quick Steps:
- Copy
packages/mcp-server/src/utils/directory-discovery.ts from prompts-mcp
- Copy
packages/mcp-server/test/unit/directory-discovery.test.ts
- Update code using
process.cwd() to use the discovery utility:
import { discoverDirectory } from "./utils/directory-discovery.js";
const knowledgeDiscovery = discoverDirectory({
subdirEnvPrefix: "KNOWLEDGE", // Creates KNOWLEDGE_SUBDIR env var
subdir: ".knowledge",
useHomeFallback: true
});
// Use knowledgeDiscovery.path for the directory
// Check knowledgeDiscovery.exists to see if it exists
// Check knowledgeDiscovery.source to see how it was found
New Environment Variables
PROJECT_DIR - Override starting directory for upward search
KNOWLEDGE_SUBDIR - Directly specify .knowledge directory location
Search Strategy
- Check
KNOWLEDGE_SUBDIR env var (direct override)
- Search upward from
PROJECT_DIR or process.cwd()
- Fallback to
~/.knowledge/ (home directory)
Benefits
✅ Works with Claude Desktop and GUI apps
✅ Searches upward from nested directories
✅ Home directory fallback
✅ Flexible environment variable control
✅ Zero breaking changes
✅ Well-tested (18 new tests in prompts-mcp)
Reference Implementation
Problem
The server uses
process.cwd()to find the.knowledge/directory, which fails when launched from GUI applications:/Applications/Applications/Visual Studio Code.app/Contents/Resources/appThis makes it impossible for users to use project-specific
.knowledge/docsets.Solution
A reusable directory-discovery utility has been implemented in prompts-mcp (commit 21c3830) that solves this problem.
Implementation Guide
See complete instructions: https://github.com/mrsimpson/prompts-mcp/blob/preconfigured-prompts/DIRECTORY_DISCOVERY_ISSUE.md
Quick Steps:
packages/mcp-server/src/utils/directory-discovery.tsfrom prompts-mcppackages/mcp-server/test/unit/directory-discovery.test.tsprocess.cwd()to use the discovery utility:New Environment Variables
PROJECT_DIR- Override starting directory for upward searchKNOWLEDGE_SUBDIR- Directly specify .knowledge directory locationSearch Strategy
KNOWLEDGE_SUBDIRenv var (direct override)PROJECT_DIRorprocess.cwd()~/.knowledge/(home directory)Benefits
✅ Works with Claude Desktop and GUI apps
✅ Searches upward from nested directories
✅ Home directory fallback
✅ Flexible environment variable control
✅ Zero breaking changes
✅ Well-tested (18 new tests in prompts-mcp)
Reference Implementation
preconfigured-prompts21c3830