Back to KB
Difficulty
Intermediate
Read Time
9 min

Snyk scans your MCP servers by running them. Here is what that means.

By Codcompass Team··9 min read

MCP Supply Chain Security: The Execution Risk in Dynamic Scanners

Current Situation Analysis

The Model Context Protocol (MCP) ecosystem is rapidly adopting a registry-based model for agent capabilities, mirroring the evolution of npm and PyPI. As organizations integrate MCP servers into their development workflows, security scanning has become a critical requirement. However, a fundamental architectural flaw exists in how several prominent security tools analyze these servers.

To retrieve metadata from an MCP server—specifically tool definitions and schemas—some scanners employ dynamic execution. Tools like Snyk's agent-scan read local configuration files (e.g., ~/.cursor/mcp.json, Claude Desktop configs), extract the command arrays, and execute the server processes to query their capabilities via the MCP protocol. This data is then transmitted to third-party analysis endpoints, such as Invariant Labs' API at invariantlabs.ai.

This approach creates a paradoxical security risk: the scanner becomes the attack vector. The configuration files that define MCP servers are often attacker-controlled or sourced from untrusted registries. By executing the command array to perform analysis, the scanner runs untrusted code on the host machine. Evidence of this execution and data exfiltration was confirmed when developers observed 429 Too Many Requests responses from the analysis API, proving that servers were being spun up and their data transmitted without explicit user intervention.

While vendors have introduced consent flows to display server names and commands before execution, the architectural tension remains. In CI/CD environments, interactive consent is impossible, leading to flags like --dangerously-run-mcp-servers that bypass safety checks entirely. This forces a choice between security automation and execution safety. Furthermore, the transmission of tool descriptions and partial configurations to external APIs raises significant data residency and compliance concerns, particularly in regulated industries where environment variables may contain sensitive credentials.

WOW Moment: Key Findings

The core insight is that dynamic scanning of untrusted MCP configurations violates the primary tenet of supply chain security: never execute untrusted code during the analysis phase. This mirrors the supply chain attacks seen in npm ecosystems where malicious install hooks executed arbitrary code.

The following comparison highlights the trade-offs between dynamic execution scanners and static analysis approaches.

Scanning StrategyExecution RiskCI/CD ViabilityData ResidencyRuntime Detection
Dynamic ExecutionCritical<br>Runs payload on host; potential RCE if config is malicious.Low<br>Requires bypass flags; breaks automation safety.Third-Party<br>Data sent to external APIs; compliance risk.High<br>Detects behavioral anomalies and runtime-only exploits.
Static AnalysisNone<br>Parses text/AST; zero code execution.High<br>Safe by default; no execution overhead.Local/Air-Gapped<br>Analysis occurs on-premise; full control.Low<br>Misses obfuscated runtime behaviors or dynamic payloads.

Why this matters: Organizations must decouple pre-deployment gating from runtime auditing. Static analysis provides a safe gate for untrusted code, while dynamic analysis should be reserved for trusted servers in isolated environments. Relying solely on dynamic scanners for untrusted inputs exposes the development pipeline to immediate compromise.

Core Solution

A robust MCP security architecture requires a hybrid pipeline that enforces static analysis as the primary gate and restricts dynamic execution to sandboxed, consent-driven workflows. This section outlines a TypeScript-based implementation of such a pipeline.

Architecture Decisions

  1. Static-First Gate: All configurations must pass static analysis before any execution is considered. This ensures that malicious command injection or known attack patterns are caught without risk.
  2. Sandboxed Dynamic Analysis: If deeper inspection is required, dynamic analysis must occur in an isolated environment with no network access and restricted permissions.
  3. Explicit Consent Policy: Dynamic execution requires explicit user approval, displaying the exact comma

🎉 Mid-Year Sale — Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register — Start Free Trial

7-day free trial · Cancel anytime · 30-day money-back