Building an Automated Vulnerability Discovery System Using Model Context Protocol
This article details the author's practical implementation of an automated vulnerability discovery system built on AI coding tools and the Model Context Protocol (MCP). It covers the overall architecture design, core module implementation, real-world case studies, efficiency gains, engineering challenges, and future evolution. In this system, every stage of the security research workflow—environment identification, static analysis, directed fuzzing, crash handling, root-cause analysis, and report drafting—is wrapped as a standardized MCP service. An LLM orchestration core drives the tools through conversational interaction, enabling a closed loop that reduces manual context transfer and frees researchers to focus on higher-level security reasoning.
Introduction
In security research, vulnerability discovery is a systematic engineering effort that relies heavily on experience and patience. The traditional workflow encompasses environment setup, target deployment, reverse analysis, attack-surface mapping, fuzzing, crash reproduction, root-cause analysis, proof-of-concept development, and disclosure report drafting. Each stage depends on different toolchains and output formats, and context transfer between stages often falls back on manual copy-and-paste. This fragmented pattern consumes significant effort on tool switching and process handoffs, while the time available for deep thinking and vulnerability verification is correspondingly compressed.
In recent years, large language models (LLMs) have shown considerable promise in code comprehension, reverse-engineering assistance, and log analysis. The Model Context Protocol (MCP) further introduces a standardized interface between AI coding tools and external toolchains: it encapsulates local commands, analysis scripts, and debugger operations as callable structured functions, enabling the model to drive these tools directly within the conversational context without manual window switching or data transfer.
This article walks through the author’s practice of building an automated vulnerability discovery system on top of AI coding tools and MCP. It covers the overall architecture design, core implementation approach, key technical decisions, real discovery cases, and the system’s advantages, limitations, and future evolution.
Why an Automated Vulnerability Discovery System Is Needed
In actual research, the primary pain point is not “not knowing how to analyze” but “time being swallowed by tool operations.” A typical research session looks like this:
- Boot a virtual machine and deploy the target binary or service.
- Use decompilation tools to locate key functions and trace call chains.
- Construct inputs and design the initial corpus based on the call chain.
- Run a fuzzing tool to perform mutation and coverage collection.
- On a crash, extract the crash context and trace the trigger path.
- Write a working proof-of-concept based on the path semantics.
- Draft a disclosure report and submit it to a vendor or bounty platform.
Each step uses its own tools and output formats, and the handoffs require the researcher to manually consolidate information. More importantly, the context produced by each step is typically the input for the next decision. For example, register state at the crash site directly shapes root-cause analysis, which in turn determines exploitability assessment. If this context could flow automatically, both the efficiency and accuracy of the entire research process would improve significantly.
An LLM’s strength lies precisely in handling this cross-step, cross-tool context integration. Embedding a model into the vulnerability discovery workflow does not replace the researcher’s judgment; rather, it delegates tedious mechanical operations, context transcription, and preliminary summarization to the model, freeing the researcher to focus on attack strategy design, boundary condition derivation, and higher-level reasoning.
From Concept to Architecture
Macro Workflow Design
The design philosophy can be summed up in one sentence: wrap every tool in the research workflow as an MCP service, use an AI coding tool as the orchestration core, and drive a closed loop through conversation.
The workflow is divided into four main stages:
Stage One: Target Onboarding and Attack-Surface Mapping. The system automatically identifies the target environment—OS version, running services, open ports, file types—and makes a preliminary attack-surface assessment. The resulting attack-surface inventory serves as input for subsequent analysis and fuzzing.
Stage Two: Static Analysis and Semantic Understanding. Using decompiler output, the system automatically locates key functions (input handlers, data parsers, permission checks), maps their call relationships into a logical call chain, and flags potential risk points.
Stage Three: Directed Fuzzing and Crash Reproduction. Based on the attack-surface inventory and call chain, the system generates targeted test cases and drives the fuzzer to perform mutation-based input generation. On a crash, the system immediately captures the crash context and performs minimal reproduction to ensure the crash can be deduplicated and classified.
Stage Four: Root-Cause Analysis and Report Generation. The system analyzes the crash context, infers the crash type (stack overflow, heap overflow, use-after-free, integer overflow, logic error, etc.), marks the suspicious code path, and generates a vulnerability report with reproduction steps, impact scope, and remediation suggestions.
These four stages are not strictly linear. They form an iterative loop: crash data from Stage Three feeds back into Stage Two to re-examine the call chain for similar risks, and root-cause findings from Stage Four may trigger a new round of directed testing on specific code paths.
MCP’s Role in the System
MCP is not “just another tool” in this architecture. It acts as the neural endings of the system, abstracting isolated command-line tools, scripts, and debugger operations into functions the model can directly invoke, achieving seamless integration between tool capability and model reasoning.
In the implementation, each MCP server runs as an independent Python process and registers a set of tool functions. The model communicates with servers over standardized JSON-RPC messages, passing parameters and receiving return values. This design offers several advantages:
- Modular isolation: each tool runs independently, so a failed call does not contaminate other modules.
- Type constraints: inputs and outputs use structured type definitions, significantly reducing parameter misuse by the model.
- Extensibility: adding a new tool only requires registering a function, with no changes to the core orchestration logic.
In practice, more than ten MCP tools were registered, covering environment identification, binary analysis, corpus generation, crash analysis, and report drafting. The value of MCP is not to replace existing tools but to connect them—enabling the model to invoke established command-line tools and scripts in a standardized way and reuse their mature engineering capabilities.
Core Implementation: From Tools to Services
Environment Identification Module
Environment identification is the first step in automated discovery and the foundation of all subsequent decisions. The system implements an environment probe that automatically:
- Determines the OS and kernel version.
- Probes network services and exposed ports.
- Collects the target binary’s architecture, protection mechanisms, and dependency libraries.
- Outlines the file system structure.
All this information is returned to the model as structured JSON. The model consolidates it into a “target profile” for continuous reference in the conversational context. This avoids repeated queries for the same information and significantly reduces token consumption and context confusion.
Fuzzing and Crash Handling
Fuzzing is indispensable in modern vulnerability discovery. The module’s design is: the model generates high-value initial seed corpora from prior static analysis, rather than relying on generic dictionaries. For a service parsing a specific protocol, for instance, the model can construct initial cases with boundary values based on protocol field semantics, then hand them to the fuzzer for mutation.
For crash handling, the system implements a complete “crash receiver”: when the target crashes, the module immediately captures the crash context (register snapshot, stack backtrace, faulting instruction), archives it with tags, and returns a summary to the model. The model then infers the crash type and decides whether minimal reproduction is needed.
One implementation detail worth noting: crash context capture must be timely. To avoid losing crash information, the module writes the raw snapshot to disk asynchronously and then synchronously returns a condensed summary to the model. The model makes decisions from the summary, while the full snapshot remains available on disk for later retrieval.
Context Compression and Core Philosophy
A critical design lesson emerged during system evolution: the model’s context window is a finite resource, and every piece of context entering it should be treated as high value.
In early iterations, the author fed large volumes of raw tool output directly to the model, causing context overload and rapid degradation in analysis quality. After repeated adjustments, a “layered filtering + semantic compression” strategy was adopted:
- Execution layer: raw tool output stays within the module and never enters the model directly.
- Summarization layer: before returning, each module condenses raw output to the minimal information required for the model’s decisions.
- Annotation layer: high-frequency information (e.g., function addresses, key paths) is referenced by short aliases in conversation to avoid repeated full transmission.
The principle is: the model should see a distilled knowledge graph, not raw data. This strategy is the key to sustained high-quality analysis.
Practical Results: From Real Discoveries to Findings
Case Overview
Within weeks of the system’s completion, it was applied to in-depth discovery against multiple fuzzing targets, covering common file parsers, network services, and protocol implementations. Overall results were substantial:
Case 1: An open-source message-parsing library. The system automatically identified missing error-handling paths under malformed input. Through directed corpus generation, it triggered a buffer overflow under standardized input. From deployment to crash reproduction took less than two hours, without human intervention.
Case 2: An embedded device’s management interface. During attack-surface mapping, the system discovered that the interface exposed multiple undocumented debug commands. Static analysis then revealed integer-overflow risks in these commands. The model designed a minimal trigger sequence that successfully crashed the device remotely.
Case 3: A desktop application’s multimedia processing component. The component’s complex state machine posed the main analysis challenge. The system employed a phased strategy: model the input container format at the protocol level, then explore internal state transitions through fuzzing, and ultimately find a use-after-free vulnerability in an obscure field combination.
These cases share a common characteristic: the system does not depend on purely random, brute-force input. It relies on semantic understanding of the target to generate highly targeted test cases and abnormal scenario combinations, significantly improving the probability of discovering deep logical vulnerabilities.
Efficiency Comparison and Quantified Gains
Compared with traditional manual workflows, the automated system provided notable efficiency gains:
- Environment setup: reduced from 30–60 minutes to under 5 minutes (model-driven tool orchestration).
- Attack-surface analysis: reduced from 1–2 hours of reading decompiler output to 10–15 minutes (model directly outputs key function lists and call chains).
- Crash analysis: reduced from approximately 1 hour per crash to approximately 10 minutes (model helps locate key bytes and trigger paths).
- Report drafting: reduced from 30–60 minutes of manual writing to 5–10 minutes (model auto-generates an initial draft from complete logs).
Perhaps more importantly, the system can continue working while the researcher rests, performing large-scale corpus mutation exploration as a low-priority background task. This 24/7 operation capability is beyond what traditional manual discovery can achieve.
Key Engineering Challenges and Countermeasures
Challenge 1: Effective Tool-Call Expression
In early experiments, the model frequently invoked tools with incomplete parameters or ambiguous semantics—for instance, passing a vague keyword instead of standardized filters when requesting a process list. The solution was to provide highly structured input definitions at MCP service registration time, including required fields, types, and enum ranges. The system also increased the detail granularity of tool descriptions and included ample calling examples for the model.
Challenge 2: Controlling Single-Task Execution Duration
Because the model makes autonomous decisions, certain tasks could enter prolonged recursive loops—for example, repeatedly calling the same tool to retrieve redundant information. The solution was to add timeout mechanisms and maximum call-count limits at the tool invocation layer. When the model invokes the same tool more than five times in one conversational round, the orchestration core proactively interrupts and asks for the model’s intent, avoiding computational deadlocks.
Challenge 3: Gaining Model Trust in Tool Return Values
A subtler issue arose when the model questioned tool results, especially when the information conflicted with its prior knowledge. The system introduced a “fact chain” mechanism at the design stage: tool return values are treated as factual anchors, and the model is explicitly instructed that “tool return values are objective facts about the current system state and should be trusted.” This reduced subjective speculation.
Challenge 4: Cross-Session State Retention
Security research is a long-running process, and the model needs to retain analysis context from previous days. However, context-window limits prevent unbounded historical memory. The solution was to persist each day’s key conclusions as structured “memory summary” files and automatically load them at session start, ensuring continuity of the analysis process.
Reflections and Future Directions
Boundaries and Limitations
The system substantially improves discovery efficiency, but significant boundaries remain:
- Dependence on reverse-engineering quality: heavily obfuscated or packed binaries degrade static analysis accuracy, reducing the system to black-box fuzzing.
- Limited adaptability to unknown threats: model knowledge is bounded by its training-data time range; effective analysis of brand-new instruction set architectures or proprietary protocols remains limited.
- Complex logic vulnerabilities: multi-step vulnerability chains that depend on specific business logic are still beyond the model’s autonomous reasoning depth.
Semantic Enhancement and Multi-Agent Collaboration
The next phase of optimization focuses on two dimensions:
Semantic enhancement: introducing finer-grained instruction-level semantic annotations to further strengthen the model’s binary semantics understanding, allowing automatic inference of variable physical constraint ranges during static analysis.
Multi-agent collaboration: a main planner model orchestrates the plan while multiple executor sub-agent models each manage a subtask module, enabling parallel analysis and overcoming the physical context-window limits of a single model.
Summary
Embedding AI coding tools into the full lifecycle of vulnerability discovery through MCP validates both the technical feasibility of LLMs in security automation and a new security research paradigm: a model with strong understanding and reasoning skills, supported by standardized tool-calling interfaces, can take over the substantial mechanical work in security research, freeing expert attention to focus on strategic thinking that truly requires human intelligence.
From a technology-evolution perspective, MCP’s core value lies in standardizing the interaction protocol between models and tools, dramatically expanding the capability boundaries of intelligent agents. As model reasoning continues to improve and the tool ecosystem matures, LLMs will play an increasingly significant role in vulnerability research. For security practitioners, actively embracing these new technologies and integrating them into existing research workflows will be a decisive advantage in the future offense-defense landscape.
