Skip to content

Commit 7793962

Browse files
committed
Suppress issues initially to not overwhelm agent in mcp server
Often agent starts to fix issues instead of config hints
1 parent 346247a commit 7793962

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

packages/mcp-server/src/texts.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export const ERROR_HINT = `For unexpected errors (exit code 2) such as "error lo
5656
- If no config file exists, create knip.json in the project root
5757
- Run knip again`;
5858

59+
export const UNCONFIGURED_HINT =
60+
'Issues are suppressed because the project is not yet configured. Reported issues might be false positives. Address configuration hints first, then re-run to get the actual issues.';
61+
5962
export const CONFIG_REVIEW_HINT = `Review the existing configuration for potential improvements:
6063
6164
- Never use "ignore" patterns (hides real issues!), always prefer specific solutions; other ignore* options are allowed

packages/mcp-server/src/tools.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { dirname, join } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { createOptions, createSession, finalizeConfigurationHints, KNIP_CONFIG_LOCATIONS } from 'knip/session';
55
import { CURATED_RESOURCES } from './curated-resources.js';
6-
import { CONFIG_REVIEW_HINT } from './texts.js';
6+
import { CONFIG_REVIEW_HINT, UNCONFIGURED_HINT } from './texts.js';
77

88
export { ERROR_HINT } from './texts.js';
99

@@ -30,15 +30,30 @@ const docsDir = join(__dirname, './docs');
3030
* @param {{ cwd: string, configFilePath: string | undefined }} options
3131
*/
3232
export function buildResults(results, options) {
33+
const configurationHints = finalizeConfigurationHints(results, options);
34+
35+
const isSuppressIssues =
36+
results.counters.total >= 10 &&
37+
configurationHints.some(hint => hint.type === 'top-level-unconfigured' || hint.type === 'workspace-unconfigured');
38+
39+
const configFile = options.configFilePath
40+
? { exists: true, filePath: options.configFilePath }
41+
: { exists: false, locations: KNIP_CONFIG_LOCATIONS };
42+
43+
const reviewHint = isSuppressIssues ? UNCONFIGURED_HINT : options.configFilePath ? CONFIG_REVIEW_HINT : undefined;
44+
const files = isSuppressIssues ? [] : Array.from(results.issues.files);
45+
const issues = isSuppressIssues
46+
? []
47+
: Object.fromEntries(Object.entries(results.issues).filter(([key]) => key !== 'files' && key !== '_files'));
48+
3349
return {
34-
configFile: options.configFilePath
35-
? { exists: true, filePath: options.configFilePath, reviewHint: CONFIG_REVIEW_HINT }
36-
: { exists: false, locations: KNIP_CONFIG_LOCATIONS },
37-
configurationHints: finalizeConfigurationHints(results, options),
50+
reviewHint,
51+
configFile,
52+
configurationHints,
3853
counters: results.counters,
3954
enabledPlugins: results.enabledPlugins,
40-
files: Array.from(results.issues.files),
41-
issues: Object.fromEntries(Object.entries(results.issues).filter(([key]) => key !== 'files' && key !== '_files')),
55+
files,
56+
issues,
4257
};
4358
}
4459

0 commit comments

Comments
 (0)