Repository navigation
fix(mcp): reject unknown module and category names instead of scanning nothing - #735
Merged
kaifcodec merged 1 commit intoOct 23, 2026
Merged
Conversation
…g nothing A `module` or `category` value that matched nothing made `scan_username` and `scan_email` return a normal envelope with `total_scanned: 0`, so a typo or a stale agent plan was indistinguishable from a scan with no findings. `_run_scan` fell through with `return []` for both cases. Validate the scope in `execute_scan` before the scan lock is taken and raise a ValueError naming the rejected value, suggesting the closest valid names (a different-case spelling first) and pointing at list_available_modules. The MCP server surfaces this as a tool error, the same way the existing argument errors are reported. `_run_scan` raises the same error instead of returning [] so no silent path remains. Module names keep resolving case-insensitively, like the CLI's -m flag; category names stay exact, like the CLI's -c flag, so 'Social' is rejected with 'social' as the first suggestion. Closes kaifcodec#727 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kaifcodec
approved these changes
Oct 23, 2026
kaifcodec
left a comment
Owner
There was a problem hiding this comment.
@VamikaSinghal,
Thank you for the clean fix and thorough test coverage! Everything looks great and all checks are green.
Feel free to check out any other open issues or submit more PRs if you're interested. Thanks again!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #727.
scan_usernameandscan_emailaccepted anymoduleorcategoryvalue. When the name matched nothing,_run_scanfell through withreturn []and the tool returned a normal envelope withtotal_scanned: 0, so a typo or a stale agent plan looked exactly like a scan with no findings.This PR validates the scope up front and reports a structured error instead:
_validate_scope()runs inexecute_scanbefore the scan lock is taken, so a rejected name never touches proxies, timeouts or concurrency (same place the existing concurrency check lives).difflib.get_close_matches, a different-case spelling always first) and points atlist_available_modules. The MCP server surfaces it as a tool error (isError: true), the same wayMissing 'username' argumentand the concurrency errors are reported today._run_scanraises the same error instead ofreturn [], so no silent path remains on the thread side either.Behaviour kept on purpose (matches the CLI):
-m(find_modulelowercases both sides), so"GitHub"still scans github.-c, so"Social"is rejected with'social'as the first suggestion.One existing test (
test_execute_scan_module_normalization) used"Made.porn"withis_email=False; that module only exists underemail_scan, so with validation it is now an unknown username module. The test keeps its purpose (dot to underscore normalisation) and scans as email instead.Before / after
Real MCP server over stdio (
python -m user_scanner.mcp.server), driven with themcpclient library:Tests
New tests in
tests/test_mcp_handlers.py, following the existing patterns there:ValueError, suggestion present or absent as expected,_scan_locknot left heldSocialrejected with'social'first;gammingsuggestsgamingadultis rejected whenno_nsfwexcludes itset_proxy_manageror_run_scanGitHubcase variant,social, email module)_run_scanitself raises for an unknown module or categoryAI disclosure
This change was written with Claude Code (Anthropic) assisting, per the AI contributor guide in
AGENTS.md. I reviewed the diff, ran the gates above and drove the real server over stdio for the before/after output.🤖 Generated with Claude Code