UNPKG

@coji/journal-mcp

Version:

MCP server for journal entries with web viewer

81 lines • 3.3 kB
import { promises as fs } from 'node:fs'; import { dirname } from 'node:path'; import { fileExists, ensureDir } from './utils/files.js'; import { detectNpxPath, getClaudeConfigPath } from './utils/system.js'; export async function setupClaudeDesktop(options = {}) { const configPath = options.configPath || getClaudeConfigPath(); console.log('šŸ”§ Setting up Claude Desktop configuration...'); console.log(`šŸ“ Config path: ${configPath}`); // Ensure config directory exists await ensureDir(dirname(configPath)); // Detect npx path const npxPath = await detectNpxPath(); console.log(`šŸ” Detected npx at: ${npxPath}`); // Read existing config or create empty one let config = {}; if (await fileExists(configPath)) { console.log('šŸ“– Reading existing configuration...'); // Create backup const backupPath = `${configPath}.backup.${Date.now()}`; const existingContent = await fs.readFile(configPath, 'utf-8'); await fs.writeFile(backupPath, existingContent, 'utf-8'); console.log(`šŸ’¾ Backup created: ${backupPath}`); try { config = JSON.parse(existingContent); } catch (error) { console.warn('āš ļø Failed to parse existing config, creating new one'); config = {}; } } // Initialize mcpServers if not exists if (!config.mcpServers) { config.mcpServers = {}; } // Check if journal config already exists if (config.mcpServers.journal && !options.force) { console.log('āœ… Journal MCP server already configured'); console.log('šŸ’” Use --force to overwrite existing configuration'); return; } // Add journal MCP server configuration config.mcpServers.journal = { command: npxPath, args: ['@coji/journal-mcp'], }; // Write updated config const configContent = JSON.stringify(config, null, 2); await fs.writeFile(configPath, configContent, 'utf-8'); console.log('āœ… Claude Desktop configuration updated!'); console.log('\nšŸ“‹ Configuration added:'); console.log(JSON.stringify(config.mcpServers.journal, null, 2)); console.log('\nšŸš€ Next steps:'); console.log('1. Restart Claude Desktop'); console.log('2. The journal MCP server will be available in Claude Desktop'); console.log('3. To start web viewer separately, run: npx @coji/journal-mcp --viewer'); console.log('\nšŸ’” Try asking Claude: "Add a journal entry about today\'s work"'); } export async function verifySetup() { const configPath = getClaudeConfigPath(); if (!(await fileExists(configPath))) { console.log('āŒ Claude Desktop config not found'); return false; } try { const content = await fs.readFile(configPath, 'utf-8'); const config = JSON.parse(content); if (config.mcpServers?.journal) { console.log('āœ… Journal MCP server is configured'); return true; } else { console.log('āŒ Journal MCP server not found in configuration'); return false; } } catch (error) { console.log('āŒ Failed to read Claude Desktop configuration'); return false; } } //# sourceMappingURL=setup.js.map