mo3ta-coverage 1.2.0 → 1.3.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.
package/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  mo3ta-coverage checks coverage for changed lines in a pull request. It finds changed source files, maps them to likely test files, runs Jest in a selected execution mode, and validates changed-line coverage against a threshold.
6
6
 
7
+ Project site: https://mo3ta.top/mo3ta-coverage/
8
+
7
9
  ## Demo
8
10
 
9
11
  https://github.com/user-attachments/assets/1139ca7a-69e6-4b41-ad24-ff20e083c4e0
@@ -311,6 +313,84 @@ mo3ta-coverage config --base origin/main --mode smart --depth 2
311
313
 
312
314
  This writes `.mo3ta-coverage.json` in the project root.
313
315
 
316
+ ## MCP server
317
+
318
+ `mo3ta-coverage` also ships an [MCP](https://modelcontextprotocol.io) server so an agent working in a local checkout can list the changed files, see which tests would run, and read the uncovered changed lines it should write tests for. The server calls the same functions as the CLI. It does not reimplement git diffs, test mapping, or lcov parsing.
319
+
320
+ The server is a second bin in this package, `mo3ta-coverage-mcp`, speaking MCP over stdio. It lives here rather than in a separate package so one publish ships it, and so it imports this repo's source directly. The CLI flags, stdout, and exit codes are unchanged; the [GitHub Action](https://github.com/MahmoudMabrok/mo3ta-coverage-action) keeps running `node index.js`.
321
+
322
+ The server requires Node.js 18 or newer. Each tool takes `root` (the checkout to inspect). When `root` is omitted, Claude Code's `CLAUDE_PROJECT_DIR` is used if it is set, otherwise the server process cwd. `useConfig` defaults to true: `base`, `mode`, and `depth` are read from `.mo3ta-coverage.json` when present, and explicit arguments override the file.
323
+
324
+ | Tool | Purpose |
325
+ | --- | --- |
326
+ | `list_changed_files` | List JS/TS files changed versus a base ref (or an explicit list). |
327
+ | `map_related_tests` | Map those files to the tests `fast`, `smart`, or `full` mode would run. |
328
+ | `check_changed_line_coverage` | Run the changed-line coverage check and return uncovered lines with source text. |
329
+
330
+ `check_changed_line_coverage` runs the repo's local Jest and writes `coverage/` there, same as the CLI. Jest is killed after `timeoutMs` (default 5 minutes) and only a tail of its output is returned. Pass `runTests: false` to grade an existing `lcov.info` without running tests. A missed threshold comes back as data (`ok: false` plus the uncovered lines), not a crashed tool. A missing git repo, a bad base ref, a missing Jest install, or a timeout comes back as a tool error with a `code` and a hint.
331
+
332
+ `full` mode still delegates discovery to `jest --findRelatedTests`. `map_related_tests` can only list the changed test files until a check actually runs Jest, matching `--dryRun`.
333
+
334
+ ### Run it
335
+
336
+ From a checkout, after `npm install`:
337
+
338
+ ```sh
339
+ node mcp/server.js
340
+ # or
341
+ npx --package . -- mo3ta-coverage-mcp
342
+ ```
343
+
344
+ Once this package is published, any project can start it without cloning the repo:
345
+
346
+ ```sh
347
+ npx -y --package mo3ta-coverage mo3ta-coverage-mcp
348
+ ```
349
+
350
+ The bin name and the package name differ, so `npx` needs `--package mo3ta-coverage` to install this package and then run the `mo3ta-coverage-mcp` binary.
351
+
352
+ ### Claude Desktop
353
+
354
+ Add this to `claude_desktop_config.json` (`~/Library/Application Support/Claude/` on macOS, `%APPDATA%\Claude\` on Windows):
355
+
356
+ ```json
357
+ {
358
+ "mcpServers": {
359
+ "mo3ta-coverage": {
360
+ "command": "npx",
361
+ "args": ["-y", "--package", "mo3ta-coverage", "mo3ta-coverage-mcp"]
362
+ }
363
+ }
364
+ }
365
+ ```
366
+
367
+ ### Cursor
368
+
369
+ Add this to `.cursor/mcp.json` in the project, or to Cursor's user MCP config:
370
+
371
+ ```json
372
+ {
373
+ "mcpServers": {
374
+ "mo3ta-coverage": {
375
+ "command": "npx",
376
+ "args": ["-y", "--package", "mo3ta-coverage", "mo3ta-coverage-mcp"]
377
+ }
378
+ }
379
+ }
380
+ ```
381
+
382
+ ### Claude Code
383
+
384
+ ```sh
385
+ claude mcp add mo3ta-coverage -- npx -y --package mo3ta-coverage mo3ta-coverage-mcp
386
+ ```
387
+
388
+ From a local checkout of this repo, point the command at the script instead:
389
+
390
+ ```sh
391
+ claude mcp add mo3ta-coverage -- node /absolute/path/to/mo3ta-coverage/mcp/server.js
392
+ ```
393
+
314
394
  ## How It Works
315
395
 
316
396
  1. Reads CLI options and saved config from [index.js](index.js).
@@ -325,7 +405,8 @@ This writes `.mo3ta-coverage.json` in the project root.
325
405
 
326
406
  ```sh
327
407
  npm install
328
- npm test
408
+ npm test # Jest, then the MCP server tests (node --test)
409
+ node mcp/server.js
329
410
  ```
330
411
 
331
412
  ## Security & dependencies
package/index.js CHANGED
@@ -15,7 +15,13 @@ function readConfig(quiet = false) {
15
15
  }
16
16
 
17
17
  if (fs.existsSync(CONFIG_PATH)) {
18
- return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
18
+ const raw = fs.readFileSync(CONFIG_PATH, 'utf8');
19
+ try {
20
+ return JSON.parse(raw);
21
+ } catch (error) {
22
+ console.error(`❌ Could not parse ${CONFIG_PATH}: ${error.message}`);
23
+ process.exit(1);
24
+ }
19
25
  }
20
26
  return {};
21
27
  }
@@ -56,7 +62,7 @@ Examples:
56
62
  $ mo3ta-coverage --mode smart --base origin/main --limit 80
57
63
  $ mo3ta-coverage --files src/a.js,src/b.ts --base origin/main
58
64
  $ mo3ta-coverage --filesFrom changed.txt --base origin/main
59
- $ mo3ta-coverage --dry-run true --files src/a.js,src/b.ts --base main
65
+ $ mo3ta-coverage --dryRun true --files src/a.js,src/b.ts --base main
60
66
  $ mo3ta-coverage --mode fast --showCovered true
61
67
  $ mo3ta-coverage --mode smart --base origin/main --ci true --ciReport coverage/report.md
62
68
  $ mo3ta-coverage config --mode smart --depth 2
@@ -0,0 +1,169 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import {
4
+ checkChangedLineCoverage,
5
+ listChangedFiles,
6
+ mapRelatedTests
7
+ } from '../src/api.js';
8
+
9
+ const rootField = z.string().optional().describe(
10
+ 'Path to the git checkout to inspect. Defaults to CLAUDE_PROJECT_DIR when Claude Code sets it, otherwise the MCP server process cwd.'
11
+ );
12
+ const baseField = z.string().optional().describe(
13
+ 'Git ref to compare against (branch, tag, or commit). Defaults to .mo3ta-coverage.json "base" when useConfig is true, otherwise origin/main.'
14
+ );
15
+ const filesField = z.union([z.array(z.string()), z.string()]).optional().describe(
16
+ 'Scan these repo-relative paths instead of git changed-file detection. A comma-separated string or an array. An empty list does not fall back to git.'
17
+ );
18
+ const filesFromField = z.string().optional().describe(
19
+ 'Newline-separated file list to scan, relative to root (for example the output of git diff --name-only).'
20
+ );
21
+ const modeField = z.string().optional().describe(
22
+ 'Test selection mode: fast (filename plus a direct import scan), smart (filename plus a reverse-import walk, default), or full (jest --findRelatedTests).'
23
+ );
24
+ const depthField = z.union([z.number(), z.string()]).optional().describe(
25
+ 'Smart-mode reverse-import depth, an integer from 1 to 10. 1 = tests that import the file. 2 (default) = also one intermediate module.'
26
+ );
27
+ const useConfigField = z.boolean().optional().describe(
28
+ 'Read base, mode, and depth defaults from .mo3ta-coverage.json in the repo. Default true. Explicit arguments override the file. Set false to ignore a broken config.'
29
+ );
30
+
31
+ const INSTRUCTIONS = [
32
+ 'mo3ta-coverage checks coverage of lines changed versus a base ref.',
33
+ 'Use list_changed_files to see changed JS/TS files, map_related_tests to see which tests would run, and check_changed_line_coverage to get the uncovered changed lines to write tests for.',
34
+ 'check_changed_line_coverage runs the repo\'s local Jest and writes coverage/ in that repo. Pass runTests: false to read an existing lcov file instead.',
35
+ 'A result with ok: false and uncovered lines is a coverage gap, not a crashed tool. Operational problems (not a git repo, bad base ref, Jest missing) come back as tool errors with a code and a hint.'
36
+ ].join(' ');
37
+
38
+ function toolResult(data, { isError = false } = {}) {
39
+ const payload = JSON.parse(JSON.stringify(data));
40
+ const summary = payload.summary || payload.message || '';
41
+ return {
42
+ isError,
43
+ content: [{ type: 'text', text: `${summary}\n\n${JSON.stringify(payload, null, 2)}` }],
44
+ structuredContent: payload
45
+ };
46
+ }
47
+
48
+ function errorResult(error) {
49
+ const data = {
50
+ ok: false,
51
+ code: error.code || 'UNEXPECTED',
52
+ message: error.message || String(error)
53
+ };
54
+ if (error.hint) data.hint = error.hint;
55
+ if (error.jest) data.jest = error.jest;
56
+ const summary = [data.message, data.hint].filter(Boolean).join('\n');
57
+ return toolResult({ ...data, summary }, { isError: true });
58
+ }
59
+
60
+ function run(fn, args) {
61
+ try {
62
+ return toolResult(fn(args || {}));
63
+ } catch (error) {
64
+ return errorResult(error);
65
+ }
66
+ }
67
+
68
+ /**
69
+ * MCP server that exposes mo3ta-coverage as tools. Does not connect a transport.
70
+ * @param {{version?: string}} [options]
71
+ */
72
+ export function createServer({ version = '0.0.0' } = {}) {
73
+ const server = new McpServer({
74
+ name: 'mo3ta-coverage',
75
+ version
76
+ }, {
77
+ instructions: INSTRUCTIONS
78
+ });
79
+
80
+ server.registerTool(
81
+ 'list_changed_files',
82
+ {
83
+ title: 'List changed files',
84
+ description: 'List JavaScript and TypeScript files changed versus a base ref (every author since the merge base, plus staged and unstaged edits). Pass files or filesFrom to scan an explicit list instead. Does not run tests.',
85
+ annotations: {
86
+ readOnlyHint: true,
87
+ destructiveHint: false,
88
+ idempotentHint: true,
89
+ openWorldHint: false
90
+ },
91
+ inputSchema: {
92
+ root: rootField,
93
+ base: baseField,
94
+ files: filesField,
95
+ filesFrom: filesFromField,
96
+ useConfig: useConfigField
97
+ }
98
+ },
99
+ async args => run(listChangedFiles, args)
100
+ );
101
+
102
+ server.registerTool(
103
+ 'map_related_tests',
104
+ {
105
+ title: 'Map related tests',
106
+ description: 'Map changed source files to the test files fast, smart, or full mode would run. smart (default) uses filenames plus a depth-limited reverse-import walk. full cannot list Jest\'s expanded set until tests actually run. Does not run Jest or read coverage.',
107
+ annotations: {
108
+ readOnlyHint: true,
109
+ destructiveHint: false,
110
+ idempotentHint: true,
111
+ openWorldHint: false
112
+ },
113
+ inputSchema: {
114
+ root: rootField,
115
+ base: baseField,
116
+ files: filesField,
117
+ filesFrom: filesFromField,
118
+ mode: modeField,
119
+ depth: depthField,
120
+ useConfig: useConfigField
121
+ }
122
+ },
123
+ async args => run(mapRelatedTests, args)
124
+ );
125
+
126
+ server.registerTool(
127
+ 'check_changed_line_coverage',
128
+ {
129
+ title: 'Check changed-line coverage',
130
+ description: 'Run the changed-line coverage check. By default runs the repo\'s local Jest (writes coverage/ in that repo) and returns per-file uncovered changed lines with source text so you can add tests. Set runTests false to grade an existing lcov file. ok false with uncovered lines means the threshold was missed. Timeout defaults to 5 minutes (timeoutMs).',
131
+ annotations: {
132
+ readOnlyHint: false,
133
+ destructiveHint: false,
134
+ idempotentHint: true,
135
+ openWorldHint: false
136
+ },
137
+ inputSchema: {
138
+ root: rootField,
139
+ base: baseField,
140
+ files: filesField,
141
+ filesFrom: filesFromField,
142
+ mode: modeField,
143
+ depth: depthField,
144
+ limit: z.union([z.number(), z.string()]).optional().describe(
145
+ 'Minimum percent of changed, coverable lines that must be covered. Default 80. Range 0 to 100.'
146
+ ),
147
+ lcov: z.string().optional().describe(
148
+ 'Path to lcov.info, relative to root or absolute. Default coverage/lcov.info.'
149
+ ),
150
+ runTests: z.boolean().optional().describe(
151
+ 'Run Jest before reading lcov. Default true. Set false to grade an existing report without running tests.'
152
+ ),
153
+ showCovered: z.boolean().optional().describe(
154
+ 'Also return covered changed line numbers. Uncovered lines are always returned. Default false.'
155
+ ),
156
+ timeoutMs: z.union([z.number(), z.string()]).optional().describe(
157
+ 'Kill Jest after this many milliseconds. Default 300000 (5 minutes). Range 1000 to 1800000.'
158
+ ),
159
+ ciReport: z.string().optional().describe(
160
+ 'Also write the CLI markdown table to this path (relative to root). Omitted by default so the tool does not create a report file.'
161
+ ),
162
+ useConfig: useConfigField
163
+ }
164
+ },
165
+ async args => run(checkChangedLineCoverage, args)
166
+ );
167
+
168
+ return server;
169
+ }
package/mcp/server.js ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ const major = Number(process.versions.node.split('.')[0]);
4
+ if (!Number.isInteger(major) || major < 18) {
5
+ console.error(`mo3ta-coverage-mcp requires Node.js 18 or newer. This process is Node ${process.versions.node}.`);
6
+ process.exit(1);
7
+ }
8
+
9
+ const { createServer } = await import('./createServer.js');
10
+ const { StdioServerTransport } = await import('@modelcontextprotocol/sdk/server/stdio.js');
11
+ const { readFileSync } = await import('node:fs');
12
+
13
+ const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
14
+ const server = createServer({ version: pkg.version });
15
+
16
+ // stdout is the MCP JSON-RPC stream. Diagnostics stay on stderr.
17
+ console.error(`mo3ta-coverage MCP server ${pkg.version} listening on stdio`);
18
+ await server.connect(new StdioServerTransport());
@@ -0,0 +1,260 @@
1
+ import assert from 'node:assert/strict';
2
+ import { spawn } from 'node:child_process';
3
+ import fs from 'node:fs';
4
+ import os from 'node:os';
5
+ import path from 'node:path';
6
+ import { execSync } from 'node:child_process';
7
+ import test from 'node:test';
8
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
9
+ import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
10
+ import { createServer } from './createServer.js';
11
+
12
+ const REPO_ROOT = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..');
13
+
14
+ function git(repo, command) {
15
+ execSync(command, { cwd: repo, stdio: 'pipe' });
16
+ }
17
+
18
+ function initFixture() {
19
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'mo3ta-mcp-'));
20
+ git(root, 'git init -b main -q');
21
+ git(root, 'git config user.email test@example.com');
22
+ git(root, 'git config user.name Test');
23
+ fs.mkdirSync(path.join(root, 'src'));
24
+ fs.writeFileSync(path.join(root, 'src', 'keep.js'), 'module.exports = { keep: 1 };\n');
25
+ git(root, 'git add src/keep.js && git commit -q -m base');
26
+ git(root, 'git checkout -q -b feature');
27
+ fs.writeFileSync(path.join(root, 'src', 'math.js'), [
28
+ 'function add(a, b) {',
29
+ ' return a + b;',
30
+ '}',
31
+ 'function sub(a, b) {',
32
+ ' return a - b;',
33
+ '}',
34
+ 'module.exports = { add, sub };',
35
+ ''
36
+ ].join('\n'));
37
+ fs.writeFileSync(path.join(root, 'src', 'math.test.js'), [
38
+ "const { add } = require('./math');",
39
+ "test('adds', () => {",
40
+ ' expect(add(1, 2)).toBe(3);',
41
+ '});',
42
+ ''
43
+ ].join('\n'));
44
+ fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({
45
+ name: 'mo3ta-mcp-fixture',
46
+ jest: {
47
+ testEnvironment: 'node',
48
+ transform: {},
49
+ coverageReporters: ['lcov', 'text-summary']
50
+ }
51
+ }));
52
+ git(root, 'git add src/math.js src/math.test.js package.json && git commit -q -m feature');
53
+ return root;
54
+ }
55
+
56
+ async function connect() {
57
+ const server = createServer({ version: 'test' });
58
+ const client = new Client({ name: 'mo3ta-mcp-test', version: '0.0.0' });
59
+ const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
60
+ await server.connect(serverTransport);
61
+ await client.connect(clientTransport);
62
+ return {
63
+ client,
64
+ async close() {
65
+ await client.close();
66
+ await server.close();
67
+ }
68
+ };
69
+ }
70
+
71
+ function dataOf(result) {
72
+ assert.ok(result.structuredContent, 'tool result should include structuredContent');
73
+ return result.structuredContent;
74
+ }
75
+
76
+ test('registers the coverage tools', async () => {
77
+ const session = await connect();
78
+ try {
79
+ const listed = await session.client.listTools();
80
+ const names = listed.tools.map(tool => tool.name).sort();
81
+ assert.deepEqual(names, [
82
+ 'check_changed_line_coverage',
83
+ 'list_changed_files',
84
+ 'map_related_tests'
85
+ ]);
86
+ const check = listed.tools.find(tool => tool.name === 'check_changed_line_coverage');
87
+ assert.match(check.description, /uncovered/);
88
+ } finally {
89
+ await session.close();
90
+ }
91
+ });
92
+
93
+ test('list and map tools return changed files and their tests', async () => {
94
+ const root = initFixture();
95
+ const session = await connect();
96
+ try {
97
+ const listed = await session.client.callTool({
98
+ name: 'list_changed_files',
99
+ arguments: { root, base: 'main', useConfig: false }
100
+ });
101
+ const listedData = dataOf(listed);
102
+ assert.equal(listed.isError, false);
103
+ assert.deepEqual(listedData.sourceFiles, ['src/math.js']);
104
+ assert.deepEqual(listedData.testFiles, ['src/math.test.js']);
105
+ assert.match(listed.content[0].text, /src\/math\.js/);
106
+
107
+ const mapped = await session.client.callTool({
108
+ name: 'map_related_tests',
109
+ arguments: { root, base: 'main', mode: 'fast', useConfig: false }
110
+ });
111
+ const mappedData = dataOf(mapped);
112
+ assert.equal(mappedData.testsToRun.includes('src/math.test.js'), true);
113
+ assert.match(mappedData.summary, /math\.test\.js/);
114
+ } finally {
115
+ await session.close();
116
+ fs.rmSync(root, { recursive: true, force: true });
117
+ }
118
+ });
119
+
120
+ test('turns a missing repo and a bad base ref into tool errors', async () => {
121
+ const session = await connect();
122
+ const missing = fs.mkdtempSync(path.join(os.tmpdir(), 'mo3ta-mcp-missing-'));
123
+ fs.rmSync(missing, { recursive: true, force: true });
124
+ const notGit = fs.mkdtempSync(path.join(os.tmpdir(), 'mo3ta-mcp-notgit-'));
125
+ try {
126
+ const missingResult = await session.client.callTool({
127
+ name: 'list_changed_files',
128
+ arguments: { root: missing, useConfig: false }
129
+ });
130
+ assert.equal(missingResult.isError, true);
131
+ assert.equal(dataOf(missingResult).code, 'REPO_NOT_FOUND');
132
+
133
+ const notGitResult = await session.client.callTool({
134
+ name: 'list_changed_files',
135
+ arguments: { root: notGit, useConfig: false }
136
+ });
137
+ assert.equal(notGitResult.isError, true);
138
+ assert.equal(dataOf(notGitResult).code, 'NOT_A_GIT_REPO');
139
+ assert.match(dataOf(notGitResult).hint, /checkout/);
140
+
141
+ const root = initFixture();
142
+ try {
143
+ const badBase = await session.client.callTool({
144
+ name: 'map_related_tests',
145
+ arguments: { root, base: 'no-such-ref', useConfig: false }
146
+ });
147
+ assert.equal(badBase.isError, true);
148
+ assert.equal(dataOf(badBase).code, 'INVALID_BASE_REF');
149
+ assert.match(dataOf(badBase).hint, /git fetch/);
150
+ } finally {
151
+ fs.rmSync(root, { recursive: true, force: true });
152
+ }
153
+ } finally {
154
+ await session.close();
155
+ fs.rmSync(notGit, { recursive: true, force: true });
156
+ }
157
+ });
158
+
159
+ test('check_changed_line_coverage runs Jest and returns the uncovered line', async () => {
160
+ const root = initFixture();
161
+ fs.symlinkSync(path.join(REPO_ROOT, 'node_modules'), path.join(root, 'node_modules'), 'dir');
162
+ const session = await connect();
163
+ try {
164
+ const result = await session.client.callTool({
165
+ name: 'check_changed_line_coverage',
166
+ arguments: {
167
+ root,
168
+ base: 'main',
169
+ mode: 'fast',
170
+ limit: 100,
171
+ useConfig: false,
172
+ timeoutMs: 120000
173
+ }
174
+ });
175
+ const data = dataOf(result);
176
+ assert.equal(result.isError, false);
177
+ assert.equal(data.testsFailed, false);
178
+ assert.equal(data.jest.ran, true);
179
+ assert.equal(data.coveragePassed, false);
180
+ assert.equal(data.ok, false);
181
+ const math = data.files.find(file => file.file === 'src/math.js');
182
+ assert.ok(math, 'expected src/math.js in the coverage result');
183
+ assert.ok(
184
+ math.uncovered.some(snippet => snippet.text.includes('return a - b')),
185
+ `expected the untested sub() line in uncovered snippets, got ${JSON.stringify(math.uncovered)}`
186
+ );
187
+ assert.match(data.summary, /FAILED/);
188
+ assert.match(data.summary, /return a - b/);
189
+ } finally {
190
+ await session.close();
191
+ fs.rmSync(root, { recursive: true, force: true });
192
+ }
193
+ });
194
+
195
+ test('check_changed_line_coverage reports a missing Jest install', async () => {
196
+ const root = initFixture();
197
+ const session = await connect();
198
+ try {
199
+ const result = await session.client.callTool({
200
+ name: 'check_changed_line_coverage',
201
+ arguments: { root, base: 'main', mode: 'fast', useConfig: false }
202
+ });
203
+ assert.equal(result.isError, true);
204
+ assert.equal(dataOf(result).code, 'JEST_NOT_FOUND');
205
+ assert.match(dataOf(result).hint, /npm|dependencies|node_modules/i);
206
+ } finally {
207
+ await session.close();
208
+ fs.rmSync(root, { recursive: true, force: true });
209
+ }
210
+ });
211
+
212
+ test('stops a Jest run that exceeds timeoutMs', async () => {
213
+ const root = initFixture();
214
+ fs.writeFileSync(path.join(root, 'src', 'math.test.js'), [
215
+ "const { add } = require('./math');",
216
+ "test('slow', () => {",
217
+ ' const start = Date.now();',
218
+ ' while (Date.now() - start < 20000) {}',
219
+ ' expect(add(1, 1)).toBe(2);',
220
+ '});',
221
+ ''
222
+ ].join('\n'));
223
+ fs.symlinkSync(path.join(REPO_ROOT, 'node_modules'), path.join(root, 'node_modules'), 'dir');
224
+ const session = await connect();
225
+ try {
226
+ const result = await session.client.callTool({
227
+ name: 'check_changed_line_coverage',
228
+ arguments: {
229
+ root,
230
+ base: 'main',
231
+ files: ['src/math.js'],
232
+ mode: 'fast',
233
+ useConfig: false,
234
+ timeoutMs: 2000
235
+ }
236
+ });
237
+ assert.equal(result.isError, true);
238
+ assert.equal(dataOf(result).code, 'JEST_TIMEOUT');
239
+ assert.match(dataOf(result).hint, /timeoutMs/);
240
+ } finally {
241
+ await session.close();
242
+ fs.rmSync(root, { recursive: true, force: true });
243
+ }
244
+ });
245
+
246
+ test('the stdio entry does not write protocol output before a client connects', async () => {
247
+ const child = spawn(process.execPath, [path.join(REPO_ROOT, 'mcp', 'server.js')], {
248
+ cwd: REPO_ROOT,
249
+ stdio: ['pipe', 'pipe', 'pipe']
250
+ });
251
+ let stdout = '';
252
+ child.stdout.setEncoding('utf8');
253
+ child.stdout.on('data', chunk => {
254
+ stdout += chunk;
255
+ });
256
+ await new Promise(resolve => setTimeout(resolve, 400));
257
+ child.kill('SIGTERM');
258
+ await new Promise(resolve => child.once('exit', resolve));
259
+ assert.equal(stdout, '');
260
+ });
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "mo3ta-coverage",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Run tests and report uncovered changed lines in a PR",
5
+ "homepage": "https://mo3ta.top/mo3ta-coverage/",
5
6
  "main": "index.js",
6
7
  "bin": {
7
- "mo3ta-coverage": "./index.js"
8
+ "mo3ta-coverage": "./index.js",
9
+ "mo3ta-coverage-mcp": "./mcp/server.js"
8
10
  },
9
11
  "scripts": {
10
- "test": "jest --coverage",
12
+ "test": "jest --coverage && node --test --test-concurrency=1 mcp/server.test.js",
13
+ "mcp": "node mcp/server.js",
11
14
  "build": "babel index.js -o dist/index.js"
12
15
  },
13
16
  "author": "Mahmoud Mabrok",
@@ -21,7 +24,8 @@
21
24
  "ci",
22
25
  "code-coverage",
23
26
  "pull-request",
24
- "diff"
27
+ "diff",
28
+ "mcp"
25
29
  ],
26
30
  "repository": {
27
31
  "type": "git",
@@ -37,7 +41,9 @@
37
41
  "jest": "30.5.2"
38
42
  },
39
43
  "dependencies": {
40
- "commander": "15.1.0"
44
+ "@modelcontextprotocol/sdk": "1.32.2",
45
+ "commander": "15.1.0",
46
+ "zod": "4.6.7"
41
47
  },
42
48
  "overrides": {
43
49
  "glob": "14.0.6",