Repository navigation
fix(cli): support directories in scan-mcp - #132
Conversation
asamassekou10
left a comment
There was a problem hiding this comment.
This is good work. The balanced handling of the three input kinds is clean, the tests drive the real CLI through spawnSync rather than importing internals, and checkGlobalAgents: false is exactly right for a project-scoped scan. Exit codes and the empty-directory message both behave the way the issue asked.
I ran it before signing off and hit one thing worth fixing.
Nested configs are not discovered, and audit finds them. Discovery joins the six canonical names onto the project root, so anything below the top level is invisible:
packages/app/.mcp.json with a wildcard allowlist
ship-safe scan-mcp . -> configs found: [], findings: 0
ship-safe audit . -> 1 wildcard tool allowlist finding
MCPSecurityAgent matches with rel.endsWith(cfg) || basename === cfg, so it picks up configs anywhere in the tree. That means someone in a monorepo runs the command whose entire job is MCP, is told there is nothing to find, and gets a clean result from the tool that should be most specific about it. That is the one failure mode worse than the EISDIR crash it replaces.
Suggested fix, keeping your deterministic ordering:
import fg from 'fast-glob';
import { SKIP_DIRS } from '../utils/patterns.js';
async function discoverMcpConfigFiles(rootPath) {
const found = await fg(MCP_CONFIG_FILES.map(name => `**/${name}`), {
cwd: rootPath, absolute: true, onlyFiles: true, dot: true,
ignore: Array.from(SKIP_DIRS).map(d => `**/${d}/**`),
});
// Preserve the canonical order you already have, then path order within it.
return found.sort((a, b) => {
const rank = p => MCP_CONFIG_FILES.findIndex(n => p.endsWith(n));
return rank(a) - rank(b) || a.localeCompare(b);
});
}That makes scan-mcp and audit agree, which is the part that matters.
Everything else checks out. 413 tests pass with this merged onto main, lint is clean, and I confirmed the original EISDIR case, a relative . target, an empty directory, and the manifest path all behave.
Happy to push that change myself if you would rather not round-trip, just say. And thanks for picking this one up.
|
Thanks for the careful reproduction and the concrete fix. Please feel free to push that change to this branch; I’ll review the resulting diff and rerun the relevant tests afterward. |
|
Thanks for your contribution, I just pushed it. |
asamassekou10
left a comment
There was a problem hiding this comment.
Looks good. Thanks again for the contribution.
Description
scan-mcpnow accepts a project directory, discovers the six canonical project-local MCP config files, and scans each discovered file without including global agent configuration. Direct manifest-file and URL inputs keep their existing behavior.Directory results use project-relative paths and deterministic discovery order, including in JSON output.
Type of Change
Checklist
Testing Done
node --test cli/__tests__/scan-mcp-directory.test.js(4/4 passed)npm run lint -- --quiet(passed)npm test(410/413 passed; the only failures are the three existing Windows symlink cases intrust-boundary-agent.test.js, all withEPERM)Related Issues
Fixes #115
Additional Notes
Directory discovery is limited to the canonical project-local config list already owned by
MCPSecurityAgent.