Repository navigation
feat(dir): expand MCP scanner coverage with yara/readiness and remote runner - #1775
Conversation
… 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]>
Codecov Report❌ Patch coverage is 📢 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]>
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]>
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]>
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]>
|
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. One thing worth discussing: WDYT about including this remote scanning into |
|
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]>
|
Thanks @paralta, both land, and I'd rather take the retraction than ship the split. Pushed as Merging remote into Folding it in fixed more than ergonomics. URL validation: agreed, and worth being blunt about how it first landed. My initial pass used The rewrite normalizes the trailing dot, then requires either a canonical
Still a mitigation, and the code says so: dir validates the URL but Two things I deliberately did not fix, because they're consequences of the merge and your call:
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
left a comment
There was a problem hiding this comment.
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 👍
Closes #1740.
MCPRunner now passes
--analyzers yara,readinessexplicitly 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.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:
remotes[].urlfrom 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'sconnections[], 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".datais 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 keysconnections/nameand nomcp_datawrapper). An earlier revision of this branch readdata.mcp_data.connectionsand would never have matched a real record; the last commit corrects both the new connection extraction and the pre-existingextractSubfolder, which had the same nonexistentdata.mcp_data.*path and always returned "".Follow-ups noted rather than built, since the issue doesn't settle them:
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.