Skip to content

fix(cli): support directories in scan-mcp - #132

Merged
asamassekou10 merged 1 commit into
asamassekou10:mainfrom
snowyukitty:fix/scan-mcp-directory
Aug 7, 2026
Merged

asamassekou10 merged 1 commit into
asamassekou10:mainfrom
snowyukitty:fix/scan-mcp-directory

Conversation

@snowyukitty

Copy link
Copy Markdown
Contributor

Description

scan-mcp now 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

  • Bug fix
  • New feature
  • New security agent
  • New security rule
  • New secret detection pattern
  • New security config/checklist
  • Documentation update
  • Other (describe below)

Checklist

  • I've tested my changes locally
  • I've added or updated tests when behavior changed
  • No security finding copy or remediation changed; this is input discovery only
  • No documentation update was needed for the issue's expected invocation
  • My code follows the project's style
  • No detector behavior changed, so the false-positive benchmark is not applicable
  • I did not add real secrets, tokens, customer data, or private repo URLs

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 in trust-boundary-agent.test.js, all with EPERM)

Related Issues

Fixes #115

Additional Notes

Directory discovery is limited to the canonical project-local config list already owned by MCPSecurityAgent.

@asamassekou10 asamassekou10 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@snowyukitty

Copy link
Copy Markdown
Contributor Author

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.

@asamassekou10

Copy link
Copy Markdown
Owner

Thanks for your contribution, I just pushed it.

@asamassekou10 asamassekou10 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks again for the contribution.

@asamassekou10
asamassekou10 merged commit b35921a into asamassekou10:main Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scan-mcp fails on a directory path with EISDIR

2 participants