Skip to content

Fix process.cwd() issue for GUI-launched apps (Claude Desktop, VS Code) #17

Description

@mrsimpson

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:

  1. Copy packages/mcp-server/src/utils/directory-discovery.ts from prompts-mcp
  2. Copy packages/mcp-server/test/unit/directory-discovery.test.ts
  3. 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

  1. Check KNOWLEDGE_SUBDIR env var (direct override)
  2. Search upward from PROJECT_DIR or process.cwd()
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions