mcplog 0.0.1
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/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mcp-log contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# mcplog
|
|
2
|
+
|
|
3
|
+
[](https://www.typescriptlang.org)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
[](https://codecov.io/github/bernoussama/mcplog?branch=master)
|
|
8
|
+
|
|
9
|
+
> Small JSON-lines logger for MCP servers.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add mcplog
|
|
15
|
+
# or
|
|
16
|
+
npm install mcplog
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { McpLogger } from "mcplog";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { McpLogger } from "mcp-log";
|
|
29
|
+
|
|
30
|
+
const logger = new McpLogger({ name: "my-mcp-server" });
|
|
31
|
+
|
|
32
|
+
logger.info("server started", { port: 3000 });
|
|
33
|
+
logger.error("request failed", { requestId: "abc123" });
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Logs are written to `stderr` by default so MCP protocol messages on `stdout` stay untouched. Set `CLANKER_LOG_FILE` or pass `filePath` to write JSON lines to a file instead.
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
new McpLogger({
|
|
42
|
+
name: string,
|
|
43
|
+
level?: "debug" | "info" | "warn" | "error",
|
|
44
|
+
filePath?: string,
|
|
45
|
+
stderr?: { write(chunk: string): unknown },
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Methods: `debug`, `info`, `warn`, and `error`.
|
|
50
|
+
|
|
51
|
+
The package also exports the `LogLevel` and `LogSink` types.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
2
|
+
export type LogSink = {
|
|
3
|
+
write(chunk: string): unknown;
|
|
4
|
+
};
|
|
5
|
+
export declare class McpLogger {
|
|
6
|
+
private readonly out;
|
|
7
|
+
private readonly minRank;
|
|
8
|
+
private readonly name;
|
|
9
|
+
constructor(options: {
|
|
10
|
+
name: string;
|
|
11
|
+
level?: LogLevel;
|
|
12
|
+
filePath?: string;
|
|
13
|
+
stderr?: LogSink;
|
|
14
|
+
});
|
|
15
|
+
private write;
|
|
16
|
+
debug(message: string, extra?: Record<string, unknown>): void;
|
|
17
|
+
info(message: string, extra?: Record<string, unknown>): void;
|
|
18
|
+
warn(message: string, extra?: Record<string, unknown>): void;
|
|
19
|
+
error(message: string, extra?: Record<string, unknown>): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC/B,CAAC;AASF,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAU;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;gBAElB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,QAAQ,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE;IAU5F,OAAO,CAAC,KAAK;IAeb,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI7D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI5D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI5D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;CAG9D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
const LEVEL_RANK = {
|
|
3
|
+
debug: 0,
|
|
4
|
+
info: 1,
|
|
5
|
+
warn: 2,
|
|
6
|
+
error: 3,
|
|
7
|
+
};
|
|
8
|
+
export class McpLogger {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.name = options.name;
|
|
11
|
+
this.minRank = LEVEL_RANK[options.level ?? "info"];
|
|
12
|
+
const resolvedPath = options.filePath ?? process.env["CLANKER_LOG_FILE"];
|
|
13
|
+
this.out = resolvedPath
|
|
14
|
+
? fs.createWriteStream(resolvedPath, { flags: "a" })
|
|
15
|
+
: (options.stderr ?? process.stderr);
|
|
16
|
+
}
|
|
17
|
+
write(level, message, extra) {
|
|
18
|
+
if (LEVEL_RANK[level] < this.minRank)
|
|
19
|
+
return;
|
|
20
|
+
const line = JSON.stringify({
|
|
21
|
+
name: this.name,
|
|
22
|
+
level,
|
|
23
|
+
time: new Date().toISOString(),
|
|
24
|
+
msg: message,
|
|
25
|
+
...extra,
|
|
26
|
+
}) + "\n";
|
|
27
|
+
this.out.write(line);
|
|
28
|
+
}
|
|
29
|
+
debug(message, extra) {
|
|
30
|
+
this.write("debug", message, extra);
|
|
31
|
+
}
|
|
32
|
+
info(message, extra) {
|
|
33
|
+
this.write("info", message, extra);
|
|
34
|
+
}
|
|
35
|
+
warn(message, extra) {
|
|
36
|
+
this.write("warn", message, extra);
|
|
37
|
+
}
|
|
38
|
+
error(message, extra) {
|
|
39
|
+
this.write("error", message, extra);
|
|
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ED,KAAK,CAAC,OAAe,EAAE,KAA+B;QACpD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,KAA+B;QACnD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,KAA+B;QACnD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,KAA+B;QACpD,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcplog",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Small JSON-lines logger for MCP servers.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/bernoussama/mcplog.git"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "pnpm run clean && tsc -p tsconfig.build.json",
|
|
25
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"coverage": "vitest run --coverage",
|
|
28
|
+
"check-types": "tsc --noEmit",
|
|
29
|
+
"lint": "oxlint",
|
|
30
|
+
"lint:fix": "oxlint --fix",
|
|
31
|
+
"fmt": "oxfmt",
|
|
32
|
+
"fmt:check": "oxfmt --check",
|
|
33
|
+
"verify": "pnpm run check-types && pnpm run lint && pnpm run test && pnpm run build",
|
|
34
|
+
"prepack": "pnpm run build",
|
|
35
|
+
"prepublishOnly": "pnpm run verify"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"oxfmt": "^0.51.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/node": "^22.19.19",
|
|
42
|
+
"@vitest/coverage-v8": "4.1.6",
|
|
43
|
+
"oxlint": "^1.66.0",
|
|
44
|
+
"typescript": "^6.0.3",
|
|
45
|
+
"vitest": "4.1.6"
|
|
46
|
+
}
|
|
47
|
+
}
|