Skip to content

feat(dir): expand MCP scanner coverage with yara/readiness and remote runner - #1775

Merged
paralta merged 11 commits into
agntcy:mainfrom
conorbronsdon:feat/mcp-scanner-coverage
Jul 31, 2026
Merged

paralta merged 11 commits into
agntcy:mainfrom
conorbronsdon:feat/mcp-scanner-coverage

Conversation

@conorbronsdon

@conorbronsdon conorbronsdon commented Jul 8, 2026 •

Copy link
Copy Markdown
Member

Closes #1740.

  1. MCPRunner now passes --analyzers yara,readiness explicitly to the behavioral scan, so both zero-dependency analyzers always run instead of relying on the binary's undocumented defaults. Global flags are placed before the subcommand, matching mcp-scanner's CLI contract (its docs reject flags placed after the subcommand). Analyzers metadata on the result now names the analyzers that actually ran ("yara", "readiness") rather than the subcommand name.

  2. New RemoteRunner (utils/scanner/remote.go) scans live MCP server endpoints. It extracts connection URLs from modules[*].data.connections[] (transport type "sse" or "streamable-http"; "stdio" connections are local and skipped), runs mcp-scanner's remote/prompts/resources/instructions subcommands against each endpoint via --server-url, and merges results with the existing package-level merge(). Network errors or unparsable output for a given endpoint/subcommand pair are recorded as a skipped sub-scan with a warning, never a hard error, so one bad endpoint doesn't block the rest. Registered alongside MCPRunner in the scan reconciler task.

