@knip/mcp 0.0.11 → 0.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knip/mcp",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Knip MCP Server",
5
5
  "type": "module",
6
6
  "bin": {
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@modelcontextprotocol/sdk": "^1.24.3",
30
30
  "zod": "^4.1.11",
31
- "knip": "^5.77.3"
31
+ "knip": "^5.77.4"
32
32
  },
33
33
  "engines": {
34
34
  "node": ">=18.18.0"
package/src/server.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  RUN_KNIP_TOOL_DESCRIPTION,
14
14
  WORKFLOW,
15
15
  } from './texts.js';
16
- import { getDocs, getResults, readContent } from './tools.js';
16
+ import { getDocs, getErrorMessage, getResults, readContent } from './tools.js';
17
17
 
18
18
  const __dirname = dirname(fileURLToPath(import.meta.url));
19
19
  const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
@@ -95,7 +95,7 @@ class MCP {
95
95
  const results = await getResults(cwd);
96
96
  return { content: [{ type: 'text', text: JSON.stringify(results) }] };
97
97
  } catch (error) {
98
- const message = error instanceof Error ? error.message : String(error);
98
+ const message = getErrorMessage(error);
99
99
  return {
100
100
  content: [{ type: 'text', text: JSON.stringify({ error: message, hint: ERROR_HINT }) }],
101
101
  isError: true,
package/src/tools.js CHANGED
@@ -7,6 +7,21 @@ import { CONFIG_REVIEW_HINT } from './texts.js';
7
7
 
8
8
  export { ERROR_HINT } from './texts.js';
9
9
 
10
+ /**
11
+ * @param {unknown} error
12
+ * @returns {string}
13
+ */
14
+ export function getErrorMessage(error) {
15
+ if (!(error instanceof Error)) return String(error);
16
+ const messages = [error.message];
17
+ let cause = error.cause;
18
+ while (cause instanceof Error) {
19
+ messages.push(cause.message);
20
+ cause = cause.cause;
21
+ }
22
+ return `${messages.join('\nCaused by: ')}\nCurrent working dir: ${process.cwd()}`;
23
+ }
24
+
10
25
  const __dirname = dirname(fileURLToPath(import.meta.url));
11
26
  const docsDir = join(__dirname, './docs');
12
27
 
@@ -31,9 +46,15 @@ export function buildResults(results, options) {
31
46
  * @param {string} cwd
32
47
  */
33
48
  export async function getResults(cwd) {
34
- const options = await createOptions({ cwd, isSession: true, isUseTscFiles: false });
35
- const session = await createSession(options);
36
- return buildResults(session.getResults(), options);
49
+ const originalCwd = process.cwd();
50
+ try {
51
+ process.chdir(cwd);
52
+ const options = await createOptions({ cwd, isSession: true, isUseTscFiles: false });
53
+ const session = await createSession(options);
54
+ return buildResults(session.getResults(), options);
55
+ } finally {
56
+ process.chdir(originalCwd);
57
+ }
37
58
  }
38
59
 
39
60
  /** @param {string} filePath */