fix(mcp): surface invalid adjacent config in scan results
Summary
The experimental stdio MCP scan tool returns an unqualified No issues found result when an adjacent osv-scanner.toml cannot be parsed. The diagnostic reaches server stderr, but the tool response contains neither that diagnostic nor an error indication. The same failure makes the CLI exit 130; the MCP process exposes that status only when the session closes. A client consuming per-call results can therefore miss that the intended scan configuration was ignored while the server remains available for further requests. This report concerns ordinary configuration-error reporting, with no security-boundary claim.
Runtime or environment
Reproduced on Linux amd64 using Python 3's standard library client against the latest published release, OSV-Scanner v2.7.0 (tag commit bfe2f84abd2f09fe0b83ba7f6dad40d296762f40), and current default main at 0f45f6b8b02a85c4c1b3d5caa9428b0f56108c3c. Both binaries were built with Go 1.27.3 and use MCP Go SDK v1.8.0. The main binary's embedded vcs.revision matches that checkout and vcs.modified=false; its displayed scanner version alone does not distinguish it from the release. MCP protocol negotiation used 2025-11-25. Online advisory queries require network access.
Steps to reproduce
Save the following as repro.py and run python3 repro.py with the release scanner on PATH, then repeat with python3 repro.py /absolute/path/to/main-build. The script creates and removes its own disposable fixture, containing only requirements.txt with six==1.17.0 and an adjacent config. It starts a fresh stdio server for each case, changes only the config from empty valid TOML to this = [invalid, scans, issues a follow-up tools/list, then closes stdin and records the server status. It also runs the CLI control on the same fixture. This exact script was executed against both tested builds; no project package code is executed.
import json
import pathlib
import selectors
import subprocess
import sys
import tempfile
exe = sys.argv[1] if len(sys.argv) > 1 else "osv-scanner"
with tempfile.TemporaryDirectory(prefix="osv-mcp-") as tmp:
root = pathlib.Path(tmp)
lock = root / "requirements.txt"
lock.write_text("six==1.17.0\n")
for case, config in [("valid", ""), ("invalid", "this = [invalid\n")]:
(root / "osv-scanner.toml").write_text(config)
with tempfile.TemporaryFile(mode="w+") as stderr:
p = subprocess.Popen([exe, "experimental-mcp"], stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=stderr, text=True)
try:
with selectors.DefaultSelector() as ready:
ready.register(p.stdout, selectors.EVENT_READ)
def call(i, method, params):
p.stdin.write(json.dumps(dict(jsonrpc="2.0", id=i,
method=method, params=params)) + "\n")
p.stdin.flush()
while True:
if not ready.select(45):
raise TimeoutError(method)
line = p.stdout.readline()
if not line:
raise RuntimeError("server closed stdout")
response = json.loads(line)
if response.get("id") == i:
return response
call(1, "initialize", dict(protocolVersion="2025-11-25", capabilities={},
clientInfo=dict(name="config-repro", version="1")))
p.stdin.write('{"jsonrpc":"2.0","method":"notifications/initialized"}\n')
p.stdin.flush()
scan = call(2, "tools/call", dict(name="scan_vulnerable_dependencies",
arguments=dict(paths=[str(root)], recursive=True,
ignore_glob_patterns=[])))
followup = call(3, "tools/list", {})
alive = p.poll() is None
p.stdin.close()
status = p.wait(timeout=10)
finally:
if p.poll() is None:
p.kill()
p.wait()
p.stdout.close()
if not p.stdin.closed:
p.stdin.close()
stderr.seek(0)
diagnostic = stderr.read().replace(str(root), "<fixture>")
cli = subprocess.run([exe, "scan", "source", "-L", str(lock), "--no-call-analysis=all",
"--no-resolve", "--format=json", "--all-packages"],
capture_output=True, text=True, timeout=45)
print(json.dumps(dict(case=case, scan=scan, alive_after_followup=alive,
followup_ok="result" in followup, server_exit_after_eof=status,
cli_exit=cli.returncode, server_stderr=diagnostic), indent=2))
Expected behavior
An MCP client should receive a diagnostic associated with the scan call when a discovered config is invalid and ignored, so it can distinguish that outcome from a scan whose configuration loaded successfully without shutting down the server. This does not require removing partial scan results or choosing one particular response representation. The CLI already treats this condition as a distinct error, and the MCP tools specification defines per-call tool-error reporting separately from optional stderr logging.
Actual behavior
Both cases on both builds returned exactly this scan response:
{"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"No issues found"}]}}
The invalid-config response has no config diagnostic and no isError field. Stderr does report the failure; this is not an absence of every error signal. With the generated fixture path replaced by <fixture>, its diagnostic is:
Ignored invalid config file at <fixture>/osv-scanner.toml because: toml: line 1 (last key "this"): expected value but found "nvalid" instead
The server successfully answered the subsequent tools/list and was still running afterward. Only after the client closed stdin did it exit 130. The empty-config server exited 0 after the same close. The CLI control returned 130 for invalid config and 0 for empty config, while identifying the pinned package in its JSON output. These are one paired valid/invalid run per build; they establish the per-request omission and delayed process status, not an incorrect advisory classification for six.
Evidence
- Expected source: The MCP tools error-handling contract distinguishes tool execution errors from protocol errors. The stdio transport contract permits clients to ignore stderr and says stderr alone should not be interpreted as an error condition. OSV-Scanner's config-error distinction is also implemented in the command runner described below.
- Failure source: The executed script and exact response above, paired with the empty-config control and CLI exit statuses.
- Evidence provenance: observed
- Local verification: reproduced
- Reproduction completeness: complete
In the inspected main source, the config manager logs invalid adjacent config and falls back to the default config. The MCP handler builds the tool result from DoScan's returned error, which is nil for this fixture. The command runner checks the logger's invalid-config flag after app.Run returns. These are source breadcrumbs, not a prescribed implementation.
Restoration check
Repeat the paired fixture through a live stdio session. The invalid-config call must expose the ignored-config condition in its per-call result before session teardown; the valid empty-config control must remain distinguishable and free of a spurious config error. Keep the ability to return genuine scan findings or partial results as appropriate. Verify that the existing CLI invalid-config status remains intact. Server stderr and eventual process status alone do not close this per-call reporting gap.
References
Merged PR #1957 established a dedicated invalid-config exit status for automation; that process-level mechanism remains present but is delayed until a long-lived MCP server finishes. Open issue #3001 concerns valid config-driven suppression visibility in machine-readable reports, whereas this case concerns a malformed config rejected during an MCP call. They have different failing inputs and restoration checks.
Triage assessment
- Impact level: P2
- Assessment status: supported
- Impact basis: Clients using per-call MCP scan results cannot distinguish successful config loading from this ignored-config failure, even though the scanner classifies it as an error for CLI automation. The observed scope is malformed adjacent TOML; no advisory false negative or security boundary failure is established.
- Workaround status: available
- Workaround basis: The executed CLI control reports the diagnostic and returns 130 for the same fixture, so callers can validate this scan through the CLI instead. Capturing server stderr also exposes the diagnostic, though it does not supply a per-call error result.
Hi, I reproduced this on current main using the reporter's setup: with an invalid osv-scanner.toml next to the scan target, the MCP scan tool returns "No issues found" with no error flag, while the same setup makes the CLI exit 130. The parse diagnostic only appears on the server's stderr.
Root cause: the config manager logs the invalid config and falls back, so DoScan returns without an error, and the MCP handleScan builds its result only from what DoScan returns. The invalid-config message already exists in-process (it's the one the CLI exit-130 logic keys on), but it isn't stored anywhere a consumer can read.
I have a fix ready locally: the cmdlogger handler now records invalid-config messages behind an accessor, and handleScan attributes new messages to the call that produced them, surfacing them as a tool error (isError: true) while keeping the scan output. Regression tests included, including a check that a later call with a valid config doesn't pick up stale errors.
One design point to flag: on the success path the scan results are still returned, with the diagnostic appended as an error rather than replacing the output.
Could I be assigned to this issue? Happy to open the PR once assigned.