mcp-use 0.1.5 → 0.1.6
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.
- package/dist/src/logging.d.ts +19 -2
- package/dist/src/logging.d.ts.map +1 -1
- package/dist/src/logging.js +136 -11
- package/package.json +1 -1
package/dist/src/logging.d.ts
CHANGED
@@ -6,15 +6,32 @@ interface LoggerOptions {
|
|
6
6
|
file?: string;
|
7
7
|
format?: 'minimal' | 'detailed' | 'emoji';
|
8
8
|
}
|
9
|
+
declare class SimpleConsoleLogger {
|
10
|
+
private _level;
|
11
|
+
private name;
|
12
|
+
constructor(name?: string, level?: LogLevel);
|
13
|
+
private shouldLog;
|
14
|
+
private formatMessage;
|
15
|
+
error(message: string): void;
|
16
|
+
warn(message: string): void;
|
17
|
+
info(message: string): void;
|
18
|
+
debug(message: string): void;
|
19
|
+
http(message: string): void;
|
20
|
+
verbose(message: string): void;
|
21
|
+
silly(message: string): void;
|
22
|
+
get level(): LogLevel;
|
23
|
+
set level(newLevel: LogLevel);
|
24
|
+
}
|
9
25
|
export declare class Logger {
|
10
26
|
private static instances;
|
27
|
+
private static simpleInstances;
|
11
28
|
private static currentFormat;
|
12
|
-
static get(name?: string): WinstonLogger;
|
29
|
+
static get(name?: string): WinstonLogger | SimpleConsoleLogger;
|
13
30
|
private static getFormatter;
|
14
31
|
static configure(options?: LoggerOptions): void;
|
15
32
|
static setDebug(enabled: boolean | 0 | 1 | 2): void;
|
16
33
|
static setFormat(format: 'minimal' | 'detailed' | 'emoji'): void;
|
17
34
|
}
|
18
|
-
export declare const logger: WinstonLogger;
|
35
|
+
export declare const logger: SimpleConsoleLogger | WinstonLogger;
|
19
36
|
export {};
|
20
37
|
//# sourceMappingURL=logging.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,E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AAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAM9B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO5B,IAAI,KAAK,IAAI,QAAQ,CAEpB;IAED,IAAI,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAE3B;CACF;AA4BD,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAC,SAAS,CAA0D;IAClF,OAAO,CAAC,MAAM,CAAC,eAAe,CAA0C;IACxE,OAAO,CAAC,MAAM,CAAC,aAAa,CAA8C;WAE5D,GAAG,CAAC,IAAI,GAAE,MAA4B,GAAG,aAAa,GAAG,mBAAmB;IA4B1F,OAAO,CAAC,MAAM,CAAC,YAAY;WAab,SAAS,CAAC,OAAO,GAAE,aAAkB,GAAG,IAAI;WAiD5C,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI;WAyB5C,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,IAAI;CAIxE;AAWD,eAAO,MAAM,MAAM,qCAAe,CAAA"}
|
package/dist/src/logging.js
CHANGED
@@ -3,8 +3,95 @@ import path from 'node:path';
|
|
3
3
|
import { createLogger, format, transports } from 'winston';
|
4
4
|
const { combine, timestamp, label, printf, colorize, splat } = format;
|
5
5
|
const DEFAULT_LOGGER_NAME = 'mcp-use';
|
6
|
+
// Environment detection function (similar to telemetry)
|
7
|
+
function isNodeJSEnvironment() {
|
8
|
+
try {
|
9
|
+
// Check for Cloudflare Workers specifically
|
10
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent?.includes('Cloudflare-Workers')) {
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
// Check for other edge runtime indicators
|
14
|
+
if (typeof globalThis.EdgeRuntime !== 'undefined' || typeof globalThis.Deno !== 'undefined') {
|
15
|
+
return false;
|
16
|
+
}
|
17
|
+
// Check for Node.js specific globals that are not available in edge environments
|
18
|
+
const hasNodeGlobals = (typeof process !== 'undefined'
|
19
|
+
&& typeof process.platform !== 'undefined'
|
20
|
+
&& typeof __dirname !== 'undefined');
|
21
|
+
// Check for Node.js modules
|
22
|
+
const hasNodeModules = (typeof fs !== 'undefined'
|
23
|
+
&& typeof createLogger === 'function');
|
24
|
+
return hasNodeGlobals && hasNodeModules;
|
25
|
+
}
|
26
|
+
catch {
|
27
|
+
return false;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
// Simple console logger for non-Node.js environments
|
31
|
+
class SimpleConsoleLogger {
|
32
|
+
_level;
|
33
|
+
name;
|
34
|
+
constructor(name = DEFAULT_LOGGER_NAME, level = 'info') {
|
35
|
+
this.name = name;
|
36
|
+
this._level = level;
|
37
|
+
}
|
38
|
+
shouldLog(level) {
|
39
|
+
const levels = ['error', 'warn', 'info', 'http', 'verbose', 'debug', 'silly'];
|
40
|
+
const currentIndex = levels.indexOf(this._level);
|
41
|
+
const messageIndex = levels.indexOf(level);
|
42
|
+
return messageIndex <= currentIndex;
|
43
|
+
}
|
44
|
+
formatMessage(level, message) {
|
45
|
+
const timestamp = new Date().toLocaleTimeString('en-US', { hour12: false });
|
46
|
+
return `${timestamp} [${this.name}] ${level}: ${message}`;
|
47
|
+
}
|
48
|
+
error(message) {
|
49
|
+
if (this.shouldLog('error')) {
|
50
|
+
console.error(this.formatMessage('error', message));
|
51
|
+
}
|
52
|
+
}
|
53
|
+
warn(message) {
|
54
|
+
if (this.shouldLog('warn')) {
|
55
|
+
console.warn(this.formatMessage('warn', message));
|
56
|
+
}
|
57
|
+
}
|
58
|
+
info(message) {
|
59
|
+
if (this.shouldLog('info')) {
|
60
|
+
console.info(this.formatMessage('info', message)); // eslint-disable-line no-console
|
61
|
+
}
|
62
|
+
}
|
63
|
+
debug(message) {
|
64
|
+
if (this.shouldLog('debug')) {
|
65
|
+
console.debug(this.formatMessage('debug', message)); // eslint-disable-line no-console
|
66
|
+
}
|
67
|
+
}
|
68
|
+
http(message) {
|
69
|
+
if (this.shouldLog('http')) {
|
70
|
+
console.log(this.formatMessage('http', message)); // eslint-disable-line no-console
|
71
|
+
}
|
72
|
+
}
|
73
|
+
verbose(message) {
|
74
|
+
if (this.shouldLog('verbose')) {
|
75
|
+
console.log(this.formatMessage('verbose', message)); // eslint-disable-line no-console
|
76
|
+
}
|
77
|
+
}
|
78
|
+
silly(message) {
|
79
|
+
if (this.shouldLog('silly')) {
|
80
|
+
console.log(this.formatMessage('silly', message)); // eslint-disable-line no-console
|
81
|
+
}
|
82
|
+
}
|
83
|
+
// Make it compatible with Winston interface
|
84
|
+
get level() {
|
85
|
+
return this._level;
|
86
|
+
}
|
87
|
+
set level(newLevel) {
|
88
|
+
this._level = newLevel;
|
89
|
+
}
|
90
|
+
}
|
6
91
|
function resolveLevel(env) {
|
7
|
-
|
92
|
+
// Safely access environment variables
|
93
|
+
const envValue = (typeof process !== 'undefined' && process.env) ? env : undefined;
|
94
|
+
switch (envValue?.trim()) {
|
8
95
|
case '2':
|
9
96
|
return 'debug';
|
10
97
|
case '1':
|
@@ -24,8 +111,18 @@ const emojiFormatter = printf(({ level, message, label, timestamp }) => {
|
|
24
111
|
});
|
25
112
|
export class Logger {
|
26
113
|
static instances = {};
|
114
|
+
static simpleInstances = {};
|
27
115
|
static currentFormat = 'minimal';
|
28
116
|
static get(name = DEFAULT_LOGGER_NAME) {
|
117
|
+
// Use simple console logger in non-Node.js environments
|
118
|
+
if (!isNodeJSEnvironment()) {
|
119
|
+
if (!this.simpleInstances[name]) {
|
120
|
+
const debugEnv = (typeof process !== 'undefined' && process.env?.DEBUG) || undefined;
|
121
|
+
this.simpleInstances[name] = new SimpleConsoleLogger(name, resolveLevel(debugEnv));
|
122
|
+
}
|
123
|
+
return this.simpleInstances[name];
|
124
|
+
}
|
125
|
+
// Use Winston logger in Node.js environments
|
29
126
|
if (!this.instances[name]) {
|
30
127
|
this.instances[name] = createLogger({
|
31
128
|
level: resolveLevel(process.env.DEBUG),
|
@@ -49,25 +146,37 @@ export class Logger {
|
|
49
146
|
}
|
50
147
|
static configure(options = {}) {
|
51
148
|
const { level, console = true, file, format = 'minimal' } = options;
|
52
|
-
const
|
149
|
+
const debugEnv = (typeof process !== 'undefined' && process.env?.DEBUG) || undefined;
|
150
|
+
const resolvedLevel = level ?? resolveLevel(debugEnv);
|
53
151
|
this.currentFormat = format;
|
54
152
|
const root = this.get();
|
55
153
|
root.level = resolvedLevel;
|
56
|
-
|
154
|
+
// For non-Node.js environments, just update the level
|
155
|
+
if (!isNodeJSEnvironment()) {
|
156
|
+
Object.values(this.simpleInstances).forEach((logger) => {
|
157
|
+
logger.level = resolvedLevel;
|
158
|
+
});
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
// Winston-specific configuration for Node.js environments
|
162
|
+
const winstonRoot = root;
|
163
|
+
winstonRoot.clear();
|
57
164
|
if (console) {
|
58
|
-
|
165
|
+
winstonRoot.add(new transports.Console());
|
59
166
|
}
|
60
167
|
if (file) {
|
61
168
|
const dir = path.dirname(path.resolve(file));
|
62
169
|
if (!fs.existsSync(dir)) {
|
63
170
|
fs.mkdirSync(dir, { recursive: true });
|
64
171
|
}
|
65
|
-
|
172
|
+
winstonRoot.add(new transports.File({ filename: file }));
|
66
173
|
}
|
67
|
-
// Update all existing loggers with new format
|
174
|
+
// Update all existing Winston loggers with new format
|
68
175
|
Object.values(this.instances).forEach((logger) => {
|
69
|
-
logger
|
70
|
-
|
176
|
+
if (logger && 'format' in logger) {
|
177
|
+
logger.level = resolvedLevel;
|
178
|
+
logger.format = combine(colorize(), splat(), label({ label: DEFAULT_LOGGER_NAME }), timestamp({ format: 'HH:mm:ss' }), this.getFormatter());
|
179
|
+
}
|
71
180
|
});
|
72
181
|
}
|
73
182
|
static setDebug(enabled) {
|
@@ -78,15 +187,31 @@ export class Logger {
|
|
78
187
|
level = 'info';
|
79
188
|
else
|
80
189
|
level = 'info';
|
81
|
-
|
190
|
+
// Update both simple and Winston loggers
|
191
|
+
Object.values(this.simpleInstances).forEach((logger) => {
|
82
192
|
logger.level = level;
|
83
193
|
});
|
84
|
-
|
194
|
+
Object.values(this.instances).forEach((logger) => {
|
195
|
+
if (logger) {
|
196
|
+
logger.level = level;
|
197
|
+
}
|
198
|
+
});
|
199
|
+
// Safely set environment variable
|
200
|
+
if (typeof process !== 'undefined' && process.env) {
|
201
|
+
process.env.DEBUG = enabled ? (enabled === true ? '2' : String(enabled)) : '0';
|
202
|
+
}
|
85
203
|
}
|
86
204
|
static setFormat(format) {
|
87
205
|
this.currentFormat = format;
|
88
206
|
this.configure({ format });
|
89
207
|
}
|
90
208
|
}
|
91
|
-
|
209
|
+
// Only configure Winston features if in Node.js environment
|
210
|
+
if (isNodeJSEnvironment()) {
|
211
|
+
Logger.configure();
|
212
|
+
}
|
213
|
+
else {
|
214
|
+
// For non-Node.js environments, just initialize with defaults
|
215
|
+
Logger.configure({ console: true });
|
216
|
+
}
|
92
217
|
export const logger = Logger.get();
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "mcp-use",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.1.
|
4
|
+
"version": "0.1.6",
|
5
5
|
"packageManager": "pnpm@10.6.1",
|
6
6
|
"description": "A utility library for integrating Model Context Protocol (MCP) with LangChain, Zod, and related tools. Provides helpers for schema conversion, event streaming, and SDK usage.",
|
7
7
|
"author": "Zane",
|