From 39abfd99bdf2e08821980248a81067eca248e054 Mon Sep 17 00:00:00 2001 From: Egor Pavlikhin Date: Tue, 30 Sep 2025 11:29:36 +1000 Subject: [PATCH 1/4] fix: Change log file path to match entry point instead of node folder --- README.md | 8 ++++++++ src/index.ts | 10 +++++++++- src/utils/logger.ts | 24 ++++++++++++++++++++---- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8ee2bae..e059626 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 (default: `octopus-mcp-log.txt`) +* `-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..6d63bf5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,9 +11,17 @@ 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 } from "path"; +import { DefaultLogFileName } from "./utils/logger.js"; 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); +logger.setEntryDirectory(__dirname); + dotenv.config({ quiet: true }); // Parse command line arguments @@ -27,7 +35,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 (default: ${DefaultLogFileName})`) .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(); diff --git a/src/utils/logger.ts b/src/utils/logger.ts index f0a08af..4665c0c 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,6 +1,8 @@ import * as fs from "fs"; import * as path from "path"; +export const DefaultLogFileName = "octopus-mcp-log.txt"; + export enum LogLevel { INFO = 1, ERROR = 2 @@ -10,25 +12,38 @@ interface LoggerConfig { logFilePath: string; minLevel: LogLevel; quietMode: boolean; + entryDirectory?: string; } /** * Default logger configuration */ const config: LoggerConfig = { - logFilePath: "mcp-server-log.txt", + logFilePath: DefaultLogFileName, minLevel: LogLevel.INFO, quietMode: false }; +/** + * Set the entry directory for resolving relative log file paths + * @param directory The directory of the entry point + */ +function setEntryDirectory(directory: string): void { + config.entryDirectory = directory; + // Update log file path if it's still the default + if (config.logFilePath === DefaultLogFileName) { + config.logFilePath = path.join(directory, DefaultLogFileName); + } +} + /** * 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); + // If it's just a filename (no path separators), use entry directory if available + if (!filePath.includes('/') && !filePath.includes('\\') && config.entryDirectory) { + config.logFilePath = path.join(config.entryDirectory, filePath); } else { config.logFilePath = filePath; } @@ -135,6 +150,7 @@ function error(message: string): void { } export const logger = { + setEntryDirectory, setLogFilePath, setLogLevel, setQuietMode, From c748edd2184e2e3b841c908a2b99a9360074ce58 Mon Sep 17 00:00:00 2001 From: Egor Pavlikhin Date: Tue, 30 Sep 2025 12:20:09 +1000 Subject: [PATCH 2/4] Only log to file if log-file param is specified --- README.md | 2 +- src/index.ts | 13 ++++++++----- src/utils/logger.ts | 29 ++++------------------------- 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index e059626..3eb1e9f 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ npx -y @octopusdeploy/mcp-server --toolsets all --read-only --server-url https:/ #### Other command line arguments * `--log-level ` - Minimum log level (info, error) -* `--log-file ` - Log file path or filename (default: `octopus-mcp-log.txt`) +* `--log-file ` - Log file path or filename. Logs will only be written to console if not specified * `-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 diff --git a/src/index.ts b/src/index.ts index 6d63bf5..2ee7a3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,15 +12,13 @@ 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 } from "path"; -import { DefaultLogFileName } from "./utils/logger.js"; +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); -logger.setEntryDirectory(__dirname); dotenv.config({ quiet: true }); @@ -35,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: ${DefaultLogFileName})`) + .option("--log-file ", `Log file path or filename. Logs will only be written to console if not specified.`) .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(); @@ -57,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 4665c0c..38aba6b 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,7 +1,4 @@ import * as fs from "fs"; -import * as path from "path"; - -export const DefaultLogFileName = "octopus-mcp-log.txt"; export enum LogLevel { INFO = 1, @@ -9,44 +6,27 @@ export enum LogLevel { } interface LoggerConfig { - logFilePath: string; + logFilePath?: string | undefined; minLevel: LogLevel; quietMode: boolean; - entryDirectory?: string; } /** * Default logger configuration */ const config: LoggerConfig = { - logFilePath: DefaultLogFileName, + logFilePath: undefined, minLevel: LogLevel.INFO, quietMode: false }; -/** - * Set the entry directory for resolving relative log file paths - * @param directory The directory of the entry point - */ -function setEntryDirectory(directory: string): void { - config.entryDirectory = directory; - // Update log file path if it's still the default - if (config.logFilePath === DefaultLogFileName) { - config.logFilePath = path.join(directory, DefaultLogFileName); - } -} /** * 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 entry directory if available - if (!filePath.includes('/') && !filePath.includes('\\') && config.entryDirectory) { - config.logFilePath = path.join(config.entryDirectory, filePath); - } else { - config.logFilePath = filePath; - } + config.logFilePath = filePath; } /** @@ -113,7 +93,7 @@ function shouldLog(level: LogLevel): boolean { * @param message Message to log */ function writeToFile(level: LogLevel, message: string): void { - if (config.quietMode) { + if (config.quietMode || config.logFilePath === undefined) { return; // Don't write to file in quiet mode } @@ -150,7 +130,6 @@ function error(message: string): void { } export const logger = { - setEntryDirectory, setLogFilePath, setLogLevel, setQuietMode, From 4298cd38e1589e592e638014db8f3460167763f5 Mon Sep 17 00:00:00 2001 From: Egor Pavlikhin Date: Tue, 30 Sep 2025 12:21:07 +1000 Subject: [PATCH 3/4] Update description --- README.md | 2 +- src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3eb1e9f..4c9fc7a 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ npx -y @octopusdeploy/mcp-server --toolsets all --read-only --server-url https:/ #### Other command line arguments * `--log-level ` - Minimum log level (info, error) -* `--log-file ` - Log file path or filename. Logs will only be written to console if not specified +* `--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 diff --git a/src/index.ts b/src/index.ts index 2ee7a3f..fc56f12 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,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. Logs will only be written to console if not specified.`) + .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(); From 2e04132056a722e8cd56272cf7666d09192ed49e Mon Sep 17 00:00:00 2001 From: Egor Pavlikhin Date: Tue, 30 Sep 2025 14:58:42 +1000 Subject: [PATCH 4/4] Update src/utils/logger.ts Co-authored-by: Andrew Best --- src/utils/logger.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 38aba6b..ca4403f 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -94,7 +94,7 @@ function shouldLog(level: LogLevel): boolean { */ function writeToFile(level: LogLevel, message: string): void { if (config.quietMode || config.logFilePath === undefined) { - return; // Don't write to file in quiet mode + return; // Don't write to file if the log file path is not defined } const timestamp = new Date().toISOString();