diff --git a/package-lock.json b/package-lock.json index 62ce41a5b..9a6457460 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,6 @@ "@rollup/plugin-node-resolve": "^16.0.3", "@stylistic/eslint-plugin": "^5.4.0", "@toon-format/toon": "^2.2.0", - "@types/debug": "^4.1.12", "@types/filesystem": "^0.0.36", "@types/node": "^26.0.0", "@types/semver": "^7.7.1", @@ -31,7 +30,6 @@ "@typescript-eslint/parser": "^8.43.0", "chrome-devtools-frontend": "1.0.1652307", "core-js": "3.49.0", - "debug": "4.4.3", "eslint": "^9.35.0", "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import": "^2.32.0", @@ -1997,16 +1995,6 @@ "@types/node": "*" } }, - "node_modules/@types/debug": { - "version": "4.1.13", - "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.13.tgz", - "integrity": "sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/ms": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", @@ -2045,13 +2033,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/ms": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", - "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/mysql": { "version": "2.15.26", "resolved": "https://registry.npmjs.org/@types/mysql/-/mysql-2.15.26.tgz", diff --git a/package.json b/package.json index d8daa6cbd..c7aa5074a 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "@rollup/plugin-node-resolve": "^16.0.3", "@stylistic/eslint-plugin": "^5.4.0", "@toon-format/toon": "^2.2.0", - "@types/debug": "^4.1.12", "@types/filesystem": "^0.0.36", "@types/node": "^26.0.0", "@types/semver": "^7.7.1", @@ -66,7 +65,6 @@ "@typescript-eslint/parser": "^8.43.0", "chrome-devtools-frontend": "1.0.1652307", "core-js": "3.49.0", - "debug": "4.4.3", "eslint": "^9.35.0", "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import": "^2.32.0", diff --git a/src/logger.ts b/src/logger.ts index d54038930..040054128 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -5,25 +5,23 @@ */ import fs from 'node:fs'; +import {debuglog} from 'node:util'; -import {debug} from './third_party/index.js'; import type {Logger} from './types.js'; const mcpDebugNamespace = 'mcp:log'; -const namespacesToEnable = [ - mcpDebugNamespace, - ...(process.env['DEBUG'] ? [process.env['DEBUG']] : []), -]; +const nodeDebugLogger = debuglog(mcpDebugNamespace); -export function saveLogsToFile(fileName: string): fs.WriteStream { - // Enable overrides everything so we need to add them - debug.enable(namespacesToEnable.join(',')); +let fileLogger: ((...args: unknown[]) => void) | null = null; +export function saveLogsToFile(fileName: string): fs.WriteStream { const logFile = fs.createWriteStream(fileName, {flags: 'a+'}); - debug.log = function (...chunks: any[]) { + + fileLogger = (...chunks: unknown[]) => { logFile.write(`${chunks.join(' ')}\n`); }; + logFile.on('error', function (error) { console.error(`Error when opening/writing to log file: ${error.message}`); logFile.end(); @@ -45,4 +43,12 @@ export function flushLogs( }); } -export const logger: Logger = debug(mcpDebugNamespace) as Logger; +let logger: Logger|undefined; + +if (fileLogger) { + logger = fileLogger; +} else if (nodeDebugLogger.enabled) { + logger = nodeDebugLogger as unknown as Logger; +} + +export {logger}; diff --git a/src/third_party/index.ts b/src/third_party/index.ts index 222f1499c..5f64f2351 100644 --- a/src/third_party/index.ts +++ b/src/third_party/index.ts @@ -18,8 +18,7 @@ export type {Options as YargsOptions} from 'yargs'; export {default as yargs} from 'yargs'; export {hideBin} from 'yargs/helpers'; export {default as semver} from 'semver'; -export {default as debug} from 'debug'; -export type {Debugger} from 'debug'; + export {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js'; export {type ShapeOutput} from '@modelcontextprotocol/sdk/server/zod-compat.js'; export {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; diff --git a/tests/third_party_notices.test.js.snapshot b/tests/third_party_notices.test.js.snapshot index 4b9412642..7477313c6 100644 --- a/tests/third_party_notices.test.js.snapshot +++ b/tests/third_party_notices.test.js.snapshot @@ -345,101 +345,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --------------------- DEPENDENCY DIVIDER -------------------- - -Name: debug -URL: git://github.com/debug-js/debug.git -Version: -License: MIT - -(The MIT License) - -Copyright (c) 2014-2017 TJ Holowaychuk -Copyright (c) 2018-2021 Josh Junon - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -and associated documentation files (the 'Software'), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial -portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT -LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - - --------------------- DEPENDENCY DIVIDER -------------------- - -Name: ms -URL: vercel/ms -Version: -License: MIT - -The MIT License (MIT) - -Copyright (c) 2020 Vercel, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - --------------------- DEPENDENCY DIVIDER -------------------- - -Name: has-flag -URL: sindresorhus/has-flag -Version: -License: MIT - -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - --------------------- DEPENDENCY DIVIDER -------------------- - -Name: supports-color -URL: chalk/supports-color -Version: -License: MIT - -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -------------------- DEPENDENCY DIVIDER -------------------- Name: zod diff --git a/tests/utils.ts b/tests/utils.ts index 465404f35..1901afd9c 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -9,7 +9,6 @@ import {spawn} from 'node:child_process'; import path from 'node:path'; import type {CallToolResult} from '@modelcontextprotocol/sdk/types.js'; -import logger from 'debug'; import type {Browser} from 'puppeteer'; import puppeteer, {Locator} from 'puppeteer'; import type { @@ -132,7 +131,7 @@ export async function withMcpContext( } context = await McpContext.from( browser, - logger('test'), + undefined, { experimentalDevToolsDebugging: false, performanceCrux: options.performanceCrux ?? true,