Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
Expand Down Expand Up @@ -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 <level>` - Minimum log level (info, error)
* `--log-file <path>` - 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
Expand Down
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +33,7 @@ program
.option("--toolsets <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 <level>", "Minimum log level (info, error)", "info")
.option("--log-file <path>", "Log file path or filename (default: mcp-server-log.txt)")
.option("--log-file <path>", '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();
Expand All @@ -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);

Expand Down
17 changes: 6 additions & 11 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as fs from "fs";
import * as path from "path";

export enum LogLevel {
INFO = 1,
ERROR = 2
}

interface LoggerConfig {
logFilePath: string;
logFilePath?: string | undefined;
minLevel: LogLevel;
quietMode: boolean;
}
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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();
Expand Down