Two deviations from the issue text, called out for review:

  • The issue describes extracting remotes[].url from the record. That field doesn't exist in the OASF schema (checked against schema.oasf.outshift.com/1.0.0 for mcp_data and mcp_server_connection): the real field is the module's connections[], where each connection carries a type and, for the two remote transports, a url. RemoteRunner reads that field instead, the same path the mcp-claudecode/mcp-cursor exporters (feat(dir): add mcp-claudecode export format #1766/feat(dir): add mcp-cursor export format #1767) use. Happy to adjust if the issue meant something else by "remotes".
  • On the same note: a module's data is itself the mcp_data object in decoded records (verified against buildMCPModule in server/skill and the record_100.json e2e fixture, whose MCP module data has top-level keys connections/name and no mcp_data wrapper). An earlier revision of this branch read data.mcp_data.connections and would never have matched a real record; the last commit corrects both the new connection extraction and the pre-existing extractSubfolder, which had the same nonexistent data.mcp_data.* path and always returned "".

Follow-ups noted rather than built, since the issue doesn't settle them:

  • llm/api analyzers stay opt-in (they need third-party credentials, out of scope per the issue's own note).
  • A SCANNER_TYPE_REMOTE proto enum needs a scanv1 proto change + buf generate cycle, left for a separate change. Until then the scan_reports row says "remote" but the ScanReport referrer carries SCANNER_TYPE_UNSPECIFIED, so the AI Finder UI (feat(gateway): surface security scan results in the AI Finder UI #1760) can't label remote scans yet.
  • Endpoints are not de-duplicated across connections/modules; a URL listed twice is scanned twice.

Verified: go build/vet/test clean on the utils, reconciler, and server modules. Runner exec paths are covered by unit tests via a fake CLI binary (testdata/fakecli), including RemoteRunner end-to-end and MCPRunner.Run. One caveat for reviewers: the fake CLI matches on argument substrings, so the exact flag ordering contract (--raw <subcommand> --server-url <url>) is grounded in mcp-scanner's documentation rather than exercised against the real binary — a live smoke run would be a good double-check before merge.

… runner

MCPRunner now passes --analyzers yara,readiness explicitly (global flags
placed before the subcommand, per mcp-scanner's CLI contract) so both
zero-dependency analyzers always run, and result metadata names the
analyzers that actually ran. New RemoteRunner scans live MCP endpoints
from modules[*].data.mcp_data.connections[] (sse/streamable-http) via
the remote/prompts/resources/instructions subcommands, skipping failed
endpoints with a warning instead of hard-failing.

Closes agntcy#1740

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Conor Bronsdon <[email protected]>
@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Jul 8, 2026
@codecov

codecov Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.39785% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
utils/scanner/mcp_endpoint.go 92.7% 7 Missing and 5 partials ⚠️
reconciler/tasks/scan/task.go 77.8% 2 Missing ⚠️
utils/scanner/mcp.go 81.8% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…k runner wiring

Raise patch coverage on the mcp-scanner expansion by exercising the
previously untested exec-invocation paths through a compiled fake CLI
(testdata/fakecli, ignored by codecov) instead of stubbing internals:

- remote.go: runOne/runMCPScannerRemote success, exec-failure, and
  unparsable-output branches; Run() merge semantics across multiple
  endpoints and subcommands, including skip-not-error handling for
  unreachable endpoints; extractRemoteEndpoints decode-error, non-v1,
  and module-walking paths (file now 100% covered).
- mcp.go: Run() end to end via a git clone of a local fixture repo,
  locking in the new yara/readiness analyzer set and CLI flag order.
- reconciler/tasks/scan: NewTask runner wiring, asserting RemoteRunner
  is registered between the MCP and Skill runners.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Conor Bronsdon <[email protected]>
@github-actions github-actions Bot added size/L Denotes a PR that changes 1000-1999 lines and removed size/M Denotes a PR that changes 200-999 lines labels Jul 8, 2026
A module's data is itself the OASF mcp_data object (see buildMCPModule and
the record_100.json e2e fixture, whose decoded MCP module data has top-level
keys [connections, name] and no mcp_data key), so both the remote endpoint
extraction added in this branch and the existing subfolder extraction must
read connections/repository directly under data rather than under a
nonexistent data.mcp_data wrapper. As written, extractConnectionURLs never
matched a real record and RemoteRunner always skipped.

Tests built records with the wrong shape, so they passed against the buggy
accessor; they now build data.connections directly to match real records.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Conor Bronsdon <[email protected]>
@conorbronsdon
conorbronsdon marked this pull request as ready for review July 9, 2026 03:19
@conorbronsdon
conorbronsdon requested a review from a team as a code owner July 9, 2026 03:19
@conorbronsdon
conorbronsdon marked this pull request as draft July 9, 2026 03:19
Empty commit to re-run the e2e jobs. Test Client hit the tryReceiveEvent
race (gRPC stream error RST_STREAM/CANCEL delivered before ctx.Done, which
the matcher's lowercase substrings don't cover) and Test Network a
name-resolution NotFound; neither is reachable from this branch's
scanner-only changes, and both jobs were green on the prior commit.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Conor Bronsdon <[email protected]>
@conorbronsdon
conorbronsdon marked this pull request as ready for review July 9, 2026 03:40
muscariello and others added 2 commits July 9, 2026 11:49
Empty commit to re-run E2E. The Test / E2E / Test Daemon External job
failed on the pre-existing, flaky "runtime should discover docker
workloads" spec (tests/e2e/daemon/01_daemon_test.go:147), which times
out pulling a runtime record ("record not found") after docker
workload discovery. This PR touches only the MCP scanner (utils/scanner,
reconciler/tasks/scan, a gorm comment) and no daemon/runtime/e2e code;
all of its own unit tests pass locally. Test / E2E / Test Client did not
fail on its own -- it was canceled by the matrix fail-fast.

Signed-off-by: Conor Bronsdon <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@paralta

paralta commented Jul 30, 2026

Copy link
Copy Markdown
Member

Good work here, @conorbronsdon 🚀 Overall looks good to me, my only note would be that we could add some URL validation - the URLs come directly from externally-published records, so a scheme allowlist (e.g. https:// only) and rejecting private/loopback ranges before passing to mcp-scanner would be a good safeguard.

One thing worth discussing: connections[] is MCP-specific in the OASF schema, so RemoteRunner will only ever find endpoints in integration/mcp modules. So, this mcp and remote separation might not be adequate here, and it creates the SCANNER_TYPE_REMOTE gap you noted as a follow-up. I realise this retracts my original suggestion from #1740.

WDYT about including this remote scanning into MCPRunner as a second step — run source code scan, run live endpoint scan, and merge findings?

@conorbronsdon

Copy link
Copy Markdown
Member Author

Good thought - let me take a look

…dpoint URLs

Addresses review on agntcy#1775.

connections[] is MCP-specific in OASF (it is an attribute of mcp_data in
schema/objects/mcp_data.json, and no other object under schema/objects
declares it), so a standalone RemoteRunner walked every module but could
only ever match integration/mcp. It is now a second phase inside
MCPRunner: source scan, then live-endpoint scan, merged into one result.
That closes the SCANNER_TYPE_REMOTE gap and drops the DB scanner-type
change with it.

Two properties are preserved deliberately:

- The phases fail differently. The source scan fails hard; the endpoint
  phase is skip-with-warning, so an unreachable endpoint cannot fail an
  otherwise-clean source scan.
- The endpoint phase has its own toggle (DisableEndpointScan). It makes
  outbound connections to third-party servers and costs one mcp-scanner
  invocation per (endpoint, subcommand).

Endpoint URLs come from externally published records, so each is now
validated before it reaches mcp-scanner: https only, and loopback,
link-local (which covers the 169.254.169.254 metadata address), private,
unique-local, unspecified, and multicast addresses are rejected.
AllowPrivateEndpoints re-permits private ranges and plain http for
self-hosted deployments where the directory and its MCP servers share a
network. Default is deny, so the safe posture ships out of the box.

This is a mitigation, not a complete defence, and the code says so: dir
validates the URL but mcp-scanner opens the connection, so a hostname
that only resolves to a private address at dial time still gets through.

Package coverage 87.9%.

Signed-off-by: Conor Bronsdon <[email protected]>
…alyzer order

Found by an adversarial review of the previous commit. Each item below was
verified by running the code, and each now has a regression test.

The validator was bypassable. net.ParseIP only accepts canonical forms, so
every non-canonical spelling of an address returned nil, fell through to the
"then it must be a hostname" branch, and was accepted, while the resolver
reads them as IPv4 addresses:

  https://2852039166/      -> 169.254.169.254   (the metadata address the
                                                 previous commit message
                                                 claimed to block)
  https://169.254.169.254./ -> same, via the trailing dot
  https://2130706433/, https://127.1/, https://0177.0.0.1/,
  https://0x7f000001/, https://0/ -> loopback or 0.0.0.0

Host handling is now: normalize the trailing dot first, then require either a
canonical netip address outside an explicit reserved-prefix table, or a
syntactically valid DNS name. A label set that is entirely digits, or a
0x-prefixed hex run, is not a DNS name.

The range check was also too narrow. net.IP.IsPrivate covers only RFC 1918 and
fc00::/7, which left accepted: 100.100.100.200 (Alibaba metadata),
100.64.0.0/10 (CGNAT, the pod and node CIDR on several managed Kubernetes
offerings), 192.0.0.0/24, 198.18.0.0/15, TEST-NET-1/2/3, 240.0.0.0/4, and
255.255.255.255. Replaced with an explicit table that also covers ::/96
(IPv4-compatible, e.g. ::127.0.0.1), 64:ff9b::/96 (NAT64) and 2002::/16 (6to4),
both of which can embed a v4 target. Addresses carrying an interface zone
(fe80::1%eth0) are refused rather than silently skipping the check, and
::ffff:127.0.0.1 is unmapped before the lookup.

merge() emitted the analyzer union in Go map order. Since Run now always ends
in a merge, that made TestMCPRunner_Run_Success fail about one run in eight,
and it made Analyzers unstable in the DB row and the OCI referrer for
byte-identical scans. Now sorted.

TestRun_DisableEndpointScan_SkipsEndpointPhase could not fail: its fixture used
schema_version 0.7.0, so extractEndpoints bailed on the non-v1 record and the
endpoint phase found nothing to scan whether the toggle worked or not.
Rewritten with a v1 record and the fake CLI, plus a counterpart test with the
toggle off, so deleting the toggle in either direction goes red.

Also:
- Split AllowInsecureTransport out of AllowPrivateEndpoints. Overloading one
  flag meant an operator who needed a private-range endpoint silently also
  opted into cleartext scans of arbitrary public hosts.
- Dropped the exported EndpointScanSettings accessor, which existed only so a
  test in another package could assert wiring. The behavior is covered in
  utils/scanner instead.
- Renamed a `url` variable shadowing the imported net/url package.
- Documented the three new keys in daemon.config.yaml and the Helm values,
  where their siblings live.

Package coverage 87.8%, measured over 8 consecutive runs with no failures.

Signed-off-by: Conor Bronsdon <[email protected]>
@conorbronsdon

conorbronsdon commented Jul 30, 2026 •

Copy link
Copy Markdown
Member Author

Thanks @paralta, both land, and I'd rather take the retraction than ship the split. Pushed as e176d4ba and 0fdd2a07, rebased onto main.

Merging remote into MCPRunner: agreed. I checked the schema first: connections is an attribute of mcp_data in schema/objects/mcp_data.json and nothing else under schema/objects declares it, so RemoteRunner walked every module but could only match integration/mcp.

Folding it in fixed more than ergonomics. toProtoScannerType switches on mcp/skill/a2a with no remote case, so the standalone runner was already writing every remote report as SCANNER_TYPE_UNSPECIFIED. Two properties kept deliberately: the source scan still fails hard while the endpoint phase is skip-with-warning, and the endpoint phase has its own toggle since it dials third-party servers.

URL validation: agreed, and worth being blunt about how it first landed. My initial pass used net.ParseIP + IsPrivate, and a review of my own branch showed it was bypassable by https://2852039166/ — 169.254.169.254 in decimal — plus the octal, hex, short, and trailing-dot spellings. net.ParseIP accepts only canonical forms, so everything else fell through to a "then it must be a hostname" branch while the resolver read them as addresses. The commit message asserted the metadata address was blocked when it wasn't, which is worse than no validation.

The rewrite normalizes the trailing dot, then requires either a canonical netip address outside an explicit reserved-prefix table or a syntactically valid DNS name (an all-digit or 0x label is not one). The table also covers what IsPrivate misses, notably 100.64.0.0/10 — the pod and node CIDR on several managed Kubernetes offerings, i.e. exactly the in-cluster case. All 25 bypasses have regression tests.

allow_private_endpoints re-permits reserved ranges for self-hosted deployments; I split allow_insecure_transport out rather than have one flag do both, so needing a private endpoint doesn't also opt you into cleartext scans of public hosts.

Still a mitigation, and the code says so: dir validates the URL but mcp-scanner opens the connection, so a name resolving to a reserved address at dial time still gets through.

Two things I deliberately did not fix, because they're consequences of the merge and your call:

  1. A record with no source code now persists as a passing MCP scan. merge sets SkippedReason only when every phase skips, so a skipped source phase plus a clean endpoint phase yields Safe=true, Skipped=false and writes ScanReport{ScannerType: "MCP", IsSafe: true}. Under the split runners no MCP row was written at all.
  2. A publisher who crashes the scanner on their own repo suppresses the endpoint scan. runSourceScan hard-errors on any non-zero mcp-scanner exit, and Run returns before the endpoint phase, so no row is written. RemoteRunner used to report those findings independently.

Both are report-model questions rather than validation ones. Happy to take either here.

Validating each endpoint URL bounds WHERE the reconciler connects but not HOW MANY connections one record can cause. The endpoint list comes from publisher-controlled record data and each entry costs one mcp-scanner invocation per subcommand, so a record declaring 500 connections would fire 2000 outbound scans at hosts of the publisher's choosing. That makes the directory an amplifier even though every individual destination passed validation.

Default cap is 8, well above what a real MCP server declares (stdio plus one or two remote transports) and far below a useful amplification factor. Configurable via MaxEndpointsPerRecord; the zero value means the default rather than unlimited, which a test pins.

Truncation is recorded on the merged result rather than added as another skipped sub-scan: merge only carries SkippedReason through when every input skipped, so a notice added that way would vanish as soon as one endpoint scanned successfully, which is exactly when a reader needs to know coverage was partial.

Signed-off-by: Conor Bronsdon <[email protected]>
…ware

A review of the previous commit found the cap real but its reporting
broken and its knob unreachable. Three fixes.

The truncation notice was silently discarded. It was written to
SkippedReason on the endpoint-phase result, and merge propagates
SkippedReason only when every input skipped, so Run's merge with the
source phase dropped it the moment one endpoint scanned successfully -
exactly the case the previous commit message claimed to protect. Verified
by probe: the phase result carried the notice, the Run result did not.
That made it a silent cap, the failure it was written to avoid.

Fixed with a Notices field on ScanResult that merge unions. A Finding
would have been the obvious carrier and is wrong: any finding sets
Safe=false, so a coverage note would mark the record unsafe. The
reconciler now logs notices at Warn. The report proto still has no field
for partial coverage, so this is a log line rather than persisted state;
that is the same report-model gap raised in the PR thread.

MaxEndpointsPerRecord was added to MCPConfig but never wired, so the
documented knob did not exist: an operator could not raise it, and with
the notice being dropped they also got no signal anything had been
truncated. Now plumbed through the scan Config like its three siblings
and documented in daemon.config.yaml and the Helm values.

Endpoints are deduplicated before the cap applies. Eight copies of one
URL previously stayed under the cap and still produced 32 requests at a
single host, with no truncation notice, so the cap bounded list length
without bounding what any one victim received.

Tests: the previous set could not catch a default raised to 500 (both
sides of the assertion were the constant), an off-by-one at the boundary,
or the notice being dropped by Run. Added a magnitude guard, a
scan-at-exactly-the-cap case, a dedup case, and a Run-level assertion
that the notice survives both merges. All four mutations now die.

Package coverage 88.2%.

Signed-off-by: Conor Bronsdon <[email protected]>

@paralta paralta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for addressing the feedback so promptly, @conorbronsdon !

Both points are acceptable to me. On the first, the analyzers field makes it clear which sub-scans actually ran, so a hosted agent with no source code getting a clean MCP result from endpoint scanning alone is fine. On the second, the retry covers the common transient failure case though, if source scanning consistently fails on a record, endpoint scanning will be permanently blocked too. That's a known limitation worth addressing later by making the two phases independent within MCPRunner, but not a blocker for this PR 👍

@paralta
paralta merged commit a0efb70 into agntcy:main Jul 31, 2026
31 checks passed
@conorbronsdon
conorbronsdon deleted the feat/mcp-scanner-coverage branch July 31, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 1000-1999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Expand MCP scanner coverage: YARA/readiness analyzers and live server scanning

3 participants