diff --git a/README.md b/README.md index 8ee2bae..4c9fc7a 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Full example configuration (for Claude Desktop, Claude Code, and Cursor): { "mcpServers": { "octopusdeploy": { + "type": "stdio", "command": "npx", "args": ["-y", "@octopusdeploy/mcp-server", "--api-key", "YOUR_API_KEY", "--server-url", "https://your-octopus.com"] } @@ -157,6 +158,13 @@ npx -y @octopusdeploy/mcp-server --toolsets core,projects --server-url https://y npx -y @octopusdeploy/mcp-server --toolsets all --read-only --server-url https://your-octopus.com --api-key YOUR_API_KEY ``` +#### Other command line arguments + +* `--log-level ` - Minimum log level (info, error) +* `--log-file ` - Log file path or filename. If not specified, logs are written to console only +* `-q, --quiet` - Disable file logging, only log errors to console +* `--list-tools-by-version` - List all registered tools by their supported Octopus Server version and exit + ## 🔨 Tools ### Core Tools diff --git a/src/index.ts b/src/index.ts index 6a03b93..fc56f12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,9 +11,15 @@ import { getClientConfigurationFromEnvironment } from "./helpers/getClientConfig import { setClientInfo } from "./utils/clientInfo.js"; import { logger } from "./utils/logger.js"; import packageJson from "../package.json" with { type: "json" }; +import { fileURLToPath } from "url"; +import { dirname, join, isAbsolute } from "path"; export const SEMVER_VERSION = packageJson.version; +// Set entry directory for logger (ESM equivalent of __dirname) +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + dotenv.config({ quiet: true }); // Parse command line arguments @@ -27,7 +33,7 @@ program .option("--toolsets ", `Comma-separated list of toolsets to enable, or "all" (default: all). Available toolsets: ${DEFAULT_TOOLSETS.join(", ")}`) .option("--read-only", "Enable read-only mode (default: enabled)", true) .option("--log-level ", "Minimum log level (info, error)", "info") - .option("--log-file ", "Log file path or filename (default: mcp-server-log.txt)") + .option("--log-file ", 'Log file path or filename. If not specified, logs are written to console only.') .option("-q, --quiet", "Disable file logging, only log errors to console", false) .option("--list-tools-by-version", "List all registered tools by their supported Octopus Server version and exit") .parse(); @@ -49,8 +55,13 @@ if (options.listToolsByVersion) { } if (options.logFile) { - logger.setLogFilePath(options.logFile); + if (dirname(options.logFile) === '.') { + logger.setLogFilePath(join(__dirname, options.logFile)); + } else { + logger.setLogFilePath(options.logFile); + } } + logger.setLogLevel(logger.parseLogLevel(options.logLevel)); logger.setQuietMode(options.quiet); diff --git a/src/utils/logger.ts b/src/utils/logger.ts index f0a08af..ca4403f 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,5 +1,4 @@ import * as fs from "fs"; -import * as path from "path"; export enum LogLevel { INFO = 1, @@ -7,7 +6,7 @@ export enum LogLevel { } interface LoggerConfig { - logFilePath: string; + logFilePath?: string | undefined; minLevel: LogLevel; quietMode: boolean; } @@ -16,22 +15,18 @@ interface LoggerConfig { * Default logger configuration */ const config: LoggerConfig = { - logFilePath: "mcp-server-log.txt", + logFilePath: undefined, minLevel: LogLevel.INFO, quietMode: false }; + /** * Set custom log file path * @param filePath Path to the log file (can be full path or just filename) */ function setLogFilePath(filePath: string): void { - // If it's just a filename (no path separators), use current directory - if (!filePath.includes('/') && !filePath.includes('\\')) { - config.logFilePath = path.join(process.cwd(), filePath); - } else { - config.logFilePath = filePath; - } + config.logFilePath = filePath; } /** @@ -98,8 +93,8 @@ function shouldLog(level: LogLevel): boolean { * @param message Message to log */ function writeToFile(level: LogLevel, message: string): void { - if (config.quietMode) { - return; // Don't write to file in quiet mode + if (config.quietMode || config.logFilePath === undefined) { + return; // Don't write to file if the log file path is not defined } const timestamp = new Date().toISOString();