@slbdn/mcp-tester 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,32 @@
1
+ /**
2
+ * Error classes for MCPClient operations.
3
+ *
4
+ * All errors include a descriptive message, error code, and proper stack trace.
5
+ * Timeout and connection errors include actionable suggestions for debugging.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * try {
10
+ * await client.callTool({ name: 'invalid-tool', arguments: {} });
11
+ * } catch (error) {
12
+ * if (error instanceof MCPServerError) {
13
+ * console.error(`Server error: ${error.message}`);
14
+ * console.error(`Operation: ${error.operation}`);
15
+ * } else if (error instanceof MCPTimeoutError) {
16
+ * console.error(`Timeout after ${error.timeout}ms on ${error.operation}`);
17
+ * console.error(`Suggestions: ${error.suggestions.join(', ')}`);
18
+ * } else if (error instanceof MCPConnectionError) {
19
+ * console.error(`Connection failed: ${error.message}`);
20
+ * console.error(`Command: ${error.command}`);
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ /**
26
+ * Base error class for all MCP client errors.
27
+ */
1
28
  export class MCPClientError extends Error {
29
+ /** Error code for programmatic error handling. */
2
30
  code;
3
31
  constructor(message, code = 'MCP_CLIENT_ERROR') {
4
32
  super(message);
@@ -7,40 +35,129 @@ export class MCPClientError extends Error {
7
35
  Error.captureStackTrace(this, MCPClientError);
8
36
  }
9
37
  }
38
+ /**
39
+ * Error thrown when a request times out.
40
+ *
41
+ * Includes the operation that timed out, the timeout value, and
42
+ * actionable suggestions for resolving the timeout.
43
+ */
10
44
  export class MCPTimeoutError extends MCPClientError {
45
+ /** The timeout value in milliseconds. */
11
46
  timeout;
12
- constructor(message, timeout) {
47
+ /** The operation that timed out (e.g., "Call tool echo", "List tools"). */
48
+ operation;
49
+ /** Actionable suggestions for resolving the timeout. */
50
+ suggestions;
51
+ constructor(message, timeout, operation, suggestions) {
13
52
  super(message, 'MCP_TIMEOUT_ERROR');
14
53
  this.name = 'MCPTimeoutError';
15
54
  this.timeout = timeout;
55
+ this.operation = operation || 'unknown operation';
56
+ this.suggestions = suggestions || MCPTimeoutError.defaultSuggestions(timeout);
16
57
  Error.captureStackTrace(this, MCPTimeoutError);
17
58
  }
59
+ /**
60
+ * Generate default suggestions based on timeout value.
61
+ */
62
+ static defaultSuggestions(timeout) {
63
+ const suggestions = [
64
+ `Increase timeout (current: ${timeout}ms) — pass a higher 'timeout' option`,
65
+ 'Check that the MCP server is running and responsive',
66
+ ];
67
+ if (timeout < 5000) {
68
+ suggestions.push('The timeout is very low — consider using at least 5000ms for CI environments');
69
+ }
70
+ if (timeout < 10000) {
71
+ suggestions.push('Network/server latency may require 10000ms+ in CI environments');
72
+ }
73
+ suggestions.push('Enable debug logging for more detail: new MCPClient({ logLevel: "debug" })');
74
+ return suggestions;
75
+ }
18
76
  }
77
+ /**
78
+ * Error thrown when the client fails to connect to the MCP server.
79
+ *
80
+ * Includes the server command and actionable suggestions for resolving
81
+ * connection failures.
82
+ */
19
83
  export class MCPConnectionError extends MCPClientError {
20
- constructor(message) {
84
+ /** The command that was used to start the server. */
85
+ command;
86
+ /** Actionable suggestions for resolving the connection failure. */
87
+ suggestions;
88
+ constructor(message, command, suggestions) {
21
89
  super(message, 'MCP_CONNECTION_ERROR');
22
90
  this.name = 'MCPConnectionError';
91
+ this.command = command || 'unknown';
92
+ this.suggestions = suggestions || MCPConnectionError.defaultSuggestions(command);
23
93
  Error.captureStackTrace(this, MCPConnectionError);
24
94
  }
95
+ /**
96
+ * Generate default suggestions based on the server command.
97
+ */
98
+ static defaultSuggestions(command) {
99
+ const suggestions = [
100
+ 'Verify the server command is correct and the executable exists',
101
+ 'Check that the server starts successfully when run manually',
102
+ 'Ensure the server communicates via stdio (stdin/stdout)',
103
+ ];
104
+ if (command === 'node' || command?.startsWith('node')) {
105
+ suggestions.push('Make sure the Node.js script path is correct and the file exists');
106
+ suggestions.push('Run the script directly to check for startup errors: node <path>');
107
+ }
108
+ if (command === 'python' || command === 'python3' || command?.startsWith('python')) {
109
+ suggestions.push('Ensure the Python environment has all required dependencies installed');
110
+ suggestions.push('Check that the Python script path is correct and the file exists');
111
+ }
112
+ if (command === 'npx') {
113
+ suggestions.push('Verify the npm package name is correct and published');
114
+ suggestions.push('Try installing the package globally first: npm install -g <package>');
115
+ }
116
+ suggestions.push('Enable debug logging for more detail: new MCPClient({ logLevel: "debug" })');
117
+ return suggestions;
118
+ }
25
119
  }
120
+ /**
121
+ * Error thrown when a client method is called before start().
122
+ *
123
+ * Includes which method was called to help identify the issue.
124
+ */
26
125
  export class MCPNotStartedError extends MCPClientError {
27
- constructor() {
28
- super('Client not started. Call start() before using client methods.', 'MCP_NOT_STARTED');
126
+ /** The method that was called on the unstarted client. */
127
+ method;
128
+ constructor(method) {
129
+ const methodInfo = method ? ` (called ${method}())` : '';
130
+ super(`Client not started${methodInfo}. Call start() before using client methods.`, 'MCP_NOT_STARTED');
29
131
  this.name = 'MCPNotStartedError';
132
+ this.method = method || 'unknown';
30
133
  Error.captureStackTrace(this, MCPNotStartedError);
31
134
  }
32
135
  }
136
+ /**
137
+ * Error thrown when start() is called on an already-started client.
138
+ */
33
139
  export class MCPAlreadyStartedError extends MCPClientError {
34
140
  constructor() {
35
- super('Client already started. Call stop() before starting again.', 'MCP_ALREADY_STARTED');
141
+ super('Client already started. Call stop() before starting again, or create a new MCPClient instance.', 'MCP_ALREADY_STARTED');
36
142
  this.name = 'MCPAlreadyStartedError';
37
143
  Error.captureStackTrace(this, MCPAlreadyStartedError);
38
144
  }
39
145
  }
146
+ /**
147
+ * Error thrown when the MCP server returns an error response.
148
+ *
149
+ * Includes the operation that failed and the server error code if available.
150
+ */
40
151
  export class MCPServerError extends MCPClientError {
41
- constructor(message) {
152
+ /** The operation that failed (e.g., "Call tool echo", "Read resource config://settings"). */
153
+ operation;
154
+ /** The MCP error code from the server response, if available. */
155
+ serverCode;
156
+ constructor(message, operation, serverCode) {
42
157
  super(message, 'MCP_SERVER_ERROR');
43
158
  this.name = 'MCPServerError';
159
+ this.operation = operation || 'unknown operation';
160
+ this.serverCode = serverCode;
44
161
  Error.captureStackTrace(this, MCPServerError);
45
162
  }
46
163
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvB,IAAI,CAAS;IAE7B,YAAY,OAAe,EAAE,OAAe,kBAAkB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAChD,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,cAAc;IACjC,OAAO,CAAS;IAEhC,YAAY,OAAe,EAAE,OAAe;QAC1C,KAAK,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACjD,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD;QACE,KAAK,CAAC,+DAA+D,EAAE,iBAAiB,CAAC,CAAC;QAC1F,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,kBAAkB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AAc;IACxD;QACE,KAAK,CACH,gGAAgG,EAChG,qBAAqB,CACtB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,sBAAsB,CAAC,CAAC;IACxD,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,cAAc;IAChD,6FAA6F;IAC7E,SAAS,CAAS;IAElC,iEAAiE;IACjD,UAAU,CAAmB;IAE7C,YAAY,OAAe,EAAE,SAAkB,EAAE,UAA4B;QAC3E,KAAK,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,mBAAmB,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAChD,CAAC;CACF"}
@@ -1,17 +1,90 @@
1
+ /**
2
+ * Logging utilities for MCP client.
3
+ *
4
+ * Provides configurable logging with multiple output levels, secret masking,
5
+ * request timing, and JSON pretty-printing for protocol debugging.
6
+ *
7
+ * All log output is automatically masked to prevent sensitive data leakage.
8
+ */
9
+ /**
10
+ * Supported log levels in order of verbosity.
11
+ */
1
12
  export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
13
+ /**
14
+ * Options for configuring a Logger instance.
15
+ */
2
16
  export interface LoggerOptions {
17
+ /**
18
+ * Minimum log level to output.
19
+ * @defaultValue "info"
20
+ */
3
21
  level?: LogLevel;
22
+ /**
23
+ * Prefix added to all log messages.
24
+ */
4
25
  prefix?: string;
26
+ /**
27
+ * Whether to mask secrets in log output.
28
+ * @defaultValue true
29
+ */
30
+ maskSecrets?: boolean;
31
+ /**
32
+ * Whether to include timestamps in log messages.
33
+ * @defaultValue false
34
+ */
35
+ timestamps?: boolean;
36
+ /**
37
+ * Whether to use colored output for different log levels.
38
+ * Colors are only used when output is a TTY (terminal).
39
+ * @defaultValue true
40
+ */
41
+ colors?: boolean;
5
42
  }
43
+ /**
44
+ * Logger interface for logging messages.
45
+ */
6
46
  export interface Logger {
47
+ /** Log a debug message. */
7
48
  debug(...args: unknown[]): void;
49
+ /** Log an info message. */
8
50
  info(...args: unknown[]): void;
51
+ /** Log a warning message. */
9
52
  warn(...args: unknown[]): void;
53
+ /** Log an error message. */
10
54
  error(...args: unknown[]): void;
11
55
  }
56
+ /**
57
+ * Pretty-print a JSON-serializable value with indentation and masking.
58
+ */
59
+ export declare function prettyPrint(value: unknown, shouldMask?: boolean): string;
60
+ /**
61
+ * Start a timer and return a function that returns elapsed milliseconds.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const elapsed = startTimer();
66
+ * await someOperation();
67
+ * logger.debug(`Operation completed in ${elapsed()}ms`);
68
+ * ```
69
+ */
70
+ export declare function startTimer(): () => number;
71
+ /**
72
+ * Logger implementation that outputs to stderr with automatic secret masking,
73
+ * timestamps, colors, and JSON pretty-printing.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const logger = new ConsoleLogger({ level: 'debug', prefix: 'MCPClient' });
78
+ * logger.info('Starting...'); // [MCPClient] INFO: Starting...
79
+ * logger.info('API key:', 'sk-abc123def456ghi789'); // [MCPClient] INFO: API key: sk-ab...789
80
+ * ```
81
+ */
12
82
  export declare class ConsoleLogger implements Logger {
13
83
  private level;
14
84
  private prefix;
85
+ private shouldMask;
86
+ private useTimestamps;
87
+ private useColors;
15
88
  constructor(options?: LoggerOptions);
16
89
  private shouldLog;
17
90
  private format;
@@ -20,10 +93,21 @@ export declare class ConsoleLogger implements Logger {
20
93
  warn(...args: unknown[]): void;
21
94
  error(...args: unknown[]): void;
22
95
  }
96
+ /**
97
+ * No-op logger that discards all log messages.
98
+ *
99
+ * Use this when you don't want any logging output.
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const logger = new NoOpLogger();
104
+ * logger.info('This will be ignored');
105
+ * ```
106
+ */
23
107
  export declare class NoOpLogger implements Logger {
24
- debug(): void;
25
- info(): void;
26
- warn(): void;
27
- error(): void;
108
+ debug(..._args: unknown[]): void;
109
+ info(..._args: unknown[]): void;
110
+ warn(..._args: unknown[]): void;
111
+ error(..._args: unknown[]): void;
28
112
  }
29
113
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChC,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACjC;AAUD,qBAAa,aAAc,YAAW,MAAM;IAC1C,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,GAAE,aAAkB;IAKvC,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,MAAM;IAKd,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;C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,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,SAAS,CAAU;gBAEf,OAAO,GAAE,aAAkB;IAQvC,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,MAAM;IAiBd,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAO/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAO9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAO9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAMhC;AAED;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,YAAW,MAAM;IACvC,KAAK,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI;IAChC,IAAI,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI;IAC/B,IAAI,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI;IAC/B,KAAK,CAAC,GAAG,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI;CACjC"}
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Logging utilities for MCP client.
3
+ *
4
+ * Provides configurable logging with multiple output levels, secret masking,
5
+ * request timing, and JSON pretty-printing for protocol debugging.
6
+ *
7
+ * All log output is automatically masked to prevent sensitive data leakage.
8
+ */
9
+ import { maskSecrets } from './masking.js';
1
10
  const LOG_LEVELS = {
2
11
  debug: 0,
3
12
  info: 1,
@@ -5,45 +14,159 @@ const LOG_LEVELS = {
5
14
  error: 3,
6
15
  none: 99,
7
16
  };
17
+ /**
18
+ * ANSI color codes for terminal output.
19
+ * Only used when output is a TTY.
20
+ */
21
+ const COLORS = {
22
+ debug: '\x1b[36m', // cyan
23
+ info: '\x1b[32m', // green
24
+ warn: '\x1b[33m', // yellow
25
+ error: '\x1b[31m', // red
26
+ dim: '\x1b[2m', // dim
27
+ reset: '\x1b[0m', // reset
28
+ };
29
+ /**
30
+ * Check if stderr is a TTY (terminal).
31
+ */
32
+ function isTTY() {
33
+ return process.stderr?.isTTY ?? false;
34
+ }
35
+ /**
36
+ * Colorize a string for terminal output.
37
+ */
38
+ function colorize(text, color, useColors) {
39
+ if (!useColors || !isTTY())
40
+ return text;
41
+ return `${color}${text}${COLORS.reset}`;
42
+ }
43
+ /**
44
+ * Format a timestamp for log messages.
45
+ */
46
+ function formatTimestamp() {
47
+ const now = new Date();
48
+ const ms = String(now.getMilliseconds()).padStart(3, '0');
49
+ return `${now.toISOString().slice(11, 23)}.${ms}`;
50
+ }
51
+ /**
52
+ * Pretty-print a JSON-serializable value with indentation and masking.
53
+ */
54
+ export function prettyPrint(value, shouldMask = true) {
55
+ if (value === null || value === undefined)
56
+ return String(value);
57
+ if (typeof value === 'string') {
58
+ return shouldMask ? maskSecrets(value) : value;
59
+ }
60
+ try {
61
+ const json = JSON.stringify(value, null, 2);
62
+ return shouldMask ? maskSecrets(json) : json;
63
+ }
64
+ catch {
65
+ const str = String(value);
66
+ return shouldMask ? maskSecrets(str) : str;
67
+ }
68
+ }
69
+ /**
70
+ * Start a timer and return a function that returns elapsed milliseconds.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const elapsed = startTimer();
75
+ * await someOperation();
76
+ * logger.debug(`Operation completed in ${elapsed()}ms`);
77
+ * ```
78
+ */
79
+ export function startTimer() {
80
+ const start = performance.now();
81
+ return () => Math.round(performance.now() - start);
82
+ }
83
+ /**
84
+ * Mask all arguments in an array by converting to strings and masking secrets.
85
+ */
86
+ function maskArgs(args, shouldMask) {
87
+ if (!shouldMask)
88
+ return args;
89
+ return args.map((arg) => (typeof arg === 'string' ? maskSecrets(arg) : maskSecrets(String(arg))));
90
+ }
91
+ /**
92
+ * Logger implementation that outputs to stderr with automatic secret masking,
93
+ * timestamps, colors, and JSON pretty-printing.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const logger = new ConsoleLogger({ level: 'debug', prefix: 'MCPClient' });
98
+ * logger.info('Starting...'); // [MCPClient] INFO: Starting...
99
+ * logger.info('API key:', 'sk-abc123def456ghi789'); // [MCPClient] INFO: API key: sk-ab...789
100
+ * ```
101
+ */
8
102
  export class ConsoleLogger {
9
103
  level;
10
104
  prefix;
105
+ shouldMask;
106
+ useTimestamps;
107
+ useColors;
11
108
  constructor(options = {}) {
12
109
  this.level = LOG_LEVELS[options.level || 'info'];
13
110
  this.prefix = options.prefix || '';
111
+ this.shouldMask = options.maskSecrets !== false; // default true
112
+ this.useTimestamps = options.timestamps ?? false;
113
+ this.useColors = options.colors ?? true;
14
114
  }
15
115
  shouldLog(messageLevel) {
16
116
  return LOG_LEVELS[messageLevel] >= this.level;
17
117
  }
18
118
  format(level, args) {
19
119
  const prefix = this.prefix ? `[${this.prefix}] ` : '';
20
- return [`${prefix}${level.toUpperCase()}:`, ...args];
120
+ const levelStr = level.toUpperCase();
121
+ const masked = maskArgs(args, this.shouldMask);
122
+ const parts = [];
123
+ if (this.useTimestamps) {
124
+ parts.push(colorize(`[${formatTimestamp()}]`, COLORS.dim, this.useColors));
125
+ }
126
+ parts.push(colorize(`${prefix}${levelStr}:`, COLORS[level] || COLORS.reset, this.useColors));
127
+ parts.push(...masked);
128
+ return parts.length > 1 ? parts : [`${prefix}${levelStr}:`, ...masked];
21
129
  }
22
130
  debug(...args) {
23
131
  if (this.shouldLog('debug')) {
24
- console.debug(...this.format('debug', args));
132
+ // eslint-disable-next-line no-console
133
+ console.error(...this.format('debug', args));
25
134
  }
26
135
  }
27
136
  info(...args) {
28
137
  if (this.shouldLog('info')) {
29
- console.info(...this.format('info', args));
138
+ // eslint-disable-next-line no-console
139
+ console.error(...this.format('info', args));
30
140
  }
31
141
  }
32
142
  warn(...args) {
33
143
  if (this.shouldLog('warn')) {
34
- console.warn(...this.format('warn', args));
144
+ // eslint-disable-next-line no-console
145
+ console.error(...this.format('warn', args));
35
146
  }
36
147
  }
37
148
  error(...args) {
38
149
  if (this.shouldLog('error')) {
150
+ // eslint-disable-next-line no-console
39
151
  console.error(...this.format('error', args));
40
152
  }
41
153
  }
42
154
  }
155
+ /**
156
+ * No-op logger that discards all log messages.
157
+ *
158
+ * Use this when you don't want any logging output.
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * const logger = new NoOpLogger();
163
+ * logger.info('This will be ignored');
164
+ * ```
165
+ */
43
166
  export class NoOpLogger {
44
- debug() { }
45
- info() { }
46
- warn() { }
47
- error() { }
167
+ debug(..._args) { }
168
+ info(..._args) { }
169
+ warn(..._args) { }
170
+ error(..._args) { }
48
171
  }
49
172
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAcA,MAAM,UAAU,GAA6B;IAC3C,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,EAAE;CACT,CAAC;AAEF,MAAM,OAAO,aAAa;IAChB,KAAK,CAAS;IACd,MAAM,CAAS;IAEvB,YAAY,UAAyB,EAAE;QACrC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;IACrC,CAAC;IAEO,SAAS,CAAC,YAAsB;QACtC,OAAO,UAAU,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC;IAChD,CAAC;IAEO,MAAM,CAAC,KAAe,EAAE,IAAe;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,OAAO,CAAC,GAAG,MAAM,GAAG,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AAgB,IAAS,CAAC;CACpC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Secret masking utility for preventing sensitive data from appearing in logs.
3
+ *
4
+ * Automatically detects and masks common secret patterns like API keys,
5
+ * tokens, passwords, and connection strings. Also masks values of known
6
+ * sensitive environment variable keys.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { maskSecrets, addSecretPattern } from '@slbdn/mcp-tester';
11
+ *
12
+ * // Built-in patterns are applied automatically
13
+ * maskSecrets('API key: sk-abc123def456ghi789');
14
+ * // → 'API key: sk-ab...789'
15
+ *
16
+ * // Add custom patterns
17
+ * addSecretPattern(/my-secret-key-[a-zA-Z0-9]+/g, 'MyOrg API key');
18
+ * ```
19
+ */
20
+ /**
21
+ * A secret masking pattern with a regex and human-readable name.
22
+ */
23
+ export interface SecretPattern {
24
+ /** Regex pattern to match secrets. */
25
+ pattern: RegExp;
26
+ /** Human-readable name for the pattern (used in diagnostics). */
27
+ name: string;
28
+ }
29
+ /**
30
+ * Mask a string value, keeping the first few and last few characters visible
31
+ * and replacing the rest with `...`.
32
+ *
33
+ * @param value - The secret value to mask
34
+ * @param visibleChars - How many characters to keep visible at start and end
35
+ * @returns Masked string like "sk-ab...789"
36
+ */
37
+ export declare function maskValue(value: string, visibleChars?: number): string;
38
+ /**
39
+ * Mask secrets in a string by applying all active secret patterns
40
+ * and masking values of known sensitive environment variable keys.
41
+ *
42
+ * @param input - The value to mask (any type — converted to string)
43
+ * @returns String with secrets replaced by masked versions
44
+ */
45
+ export declare function maskSecrets(input: unknown): string;
46
+ /**
47
+ * Add a custom secret pattern to the masking rules.
48
+ *
49
+ * @param pattern - Regex pattern to match secrets
50
+ * @param name - Human-readable name for the pattern
51
+ */
52
+ export declare function addSecretPattern(pattern: RegExp, name?: string): void;
53
+ /**
54
+ * Reset all secret patterns to the built-in defaults.
55
+ * Removes any patterns added via `addSecretPattern()`.
56
+ */
57
+ export declare function resetSecretPatterns(): void;
58
+ /**
59
+ * Get the list of currently active secret patterns.
60
+ */
61
+ export declare function getSecretPatterns(): SecretPattern[];
62
+ /**
63
+ * Get the set of sensitive environment variable key names.
64
+ */
65
+ export declare function getSensitiveEnvKeys(): ReadonlySet<string>;
66
+ //# sourceMappingURL=masking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"masking.d.ts","sourceRoot":"","sources":["../../src/utils/masking.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAuFD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,GAAE,MAAsB,GAAG,MAAM,CAOrF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA2BlD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAiB,GAAG,IAAI,CAE/E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,aAAa,EAAE,CAEnD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,WAAW,CAAC,MAAM,CAAC,CAEzD"}