loglens-mcp 0.1.0__tar.gz
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.
- loglens_mcp-0.1.0/LICENSE +21 -0
- loglens_mcp-0.1.0/MANIFEST.in +4 -0
- loglens_mcp-0.1.0/PKG-INFO +150 -0
- loglens_mcp-0.1.0/README.md +137 -0
- loglens_mcp-0.1.0/THIRD_PARTY.md +3 -0
- loglens_mcp-0.1.0/assets/logo.svg +14 -0
- loglens_mcp-0.1.0/examples/build.json +1 -0
- loglens_mcp-0.1.0/loglens_mcp/__init__.py +2 -0
- loglens_mcp-0.1.0/loglens_mcp/__main__.py +30 -0
- loglens_mcp-0.1.0/loglens_mcp/core.py +133 -0
- loglens_mcp-0.1.0/loglens_mcp.egg-info/PKG-INFO +150 -0
- loglens_mcp-0.1.0/loglens_mcp.egg-info/SOURCES.txt +19 -0
- loglens_mcp-0.1.0/loglens_mcp.egg-info/dependency_links.txt +1 -0
- loglens_mcp-0.1.0/loglens_mcp.egg-info/entry_points.txt +2 -0
- loglens_mcp-0.1.0/loglens_mcp.egg-info/requires.txt +1 -0
- loglens_mcp-0.1.0/loglens_mcp.egg-info/top_level.txt +1 -0
- loglens_mcp-0.1.0/pyproject.toml +21 -0
- loglens_mcp-0.1.0/server.json +23 -0
- loglens_mcp-0.1.0/setup.cfg +4 -0
- loglens_mcp-0.1.0/tests/test_core.py +49 -0
- loglens_mcp-0.1.0/tests/test_protocol.py +23 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ahmed Saeed
|
|
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.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: loglens-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline bounded compile and test log summaries
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Repository, https://github.com/ahmedsaeed1-eng/loglens-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/ahmedsaeed1-eng/loglens-mcp/issues
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: mcp<2,>=1.29
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
# LogLens MCP
|
|
17
|
+
|
|
18
|
+
<!-- mcp-name: io.github.ahmedsaeed1-eng/loglens-mcp -->
|
|
19
|
+
|
|
20
|
+
**Keep the evidence. Bound the output. Make omissions visible.**
|
|
21
|
+
|
|
22
|
+
[](https://github.com/ahmedsaeed1-eng/loglens-mcp/stargazers) [](https://github.com/ahmedsaeed1-eng/loglens-mcp/actions/workflows/ci.yml)
|
|
23
|
+
|
|
24
|
+
|  |  |  |
|
|
25
|
+
| :---: | :---: | :---: |
|
|
26
|
+
|
|
27
|
+
LogLens is an offline tool for explicitly supplied, benign compilation and unit-test
|
|
28
|
+
logs. It classifies familiar diagnostic lines, groups exact repeated lines,
|
|
29
|
+
retains numbered excerpts and reports omissions. It never runs the build,
|
|
30
|
+
retrieves logs, intercepts tools, operates sessions, or accesses files and networks.
|
|
31
|
+
It is not a security log analyzer.
|
|
32
|
+
|
|
33
|
+
## Motivation
|
|
34
|
+
|
|
35
|
+
Reports in [Codex issue #44305](https://github.com/openai/codex/issues/44305)
|
|
36
|
+
and [Claude Code issue #49048](https://github.com/anthropics/claude-code/issues/49048)
|
|
37
|
+
describe context growth from tool loops or request output filtering.
|
|
38
|
+
LogLens is an independent implementation of bounded build/test log summaries,
|
|
39
|
+
not an official fix for either product. It measures actual JSON output
|
|
40
|
+
characters and UTF-8 bytes, not token counts, savings, or cost.
|
|
41
|
+
|
|
42
|
+
## Input → report
|
|
43
|
+
|
|
44
|
+
| Stage | Behavior |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| Accept | Explicit UTF-8 log string (up to 256 KiB / 10,000 lines) |
|
|
47
|
+
| Recognize | Common TypeScript, Dart, Gradle/Kotlin, pytest, Jest/Vitest line shapes |
|
|
48
|
+
| Group | Exact repeated raw diagnostic lines, not inferred root cause |
|
|
49
|
+
| Preserve | Source line numbers, excerpts, raw-line SHA-256 identity |
|
|
50
|
+
| Bound | Explicit omission counts, coverage totals, maximum JSON characters |
|
|
51
|
+
| Report | Diagnostics detected, incomplete, or no recognized diagnostic lines |
|
|
52
|
+
|
|
53
|
+
The parser is deliberately conservative and line-oriented. It does not parse
|
|
54
|
+
all tool versions, stack traces or multiline exceptions. Unknown lines are
|
|
55
|
+
not discarded silently; they are counted and some are included with evidence
|
|
56
|
+
line numbers. ANSI color codes are stripped for display and other control
|
|
57
|
+
characters escaped; raw grouping still uses the original line. Each group
|
|
58
|
+
retains the first 12 line numbers and counts any remaining ones. Excerpts are
|
|
59
|
+
limited to 220 characters plus an ellipsis.
|
|
60
|
+
|
|
61
|
+
Output status `no_recognized_diagnostics` is not a successful build verdict.
|
|
62
|
+
It requires the caller to explicitly attest the input is complete, a recognized
|
|
63
|
+
positive summary line, and no diagnostics, unknown content or omissions. If there are
|
|
64
|
+
recognized failures, `diagnostics_detected` is reported even for incomplete
|
|
65
|
+
input; consult `coverage.incomplete` separately. Missing or truncated evidence
|
|
66
|
+
never becomes a clean result.
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
Python 3.10+. Install from source so the official MCP SDK dependency is present;
|
|
71
|
+
package access is needed only for installation.
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
git clone https://github.com/ahmedsaeed1-eng/loglens-mcp.git
|
|
75
|
+
cd loglens-mcp
|
|
76
|
+
python -m venv .venv
|
|
77
|
+
# Activate the virtual environment for your OS.
|
|
78
|
+
python -m pip install .
|
|
79
|
+
python -m loglens_mcp serve
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
For a client supporting stdio MCP, adapt this configuration to its documentation:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"mcpServers": {
|
|
87
|
+
"loglens": {
|
|
88
|
+
"command": "/absolute/path/to/venv/bin/python",
|
|
89
|
+
"args": ["-m", "loglens_mcp", "serve"]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
On Windows use the virtual environment's Python executable and escape backslashes
|
|
96
|
+
in JSON. The official Python MCP SDK client was tested; specific Codex and Claude
|
|
97
|
+
product UIs were not tested.
|
|
98
|
+
|
|
99
|
+
## Example
|
|
100
|
+
|
|
101
|
+
The CLI reads an explicit JSON object from stdin and writes compact JSON to stdout.
|
|
102
|
+
It does not read source paths or invoke commands. The example file is supplied
|
|
103
|
+
by the caller via shell redirection.
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
python -m loglens_mcp summarize < examples/build.json
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
MCP tool: `summarize_build_log(log, complete=false, max_chars=16000)`.
|
|
110
|
+
The returned string is compact JSON. `max_chars` (1,000–100,000) strictly
|
|
111
|
+
bounds the returned JSON content, not protocol framing. Oversized input is
|
|
112
|
+
rejected rather than silently truncated. Omission counts report groups,
|
|
113
|
+
underlying diagnostic occurrences, unknown lines, summary lines and omitted
|
|
114
|
+
numbered occurrences in retained groups. Diagnostic excerpts are prioritized
|
|
115
|
+
by severity, then source position, before summaries and unknown excerpts.
|
|
116
|
+
|
|
117
|
+
The metadata reports input/output characters and UTF-8 bytes and signed
|
|
118
|
+
reductions. Negative reductions mean the report is larger than the input, which
|
|
119
|
+
is common for short logs. Repeated large logs can yield smaller output,
|
|
120
|
+
depending on budget and structure; no token-saving estimate is made.
|
|
121
|
+
|
|
122
|
+
Avoid submitting secrets, private records, or security/network/attack logs.
|
|
123
|
+
LogLens is not a redaction or data-classification service. It processes the
|
|
124
|
+
supplied strings as data and cannot validate that their details are safe to share.
|
|
125
|
+
|
|
126
|
+
## Tests
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
python -m unittest discover -s tests -v
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Tests cover repeated diagnostics, supported formats, line accounting, unknown
|
|
133
|
+
content, limits, omitted evidence, byte/character metrics, CLI, and a real
|
|
134
|
+
MCP stdio session using the official SDK. Local Python 3.12 tests passed;
|
|
135
|
+
CI is configured for Python 3.10/3.12 on Windows, Linux and macOS.
|
|
136
|
+
Remote workflow status is reflected by its live badge.
|
|
137
|
+
|
|
138
|
+
MIT. [License](LICENSE) · [Credits](THIRD_PARTY.md)
|
|
139
|
+
|
|
140
|
+
## Distribution and MCP launch
|
|
141
|
+
|
|
142
|
+
After installation, `loglens-mcp` starts the same stdio MCP server as the module invocation above.
|
|
143
|
+
Once the version is published to PyPI, an MCP client with `uvx` can launch it using:
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
uvx loglens-mcp==0.1.0
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This repository contains registry metadata and a manually dispatched packaging workflow.
|
|
150
|
+
Package and MCP registry publication are separate steps; the metadata alone does not publish them.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# LogLens MCP
|
|
4
|
+
|
|
5
|
+
<!-- mcp-name: io.github.ahmedsaeed1-eng/loglens-mcp -->
|
|
6
|
+
|
|
7
|
+
**Keep the evidence. Bound the output. Make omissions visible.**
|
|
8
|
+
|
|
9
|
+
[](https://github.com/ahmedsaeed1-eng/loglens-mcp/stargazers) [](https://github.com/ahmedsaeed1-eng/loglens-mcp/actions/workflows/ci.yml)
|
|
10
|
+
|
|
11
|
+
|  |  |  |
|
|
12
|
+
| :---: | :---: | :---: |
|
|
13
|
+
|
|
14
|
+
LogLens is an offline tool for explicitly supplied, benign compilation and unit-test
|
|
15
|
+
logs. It classifies familiar diagnostic lines, groups exact repeated lines,
|
|
16
|
+
retains numbered excerpts and reports omissions. It never runs the build,
|
|
17
|
+
retrieves logs, intercepts tools, operates sessions, or accesses files and networks.
|
|
18
|
+
It is not a security log analyzer.
|
|
19
|
+
|
|
20
|
+
## Motivation
|
|
21
|
+
|
|
22
|
+
Reports in [Codex issue #44305](https://github.com/openai/codex/issues/44305)
|
|
23
|
+
and [Claude Code issue #49048](https://github.com/anthropics/claude-code/issues/49048)
|
|
24
|
+
describe context growth from tool loops or request output filtering.
|
|
25
|
+
LogLens is an independent implementation of bounded build/test log summaries,
|
|
26
|
+
not an official fix for either product. It measures actual JSON output
|
|
27
|
+
characters and UTF-8 bytes, not token counts, savings, or cost.
|
|
28
|
+
|
|
29
|
+
## Input → report
|
|
30
|
+
|
|
31
|
+
| Stage | Behavior |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Accept | Explicit UTF-8 log string (up to 256 KiB / 10,000 lines) |
|
|
34
|
+
| Recognize | Common TypeScript, Dart, Gradle/Kotlin, pytest, Jest/Vitest line shapes |
|
|
35
|
+
| Group | Exact repeated raw diagnostic lines, not inferred root cause |
|
|
36
|
+
| Preserve | Source line numbers, excerpts, raw-line SHA-256 identity |
|
|
37
|
+
| Bound | Explicit omission counts, coverage totals, maximum JSON characters |
|
|
38
|
+
| Report | Diagnostics detected, incomplete, or no recognized diagnostic lines |
|
|
39
|
+
|
|
40
|
+
The parser is deliberately conservative and line-oriented. It does not parse
|
|
41
|
+
all tool versions, stack traces or multiline exceptions. Unknown lines are
|
|
42
|
+
not discarded silently; they are counted and some are included with evidence
|
|
43
|
+
line numbers. ANSI color codes are stripped for display and other control
|
|
44
|
+
characters escaped; raw grouping still uses the original line. Each group
|
|
45
|
+
retains the first 12 line numbers and counts any remaining ones. Excerpts are
|
|
46
|
+
limited to 220 characters plus an ellipsis.
|
|
47
|
+
|
|
48
|
+
Output status `no_recognized_diagnostics` is not a successful build verdict.
|
|
49
|
+
It requires the caller to explicitly attest the input is complete, a recognized
|
|
50
|
+
positive summary line, and no diagnostics, unknown content or omissions. If there are
|
|
51
|
+
recognized failures, `diagnostics_detected` is reported even for incomplete
|
|
52
|
+
input; consult `coverage.incomplete` separately. Missing or truncated evidence
|
|
53
|
+
never becomes a clean result.
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
Python 3.10+. Install from source so the official MCP SDK dependency is present;
|
|
58
|
+
package access is needed only for installation.
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
git clone https://github.com/ahmedsaeed1-eng/loglens-mcp.git
|
|
62
|
+
cd loglens-mcp
|
|
63
|
+
python -m venv .venv
|
|
64
|
+
# Activate the virtual environment for your OS.
|
|
65
|
+
python -m pip install .
|
|
66
|
+
python -m loglens_mcp serve
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
For a client supporting stdio MCP, adapt this configuration to its documentation:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"mcpServers": {
|
|
74
|
+
"loglens": {
|
|
75
|
+
"command": "/absolute/path/to/venv/bin/python",
|
|
76
|
+
"args": ["-m", "loglens_mcp", "serve"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
On Windows use the virtual environment's Python executable and escape backslashes
|
|
83
|
+
in JSON. The official Python MCP SDK client was tested; specific Codex and Claude
|
|
84
|
+
product UIs were not tested.
|
|
85
|
+
|
|
86
|
+
## Example
|
|
87
|
+
|
|
88
|
+
The CLI reads an explicit JSON object from stdin and writes compact JSON to stdout.
|
|
89
|
+
It does not read source paths or invoke commands. The example file is supplied
|
|
90
|
+
by the caller via shell redirection.
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
python -m loglens_mcp summarize < examples/build.json
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
MCP tool: `summarize_build_log(log, complete=false, max_chars=16000)`.
|
|
97
|
+
The returned string is compact JSON. `max_chars` (1,000–100,000) strictly
|
|
98
|
+
bounds the returned JSON content, not protocol framing. Oversized input is
|
|
99
|
+
rejected rather than silently truncated. Omission counts report groups,
|
|
100
|
+
underlying diagnostic occurrences, unknown lines, summary lines and omitted
|
|
101
|
+
numbered occurrences in retained groups. Diagnostic excerpts are prioritized
|
|
102
|
+
by severity, then source position, before summaries and unknown excerpts.
|
|
103
|
+
|
|
104
|
+
The metadata reports input/output characters and UTF-8 bytes and signed
|
|
105
|
+
reductions. Negative reductions mean the report is larger than the input, which
|
|
106
|
+
is common for short logs. Repeated large logs can yield smaller output,
|
|
107
|
+
depending on budget and structure; no token-saving estimate is made.
|
|
108
|
+
|
|
109
|
+
Avoid submitting secrets, private records, or security/network/attack logs.
|
|
110
|
+
LogLens is not a redaction or data-classification service. It processes the
|
|
111
|
+
supplied strings as data and cannot validate that their details are safe to share.
|
|
112
|
+
|
|
113
|
+
## Tests
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
python -m unittest discover -s tests -v
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Tests cover repeated diagnostics, supported formats, line accounting, unknown
|
|
120
|
+
content, limits, omitted evidence, byte/character metrics, CLI, and a real
|
|
121
|
+
MCP stdio session using the official SDK. Local Python 3.12 tests passed;
|
|
122
|
+
CI is configured for Python 3.10/3.12 on Windows, Linux and macOS.
|
|
123
|
+
Remote workflow status is reflected by its live badge.
|
|
124
|
+
|
|
125
|
+
MIT. [License](LICENSE) · [Credits](THIRD_PARTY.md)
|
|
126
|
+
|
|
127
|
+
## Distribution and MCP launch
|
|
128
|
+
|
|
129
|
+
After installation, `loglens-mcp` starts the same stdio MCP server as the module invocation above.
|
|
130
|
+
Once the version is published to PyPI, an MCP client with `uvx` can launch it using:
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
uvx loglens-mcp==0.1.0
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
This repository contains registry metadata and a manually dispatched packaging workflow.
|
|
137
|
+
Package and MCP registry publication are separate steps; the metadata alone does not publish them.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 820 225" role="img" aria-label="LogLens diagnostic focusing diagram">
|
|
2
|
+
<rect width="820" height="225" rx="16" fill="#101b1e"/>
|
|
3
|
+
<g fill="#152f32" stroke="#5a857b" stroke-width="1">
|
|
4
|
+
<rect x="32" y="88" width="232" height="22" rx="4"/><rect x="32" y="115" width="232" height="22" rx="4"/><rect x="32" y="142" width="232" height="22" rx="4"/>
|
|
5
|
+
</g><g fill="#9dceb9" font-size="13" font-family="monospace"><text x="44" y="103">0042 FAIL fixture</text><text x="44" y="130">0043 FAIL fixture</text><text x="44" y="157">0044 context...</text></g>
|
|
6
|
+
<path d="M270 126h104m72 0h102" stroke="#85cbb2" stroke-dasharray="8 5" stroke-width="3"/>
|
|
7
|
+
<circle cx="410" cy="126" r="39" stroke="#f4ae62" stroke-width="7" fill="#14302d"/>
|
|
8
|
+
<path d="m437 153 28 28" stroke="#f4ae62" stroke-width="9" stroke-linecap="round"/>
|
|
9
|
+
<rect x="549" y="87" width="238" height="78" rx="5" fill="#203b34" stroke="#90c8a7" stroke-width="1.5"/>
|
|
10
|
+
<g fill="#f7d2a0" font-size="15" font-family="monospace"><text x="566" y="115">FAIL ×2 · lines 42–43</text><text x="566" y="140">unknown ×1 · line 44</text></g>
|
|
11
|
+
<text x="32" y="52" font-size="30" font-family="sans-serif" font-weight="bold" fill="#d4eddf">LogLens MCP</text>
|
|
12
|
+
<text x="788" y="51" font-size="14" font-family="monospace" fill="#86c9a9" text-anchor="end">BUILD / TEST OUTPUT</text>
|
|
13
|
+
<text x="32" y="204" font-size="14" font-family="monospace" fill="#97b5ac">Keep the evidence. Bound the output. Make omissions visible.</text>
|
|
14
|
+
</svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"log":"src/app.ts(4,8): error TS2322: Type mismatch\nsrc/app.ts(4,8): error TS2322: Type mismatch\n> Task :app:compileDebugKotlin FAILED\nSome additional context\nBUILD FAILED in 3s","complete":false,"max_chars":8000}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
from .core import summarize,serialize,MAX_INPUT_BYTES
|
|
5
|
+
|
|
6
|
+
def serve():
|
|
7
|
+
from mcp.server.fastmcp import FastMCP
|
|
8
|
+
mcp=FastMCP("LogLens",instructions="Classify explicitly supplied benign compile and test logs. Never retrieve logs, run commands, infer security findings, or verify outcomes independently.")
|
|
9
|
+
@mcp.tool()
|
|
10
|
+
def summarize_build_log(log: str,complete: bool=False,max_chars: int=16000)->str:
|
|
11
|
+
"""Return bounded compact JSON, preserving line counts, excerpts and omitted evidence."""
|
|
12
|
+
return serialize(summarize(log,complete,max_chars))
|
|
13
|
+
mcp.run(transport="stdio")
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
parser=argparse.ArgumentParser(description="Offline build/test log summaries")
|
|
17
|
+
parser.add_argument("action",choices=["summarize","serve"])
|
|
18
|
+
args=parser.parse_args()
|
|
19
|
+
if args.action=="serve": serve(); return 0
|
|
20
|
+
try:
|
|
21
|
+
raw=sys.stdin.buffer.read(MAX_INPUT_BYTES*6+1)
|
|
22
|
+
if len(raw)>MAX_INPUT_BYTES*6: raise ValueError("JSON input too large")
|
|
23
|
+
data=json.loads(raw)
|
|
24
|
+
if not isinstance(data,dict) or set(data)-{"log","complete","max_chars"}: raise ValueError("Expected log, optional complete and max_chars")
|
|
25
|
+
result=summarize(**data)
|
|
26
|
+
sys.stdout.buffer.write(serialize(result).encode("utf-8"))
|
|
27
|
+
return 0
|
|
28
|
+
except (TypeError,ValueError,UnicodeError) as e:
|
|
29
|
+
print(f"Error: {e}",file=sys.stderr); return 2
|
|
30
|
+
if __name__=="__main__": raise SystemExit(main())
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Bounded summaries of caller-supplied build and test logs. No retrieval."""
|
|
2
|
+
import json
|
|
3
|
+
import re
|
|
4
|
+
import hashlib
|
|
5
|
+
|
|
6
|
+
MAX_INPUT_BYTES=262144
|
|
7
|
+
MAX_LINES=10000
|
|
8
|
+
MAX_EXCERPT=220
|
|
9
|
+
MAX_LINE_NUMBERS=12
|
|
10
|
+
PATTERNS=[
|
|
11
|
+
("typescript",re.compile(r"^(?P<location>.+?\(\d+,\d+\)):\s*(?P<severity>error|warning)\s+(?P<code>TS\d+):\s*(?P<message>.*)$")),
|
|
12
|
+
("typescript",re.compile(r"^(?P<location>.+?:\d+:\d+)\s+-\s+(?P<severity>error|warning)\s+(?P<code>TS\d+):\s*(?P<message>.*)$")),
|
|
13
|
+
("dart",re.compile(r"^\s*(?P<severity>error|warning|info)\s*[•-]\s*(?P<message>.*?)\s*[•-]\s*(?P<location>.+?:\d+:\d+)\s*[•-]\s*(?P<code>[a-z_]+)\s*$")),
|
|
14
|
+
("dart",re.compile(r"^(?P<location>.+?:\d+:\d+):\s*(?P<severity>Error|Warning):\s*(?P<message>.*)$")),
|
|
15
|
+
("gradle",re.compile(r"^> Task (?P<location>:[\w:.-]+) (?P<severity>FAILED)\s*$")),
|
|
16
|
+
("gradle",re.compile(r"^(?P<severity>e|w):\s*(?P<location>.+?:\d+:\d+):?\s*(?P<message>.+)$")),
|
|
17
|
+
("pytest",re.compile(r"^(?P<severity>FAILED|ERROR)\s+(?P<location>[^\s]+)(?:\s+-\s+(?P<message>.*))?$")),
|
|
18
|
+
("jest-vitest",re.compile(r"^\s*(?P<severity>FAIL)\s+(?P<location>[^\s]+)(?:\s+(?P<message>.*))?$")),
|
|
19
|
+
]
|
|
20
|
+
ANSI=re.compile(r"\x1b\[[0-9;]*m")
|
|
21
|
+
CONTROL=re.compile(r"[\x00-\x08\x0b-\x1f\x7f]")
|
|
22
|
+
SUMMARY=re.compile(r"^\s*(?:=+\s*(?:\d+\s+(?:passed|failed|errors?|skipped|warnings?)\b[^=]*)=+|(?:Test Suites|Tests|Snapshots|Time):\s+.+|BUILD (?:SUCCESSFUL|FAILED)(?: in .*)?|(?:✓|✔)\s+.*)$")
|
|
23
|
+
FAIL_SUMMARY=re.compile(r"\b(?:[1-9]\d*\s+(?:failed|errors?|warnings?)|BUILD FAILED)\b",re.I)
|
|
24
|
+
PASS_SUMMARY=re.compile(r"\b(?:[1-9]\d*\s+passed|BUILD SUCCESSFUL)\b",re.I)
|
|
25
|
+
|
|
26
|
+
def safe_text(line):
|
|
27
|
+
return CONTROL.sub(lambda m:f"\\x{ord(m.group()):02x}",ANSI.sub("",line))
|
|
28
|
+
|
|
29
|
+
def clipped(value):
|
|
30
|
+
return value[:MAX_EXCERPT]+("…" if len(value)>MAX_EXCERPT else "")
|
|
31
|
+
|
|
32
|
+
def serialize(value):
|
|
33
|
+
return json.dumps(value,ensure_ascii=False,separators=(",",":"),allow_nan=False)
|
|
34
|
+
|
|
35
|
+
def classify(raw):
|
|
36
|
+
line=safe_text(raw)
|
|
37
|
+
for family,pattern in PATTERNS:
|
|
38
|
+
m=pattern.fullmatch(line)
|
|
39
|
+
if not m: continue
|
|
40
|
+
d=m.groupdict()
|
|
41
|
+
severity=d.get("severity","").lower()
|
|
42
|
+
severity="error" if severity in ("e","error","failed","fail") else "warning" if severity in ("w","warning") else "info"
|
|
43
|
+
return family,severity,d.get("location","") or "",d.get("code","") or "",d.get("message","") or "",line
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
def summarize(log,complete=False,max_chars=16000):
|
|
47
|
+
if not isinstance(log,str): raise ValueError("log must be text")
|
|
48
|
+
if type(complete) is not bool: raise ValueError("complete must be a boolean")
|
|
49
|
+
if type(max_chars) is not int or not 1000<=max_chars<=100000: raise ValueError("max_chars must be 1000–100000")
|
|
50
|
+
try: raw_bytes=len(log.encode("utf-8"))
|
|
51
|
+
except UnicodeError: raise ValueError("Invalid UTF-8 text") from None
|
|
52
|
+
if raw_bytes>MAX_INPUT_BYTES: raise ValueError("Input exceeds 256 KiB; supply a smaller labeled excerpt")
|
|
53
|
+
lines=log.splitlines()
|
|
54
|
+
if len(lines)>MAX_LINES: raise ValueError("Input exceeds 10,000 lines")
|
|
55
|
+
groups={}
|
|
56
|
+
unknown=[]
|
|
57
|
+
summaries=[]
|
|
58
|
+
blank=0
|
|
59
|
+
recognized=0
|
|
60
|
+
unknown_count=0
|
|
61
|
+
summary_count=0
|
|
62
|
+
error_count=0
|
|
63
|
+
warning_count=0
|
|
64
|
+
fail_summary=False
|
|
65
|
+
pass_summary=False
|
|
66
|
+
clipped_count=0
|
|
67
|
+
for n,raw in enumerate(lines,1):
|
|
68
|
+
line=safe_text(raw)
|
|
69
|
+
if not line.strip():
|
|
70
|
+
blank+=1; continue
|
|
71
|
+
hit=classify(raw)
|
|
72
|
+
if hit:
|
|
73
|
+
recognized+=1
|
|
74
|
+
family,severity,location,code,message,display=hit
|
|
75
|
+
if severity=="error": error_count+=1
|
|
76
|
+
elif severity=="warning": warning_count+=1
|
|
77
|
+
# Group exact raw lines, not inferred root causes.
|
|
78
|
+
key=(family,severity,raw)
|
|
79
|
+
if key not in groups:
|
|
80
|
+
groups[key]={"family":family,"severity":severity,"location":clipped(location),"code":clipped(code),"message":clipped(message),"excerpt":clipped(display),"count":0,"lines":[],"omitted_line_numbers":0,"raw_sha256":hashlib.sha256(raw.encode("utf-8")).hexdigest(),"excerpt_truncated":any(len(v)>MAX_EXCERPT for v in (location,code,message,display))}
|
|
81
|
+
item=groups[key]; item["count"]+=1
|
|
82
|
+
if len(item["lines"])<MAX_LINE_NUMBERS: item["lines"].append(n)
|
|
83
|
+
else: item["omitted_line_numbers"]+=1
|
|
84
|
+
elif SUMMARY.fullmatch(line):
|
|
85
|
+
summary_count+=1
|
|
86
|
+
fail_summary |= bool(FAIL_SUMMARY.search(line))
|
|
87
|
+
pass_summary |= bool(PASS_SUMMARY.search(line))
|
|
88
|
+
summaries.append({"line":n,"excerpt":clipped(line),"excerpt_truncated":len(line)>MAX_EXCERPT})
|
|
89
|
+
else:
|
|
90
|
+
unknown_count+=1
|
|
91
|
+
unknown.append({"line":n,"excerpt":clipped(line),"excerpt_truncated":len(line)>MAX_EXCERPT})
|
|
92
|
+
if len(line)>MAX_EXCERPT: clipped_count+=1
|
|
93
|
+
result={"status":"incomplete","complete_claim":complete,"coverage":{"input_lines":len(lines),"diagnostic_lines":recognized,"unknown_lines":unknown_count,"summary_lines":summary_count,"blank_lines":blank,"error_lines":error_count,"warning_lines":warning_count,"input_excerpt_truncations":clipped_count},
|
|
94
|
+
"diagnostics":[],"unknown":[],"summaries":[],
|
|
95
|
+
"omitted":{"diagnostic_groups":len(groups),"diagnostic_lines":recognized,"unknown_lines":unknown_count,"summary_lines":summary_count,"line_numbers":0},
|
|
96
|
+
"size":{"input_chars":len(log),"input_utf8_bytes":raw_bytes,"output_chars":0,"output_utf8_bytes":0,"char_reduction":0,"byte_reduction":0},
|
|
97
|
+
"note":"Only supplied lines classified; no execution or independent build verification. Unknown excerpts may contain failures."}
|
|
98
|
+
def metrics():
|
|
99
|
+
# Recalculate self-referential serialized length to a fixed point.
|
|
100
|
+
for _ in range(15):
|
|
101
|
+
serialized=serialize(result); c=len(serialized); b=len(serialized.encode("utf-8"))
|
|
102
|
+
value={"input_chars":len(log),"input_utf8_bytes":raw_bytes,"output_chars":c,"output_utf8_bytes":b,"char_reduction":len(log)-c,"byte_reduction":raw_bytes-b}
|
|
103
|
+
if result["size"]==value: return
|
|
104
|
+
result["size"]=value
|
|
105
|
+
def status():
|
|
106
|
+
omitted=result["omitted"]
|
|
107
|
+
incomplete=(not complete or unknown_count or clipped_count or any(omitted.values()))
|
|
108
|
+
result["status"]="diagnostics_detected" if error_count or warning_count or fail_summary else "incomplete" if incomplete or not pass_summary else "no_recognized_diagnostics"
|
|
109
|
+
result["coverage"]["incomplete"]=bool(incomplete or not pass_summary)
|
|
110
|
+
status(); metrics()
|
|
111
|
+
if len(serialize(result))>max_chars: raise ValueError("Budget too small for coverage metadata")
|
|
112
|
+
rank={"error":0,"warning":1,"info":2}
|
|
113
|
+
categories=[("diagnostics",sorted(groups.values(),key=lambda x:(rank[x["severity"]],x["lines"][0])),"diagnostic_groups"),("summaries",summaries,"summary_lines"),("unknown",unknown,"unknown_lines")]
|
|
114
|
+
for name,items,omission in categories:
|
|
115
|
+
for item in items:
|
|
116
|
+
result[name].append(item)
|
|
117
|
+
result["omitted"][omission]-=1
|
|
118
|
+
if name=="diagnostics":
|
|
119
|
+
result["omitted"]["diagnostic_lines"]-=item["count"]
|
|
120
|
+
result["omitted"]["line_numbers"]+=item["omitted_line_numbers"]
|
|
121
|
+
status(); metrics()
|
|
122
|
+
if len(serialize(result))>max_chars:
|
|
123
|
+
result[name].pop()
|
|
124
|
+
result["omitted"][omission]+=1
|
|
125
|
+
if name=="diagnostics":
|
|
126
|
+
result["omitted"]["diagnostic_lines"]+=item["count"]
|
|
127
|
+
result["omitted"]["line_numbers"]-=item["omitted_line_numbers"]
|
|
128
|
+
status(); metrics()
|
|
129
|
+
# Keep remaining entries explicitly omitted, not silently dropped.
|
|
130
|
+
break
|
|
131
|
+
status(); metrics()
|
|
132
|
+
if len(serialize(result))>max_chars: raise ValueError("Budget cannot contain coverage metadata")
|
|
133
|
+
return result
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: loglens-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline bounded compile and test log summaries
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Repository, https://github.com/ahmedsaeed1-eng/loglens-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/ahmedsaeed1-eng/loglens-mcp/issues
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: mcp<2,>=1.29
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
# LogLens MCP
|
|
17
|
+
|
|
18
|
+
<!-- mcp-name: io.github.ahmedsaeed1-eng/loglens-mcp -->
|
|
19
|
+
|
|
20
|
+
**Keep the evidence. Bound the output. Make omissions visible.**
|
|
21
|
+
|
|
22
|
+
[](https://github.com/ahmedsaeed1-eng/loglens-mcp/stargazers) [](https://github.com/ahmedsaeed1-eng/loglens-mcp/actions/workflows/ci.yml)
|
|
23
|
+
|
|
24
|
+
|  |  |  |
|
|
25
|
+
| :---: | :---: | :---: |
|
|
26
|
+
|
|
27
|
+
LogLens is an offline tool for explicitly supplied, benign compilation and unit-test
|
|
28
|
+
logs. It classifies familiar diagnostic lines, groups exact repeated lines,
|
|
29
|
+
retains numbered excerpts and reports omissions. It never runs the build,
|
|
30
|
+
retrieves logs, intercepts tools, operates sessions, or accesses files and networks.
|
|
31
|
+
It is not a security log analyzer.
|
|
32
|
+
|
|
33
|
+
## Motivation
|
|
34
|
+
|
|
35
|
+
Reports in [Codex issue #44305](https://github.com/openai/codex/issues/44305)
|
|
36
|
+
and [Claude Code issue #49048](https://github.com/anthropics/claude-code/issues/49048)
|
|
37
|
+
describe context growth from tool loops or request output filtering.
|
|
38
|
+
LogLens is an independent implementation of bounded build/test log summaries,
|
|
39
|
+
not an official fix for either product. It measures actual JSON output
|
|
40
|
+
characters and UTF-8 bytes, not token counts, savings, or cost.
|
|
41
|
+
|
|
42
|
+
## Input → report
|
|
43
|
+
|
|
44
|
+
| Stage | Behavior |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| Accept | Explicit UTF-8 log string (up to 256 KiB / 10,000 lines) |
|
|
47
|
+
| Recognize | Common TypeScript, Dart, Gradle/Kotlin, pytest, Jest/Vitest line shapes |
|
|
48
|
+
| Group | Exact repeated raw diagnostic lines, not inferred root cause |
|
|
49
|
+
| Preserve | Source line numbers, excerpts, raw-line SHA-256 identity |
|
|
50
|
+
| Bound | Explicit omission counts, coverage totals, maximum JSON characters |
|
|
51
|
+
| Report | Diagnostics detected, incomplete, or no recognized diagnostic lines |
|
|
52
|
+
|
|
53
|
+
The parser is deliberately conservative and line-oriented. It does not parse
|
|
54
|
+
all tool versions, stack traces or multiline exceptions. Unknown lines are
|
|
55
|
+
not discarded silently; they are counted and some are included with evidence
|
|
56
|
+
line numbers. ANSI color codes are stripped for display and other control
|
|
57
|
+
characters escaped; raw grouping still uses the original line. Each group
|
|
58
|
+
retains the first 12 line numbers and counts any remaining ones. Excerpts are
|
|
59
|
+
limited to 220 characters plus an ellipsis.
|
|
60
|
+
|
|
61
|
+
Output status `no_recognized_diagnostics` is not a successful build verdict.
|
|
62
|
+
It requires the caller to explicitly attest the input is complete, a recognized
|
|
63
|
+
positive summary line, and no diagnostics, unknown content or omissions. If there are
|
|
64
|
+
recognized failures, `diagnostics_detected` is reported even for incomplete
|
|
65
|
+
input; consult `coverage.incomplete` separately. Missing or truncated evidence
|
|
66
|
+
never becomes a clean result.
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
Python 3.10+. Install from source so the official MCP SDK dependency is present;
|
|
71
|
+
package access is needed only for installation.
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
git clone https://github.com/ahmedsaeed1-eng/loglens-mcp.git
|
|
75
|
+
cd loglens-mcp
|
|
76
|
+
python -m venv .venv
|
|
77
|
+
# Activate the virtual environment for your OS.
|
|
78
|
+
python -m pip install .
|
|
79
|
+
python -m loglens_mcp serve
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
For a client supporting stdio MCP, adapt this configuration to its documentation:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"mcpServers": {
|
|
87
|
+
"loglens": {
|
|
88
|
+
"command": "/absolute/path/to/venv/bin/python",
|
|
89
|
+
"args": ["-m", "loglens_mcp", "serve"]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
On Windows use the virtual environment's Python executable and escape backslashes
|
|
96
|
+
in JSON. The official Python MCP SDK client was tested; specific Codex and Claude
|
|
97
|
+
product UIs were not tested.
|
|
98
|
+
|
|
99
|
+
## Example
|
|
100
|
+
|
|
101
|
+
The CLI reads an explicit JSON object from stdin and writes compact JSON to stdout.
|
|
102
|
+
It does not read source paths or invoke commands. The example file is supplied
|
|
103
|
+
by the caller via shell redirection.
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
python -m loglens_mcp summarize < examples/build.json
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
MCP tool: `summarize_build_log(log, complete=false, max_chars=16000)`.
|
|
110
|
+
The returned string is compact JSON. `max_chars` (1,000–100,000) strictly
|
|
111
|
+
bounds the returned JSON content, not protocol framing. Oversized input is
|
|
112
|
+
rejected rather than silently truncated. Omission counts report groups,
|
|
113
|
+
underlying diagnostic occurrences, unknown lines, summary lines and omitted
|
|
114
|
+
numbered occurrences in retained groups. Diagnostic excerpts are prioritized
|
|
115
|
+
by severity, then source position, before summaries and unknown excerpts.
|
|
116
|
+
|
|
117
|
+
The metadata reports input/output characters and UTF-8 bytes and signed
|
|
118
|
+
reductions. Negative reductions mean the report is larger than the input, which
|
|
119
|
+
is common for short logs. Repeated large logs can yield smaller output,
|
|
120
|
+
depending on budget and structure; no token-saving estimate is made.
|
|
121
|
+
|
|
122
|
+
Avoid submitting secrets, private records, or security/network/attack logs.
|
|
123
|
+
LogLens is not a redaction or data-classification service. It processes the
|
|
124
|
+
supplied strings as data and cannot validate that their details are safe to share.
|
|
125
|
+
|
|
126
|
+
## Tests
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
python -m unittest discover -s tests -v
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Tests cover repeated diagnostics, supported formats, line accounting, unknown
|
|
133
|
+
content, limits, omitted evidence, byte/character metrics, CLI, and a real
|
|
134
|
+
MCP stdio session using the official SDK. Local Python 3.12 tests passed;
|
|
135
|
+
CI is configured for Python 3.10/3.12 on Windows, Linux and macOS.
|
|
136
|
+
Remote workflow status is reflected by its live badge.
|
|
137
|
+
|
|
138
|
+
MIT. [License](LICENSE) · [Credits](THIRD_PARTY.md)
|
|
139
|
+
|
|
140
|
+
## Distribution and MCP launch
|
|
141
|
+
|
|
142
|
+
After installation, `loglens-mcp` starts the same stdio MCP server as the module invocation above.
|
|
143
|
+
Once the version is published to PyPI, an MCP client with `uvx` can launch it using:
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
uvx loglens-mcp==0.1.0
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This repository contains registry metadata and a manually dispatched packaging workflow.
|
|
150
|
+
Package and MCP registry publication are separate steps; the metadata alone does not publish them.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
THIRD_PARTY.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
server.json
|
|
7
|
+
assets/logo.svg
|
|
8
|
+
examples/build.json
|
|
9
|
+
loglens_mcp/__init__.py
|
|
10
|
+
loglens_mcp/__main__.py
|
|
11
|
+
loglens_mcp/core.py
|
|
12
|
+
loglens_mcp.egg-info/PKG-INFO
|
|
13
|
+
loglens_mcp.egg-info/SOURCES.txt
|
|
14
|
+
loglens_mcp.egg-info/dependency_links.txt
|
|
15
|
+
loglens_mcp.egg-info/entry_points.txt
|
|
16
|
+
loglens_mcp.egg-info/requires.txt
|
|
17
|
+
loglens_mcp.egg-info/top_level.txt
|
|
18
|
+
tests/test_core.py
|
|
19
|
+
tests/test_protocol.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mcp<2,>=1.29
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
loglens_mcp
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires=["setuptools>=77"]
|
|
3
|
+
build-backend="setuptools.build_meta"
|
|
4
|
+
[project]
|
|
5
|
+
name="loglens-mcp"
|
|
6
|
+
version="0.1.0"
|
|
7
|
+
description="Offline bounded compile and test log summaries"
|
|
8
|
+
readme="README.md"
|
|
9
|
+
requires-python=">=3.10"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
dependencies=["mcp>=1.29,<2"]
|
|
13
|
+
[project.scripts]
|
|
14
|
+
loglens-mcp = "loglens_mcp.__main__:serve"
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Repository = "https://github.com/ahmedsaeed1-eng/loglens-mcp"
|
|
18
|
+
Issues = "https://github.com/ahmedsaeed1-eng/loglens-mcp/issues"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools.packages.find]
|
|
21
|
+
include=["loglens_mcp*"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.ahmedsaeed1-eng/loglens-mcp",
|
|
4
|
+
"title": "LogLens MCP",
|
|
5
|
+
"description": "Offline bounded summaries of explicitly supplied benign build and test logs",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "https://github.com/ahmedsaeed1-eng/loglens-mcp",
|
|
8
|
+
"source": "github"
|
|
9
|
+
},
|
|
10
|
+
"version": "0.1.0",
|
|
11
|
+
"packages": [
|
|
12
|
+
{
|
|
13
|
+
"registryType": "pypi",
|
|
14
|
+
"registryBaseUrl": "https://pypi.org",
|
|
15
|
+
"identifier": "loglens-mcp",
|
|
16
|
+
"version": "0.1.0",
|
|
17
|
+
"runtimeHint": "uvx",
|
|
18
|
+
"transport": {
|
|
19
|
+
"type": "stdio"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from loglens_mcp.core import *
|
|
3
|
+
class Summary(unittest.TestCase):
|
|
4
|
+
def test_families_and_lines(self):
|
|
5
|
+
lines=["src/app.ts(4,8): error TS2322: Type mismatch","src/app.ts(4,8): error TS2322: Type mismatch","FAILED tests/test_a.py::test_a - AssertionError: no","FAIL src/test.js (2 s)","> Task :app:compileDebugKotlin FAILED","error • Wrong value • lib/app.dart:4:8 • invalid_assignment","unknown continuation", "", "BUILD FAILED in 3s"]
|
|
6
|
+
result=summarize("\n".join(lines))
|
|
7
|
+
self.assertEqual(result["coverage"]["input_lines"],9)
|
|
8
|
+
self.assertEqual(result["coverage"]["diagnostic_lines"],6)
|
|
9
|
+
self.assertEqual(result["diagnostics"][0]["lines"],[1,2])
|
|
10
|
+
self.assertEqual(result["diagnostics"][0]["count"],2)
|
|
11
|
+
self.assertEqual(result["unknown"][0]["line"],7)
|
|
12
|
+
self.assertEqual(result["status"],"diagnostics_detected")
|
|
13
|
+
def test_never_clean_incomplete(self):
|
|
14
|
+
for text in ("unknown","", "BUILD SUCCESSFUL in 3s\nunknown"):
|
|
15
|
+
self.assertEqual(summarize(text,True)["status"],"incomplete")
|
|
16
|
+
self.assertEqual(summarize("BUILD SUCCESSFUL in 3s",False)["status"],"incomplete")
|
|
17
|
+
self.assertEqual(summarize("BUILD SUCCESSFUL in 3s",True)["status"],"no_recognized_diagnostics")
|
|
18
|
+
def test_budget_metrics(self):
|
|
19
|
+
text="\n".join(["FAILED tests/test_one.py::test_one - AssertionError"]*500+["unrecognized "+str(i) for i in range(200)])
|
|
20
|
+
result=summarize(text,max_chars=1600)
|
|
21
|
+
raw=serialize(result)
|
|
22
|
+
self.assertLessEqual(len(raw),1600)
|
|
23
|
+
self.assertEqual(result["size"]["output_chars"],len(raw))
|
|
24
|
+
self.assertEqual(result["size"]["output_utf8_bytes"],len(raw.encode()))
|
|
25
|
+
self.assertEqual(result["size"]["char_reduction"],len(text)-len(raw))
|
|
26
|
+
self.assertEqual(result["diagnostics"][0]["count"],500)
|
|
27
|
+
self.assertEqual(result["omitted"]["line_numbers"],488)
|
|
28
|
+
self.assertGreater(result["omitted"]["unknown_lines"],0)
|
|
29
|
+
self.assertTrue(result["coverage"]["incomplete"])
|
|
30
|
+
def test_exact_and_escaped(self):
|
|
31
|
+
s=summarize("FAIL abc.js\nFAIL abc.js\nFAIL abc.js different\n\x1b[31mFAIL x.js\x1b[0m\nother\x07")
|
|
32
|
+
self.assertEqual(len(s["diagnostics"]),3)
|
|
33
|
+
self.assertIn("\\x07",s["unknown"][0]["excerpt"])
|
|
34
|
+
def test_failure_summary_and_bounds(self):
|
|
35
|
+
self.assertEqual(summarize("===== 2 failed, 1 passed in 1s =====",True)["status"],"diagnostics_detected")
|
|
36
|
+
for value in ("a"*262145,"\n"*10001):
|
|
37
|
+
with self.assertRaises(ValueError): summarize(value)
|
|
38
|
+
with self.assertRaises(ValueError): summarize("x",max_chars=999)
|
|
39
|
+
self.assertTrue(summarize("x"*1000,True)["coverage"]["incomplete"])
|
|
40
|
+
def test_coverage_totals(self):
|
|
41
|
+
r=summarize("FAIL a.js\nFAIL b.js\nnoise\nnoise\nBUILD SUCCESSFUL in 1s",True,1000)
|
|
42
|
+
c=r["coverage"]
|
|
43
|
+
self.assertEqual(sum(c[k] for k in ("blank_lines","summary_lines","unknown_lines","diagnostic_lines")),c["input_lines"])
|
|
44
|
+
self.assertEqual(sum(d["count"] for d in r["diagnostics"])+r["omitted"]["diagnostic_lines"],c["diagnostic_lines"])
|
|
45
|
+
self.assertEqual(len(r["unknown"])+r["omitted"]["unknown_lines"],c["unknown_lines"])
|
|
46
|
+
|
|
47
|
+
def test_summary_must_show_pass_evidence(self):
|
|
48
|
+
self.assertEqual(summarize("Tests: 3 total",True)["status"],"incomplete")
|
|
49
|
+
self.assertEqual(summarize("===== 1 passed, 2 warnings in 0s =====",True)["status"],"diagnostics_detected")
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import json,sys,subprocess,unittest
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from mcp import ClientSession, StdioServerParameters
|
|
4
|
+
from mcp.client.stdio import stdio_client
|
|
5
|
+
class Protocol(unittest.IsolatedAsyncioTestCase):
|
|
6
|
+
async def test_stdio(self):
|
|
7
|
+
async with stdio_client(StdioServerParameters(command=sys.executable,args=["-m","loglens_mcp","serve"])) as (reader,writer):
|
|
8
|
+
async with ClientSession(reader,writer) as session:
|
|
9
|
+
await session.initialize()
|
|
10
|
+
tools=await session.list_tools()
|
|
11
|
+
self.assertEqual([t.name for t in tools.tools],["summarize_build_log"])
|
|
12
|
+
r=await session.call_tool("summarize_build_log",{"log":"FAIL a.js","max_chars":2000})
|
|
13
|
+
self.assertFalse(r.isError,r)
|
|
14
|
+
self.assertEqual(json.loads(r.content[0].text)["coverage"]["error_lines"],1)
|
|
15
|
+
r=await session.call_tool("summarize_build_log",{"log":"FAIL a.js","max_chars":3})
|
|
16
|
+
self.assertTrue(r.isError)
|
|
17
|
+
class CLI(unittest.TestCase):
|
|
18
|
+
def test_cli(self):
|
|
19
|
+
r=subprocess.run([sys.executable,"-m","loglens_mcp","summarize"],input=Path("examples/build.json").read_bytes(),capture_output=True,check=True)
|
|
20
|
+
data=json.loads(r.stdout)
|
|
21
|
+
self.assertEqual(data["size"]["output_utf8_bytes"],len(r.stdout))
|
|
22
|
+
r=subprocess.run([sys.executable,"-m","loglens_mcp","summarize"],input=b"{}",capture_output=True)
|
|
23
|
+
self.assertEqual(r.returncode,2)
|