Skip to content

MCP server trying to create logs directory in root #5

@hongfeiyang

Description

@hongfeiyang

MCP Server Creating Logs Directory in Root Location

Description

The MCP server is attempting to create a logs directory in a privileged root location instead of within the application directory. This happens because the code in index.ts creates the logs directory relative to the current working directory (process.cwd()), which can be unpredictable depending on how the application is launched.

Code causing the issue:

// Log configuration
const logsDir = path.join(process.cwd(), 'logs');
if (!fs.existsSync(logsDir)) {
  fs.mkdirSync(logsDir, { recursive: true });
}

Steps to Reproduce

  1. Run the install command for the MCP server using Cline as described in the GitHub readme
  2. Observe error when the server attempts to create the logs directory

Expected Behavior

The server should install successfully, creating the logs directory within the application's directory structure, not at the root level.

Error Messages

node:fs:1372 const result = binding.mkdir( ^ Error: ENOENT: no such file or directory, mkdir '/logs' 
at Object.mkdirSync (node:fs:1372:26) 
at file:///Users/hongfeiyang/Documents/Cline/MCP/mcp-server-simulator-ios-idb/dist/mcp/mcp-server.js:12:8 
at ModuleJob.run (node:internal/modules/esm/module_job:263:25) 
at async ModuleLoader.import (node:internal/modules/esm/loader:540:24) 
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5) 
{ errno: -2, code: 'ENOENT', syscall: 'mkdir', path: '/logs' } 
Node.js v20.19.0 
MCP error -32000: Connection closed

Environment

  • OS: macOS 15.3.2
  • RooCode: 3.10.5
  • Node.js: v20.19.0

Possible Solution - I ran this with AI :)

Replace process.cwd() with __dirname (for CommonJS) or the ESM equivalent to ensure the logs directory is created relative to the application directory rather than the current working directory:

// For ESM:
import { fileURLToPath } from 'url';
import path from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const logsDir = path.join(__dirname, 'logs');

// Or make it configurable:
// const logsDir = process.env.LOGS_DIR || path.join(__dirname, 'logs');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions