Jatin Gupta
Jatin Gupta
Senior Architect @ HCL Tech
Jatin Gupta

Blog

Building an Autonomous DevSecOps Engine (Agentic AI + RAG + MCP + CI/CD)

Building an Autonomous DevSecOps Engine (Agentic AI + RAG + MCP + CI/CD)

DevSecOps Agentic AI Platform Engineering

Building an Autonomous DevSecOps Engine

Agentic AI + RAG + MCP + CI/CD — the deep technical guide to moving from brittle, hand-wired security scripts to an intent-driven control plane that reviews, tests, and proposes fixes for infrastructure and application code.

August 2026
14 min read
Applied AI Engineering
Faster reviews — Terraform, Security, and Kubernetes agents run in parallel, not serial
0
Bespoke tool wrappers once every scan tool is behind an MCP server
1
Risk-tiered control plane that auto-merges low risk and blocks hardcoded credentials
The Shift

From automated pipelines to autonomous engineering systems

The transition from automated pipelines to autonomous engineering systems requires a fundamental shift in architecture. You can no longer rely on brittle bash scripts piping output from one security tool to another. A script has a fixed shape: it runs the same commands in the same order and makes the same decisions regardless of what it finds. It cannot triage, cannot reason about severity, and cannot propose a fix.

Instead, you need a dynamic, intent-driven control plane. The system must observe a change, decide which checks matter, run them, interpret the results against your own policies, and act — autonomously where it is safe, escalating where it is not.

This guide details the technical implementation of combining Agentic AI, DevSecOps, RAG, MCP, and CI/CD into a single, cohesive engine that autonomously reviews, tests, and proposes fixes for infrastructure and application code.


Layer 01

The core execution engine: LangGraph

At the heart of this architecture is the AI Orchestrator. We use LangGraph to manage the execution flow, state, and decision-making of our multi-agent system. LangGraph allows us to define the DevSecOps process as a cyclical state machine rather than a linear script. Nodes are agent decisions; edges are transitions; cycles let the system re-plan when a check surfaces something unexpected.

The graph state must hold context references, PR metadata, and the accumulated findings of our specialized agents — Terraform, Kubernetes, Security, and the synthesizer that turns findings into a review.

# state_graph.py — the DevSecOps state machine from typing import TypedDict, List from langgraph.graph import StateGraph, END # 1. Define the State class DevSecOpsState(TypedDict): pr_id: str changed_files: List[str] context_versions: dict # refs to MCP/RAG context, not raw data terraform_findings: List[dict] security_findings: List[dict] k8s_findings: List[dict] final_review: str risk_level: str # 2. Initialize the Graph workflow = StateGraph(DevSecOpsState) # 3. Add Agent Nodes workflow.add_node("analyze_pr", analyze_pr_node) workflow.add_node("terraform_agent", run_terraform_checks) workflow.add_node("security_agent", run_security_checks) workflow.add_node("k8s_agent", run_k8s_checks) workflow.add_node("synthesize_review", synthesize_review_node) # 4. Define the Flow — parallel execution for speed workflow.set_entry_point("analyze_pr") workflow.add_edge("analyze_pr", "terraform_agent") workflow.add_edge("analyze_pr", "security_agent") workflow.add_edge("analyze_pr", "k8s_agent") # Synchronize the parallel agents into the synthesizer workflow.add_edge("terraform_agent", "synthesize_review") workflow.add_edge("security_agent", "synthesize_review") workflow.add_edge("k8s_agent", "synthesize_review") workflow.add_edge("synthesize_review", END) app = workflow.compile()
Engineering note: By running the Terraform, Security, and Kubernetes nodes in parallel, we drastically reduce the wall-clock time of the CI/CD pipeline. The three scans that used to run serially now overlap — the synthesizer only waits for the slowest.

Layer 02

The integration bus: Model Context Protocol (MCP)

A common anti-pattern is writing custom Python wrappers for every single DevSecOps tool — Trivy, Checkov, Kube-bench, each with its own CLI quirks and output formats. MCP (Model Context Protocol) eliminates this. It acts as the dependency injection layer for your agents, providing a standardized JSON-RPC interface to access external tools.

Your LangGraph nodes do not execute subprocess.run(["trivy", "fs", "."]). Instead, they declare a context requirement, and the MCP Client fetches it. The server executes the underlying binary securely and returns structured JSON findings back into the graph state.

# mcp_bus.py — connect LangGraph agents to MCP servers from mcp import McpClient from langchain_community.tools.mcp import MCPTool # Terraform MCP server (e.g. github.com/agenticdevops/tfmcp) tf_client = McpClient(endpoint="http://localhost:8080/terraform-mcp") tf_tools = [MCPTool(client=tf_client, name=t.name) for t in tf_client.list_tools()] # Kubernetes / Security MCP server k8s_client = McpClient(endpoint="http://localhost:8081/k8s-mcp") k8s_tools = [MCPTool(client=k8s_client, name=t.name) for t in k8s_client.list_tools()] # Bind the tools to the LLM driving that node llm_with_tf_tools = llm.bind_tools(tf_tools)

When the terraform_agent node executes, the LLM requests a drift check or a terraform plan. The MCP server runs the binary, parses the output into structured JSON, and hands it back. The agent never shells out directly — every tool call is mediated, logged, and governed by the bus.


Layer 03

RAG injection: enforcing enterprise context

Generic AI will tell you that a public IP on a Kubernetes service is fine. RAG ensures the AI knows your company policy strictly forbids it. This is the difference between a clever assistant and a governance-compliant reviewer.

The RAG pipeline sits alongside the orchestrator. Before the synthesize_review node generates its final PR comment, it queries an internal vector database — Azure AI Search, Qdrant — containing your architecture decision records (ADRs), Confluence wikis, and security policies. The retrieved policy is injected into the context window, grounding every recommendation in your internal corporate governance.

# rag.py — hybrid (keyword + vector) enterprise policy retrieval def retrieve_enterprise_policies(changed_files, findings): # Extract keywords from the files and tool findings query = generate_search_query(changed_files, findings) # Azure AI Search hybrid search: keyword + vector client = SearchClient(endpoint=AZURE_SEARCH_ENDPOINT, index_name="devsecops-policies") results = client.search( search_text=query.keyword, vector_queries=[VectorizedQuery( vector=query.embedding, k_nearest_neighbors=3, fields="contentVector", )], ) return format_docs(results)

Hybrid search matters here. Keyword matching catches exact policy titles ("no public IP on a service"); vector search catches semantic matches ("why is this load balancer exposed?"). Together they retrieve the right policy, and the retrieved policy is what constrains the agent's recommendation — not the model's generic training data.


Layer 04

CI/CD integration: GitHub Actions / Azure DevOps

The orchestrator must be triggered dynamically by the developer workflow. We containerize the LangGraph application and invoke it via a GitHub Action on every pull request — opened, synchronize, and reopened.

# .github/workflows/agentic-review.yml name: Agentic DevSecOps Review on: pull_request: types: [opened, synchronize, reopened] jobs: ai-orchestrator: runs-on: ubuntu-latest permissions: contents: read pull-requests: write id-token: write # required for OIDC / managed identities steps: - name: Checkout Code uses: actions/checkout@v4 - name: Authenticate via OIDC (Least Privilege) uses: azure/login@v1 with: client-id: ${{ secrets.AZURE_CLIENT_ID }} tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - name: Start MCP Servers run: | docker run -d -p 8080:8080 local/terraform-mcp-server docker run -d -p 8081:8081 local/k8s-mcp-server - name: Run Agentic Orchestrator env: OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_KEY }} PR_NUMBER: ${{ github.event.pull_request.number }} run: python run_orchestrator.py --pr $PR_NUMBER

Notice the least-privilege posture baked into the workflow. OIDC replaces long-lived credentials; the runner holds only the permissions the review actually needs; the MCP servers run in an ephemeral, isolated network that cannot reach the production VPC.


Layer 05

Security & risk-tiered governance

Autonomy without boundaries is a critical vulnerability. We enforce a Risk-Tiered Approval Model directly within the LangGraph routing logic. The synthesize_review node assigns a risk_level — Low, Medium, High, Critical — based on the MCP tool findings and RAG policy violations. Then a conditional edge decides what happens to the PR.

# governance.py — conditional edge routing by risk def route_based_on_risk(state: DevSecOpsState): risk = state.get("risk_level", "High") if risk == "Low": return "auto_merge_pr" # docs update, all checks pass elif risk == "Medium": return "request_team_lead" # standard app logic change elif risk == "High": return "request_sec_review" # IAM role modification detected else: return "block_and_escalate" # hardcoded AWS credential found # add the conditional edges to the graph workflow.add_conditional_edges("synthesize_review", route_based_on_risk)

Security guardrails to enforce

  • Network isolation. The MCP servers and the LangGraph container run in an ephemeral, isolated CI/CD runner network. They cannot reach the production VPC.
  • Secrets management. The AI does not have access to production secrets. If Terraform needs to plan against a live environment, it uses short-lived OIDC tokens retrieved dynamically by the CI/CD runner.
  • Auditability. Every tool invocation via MCP and every LLM API call is logged to a centralized SIEM (Splunk, Azure Sentinel) for full forensic traceability.

The Whole Thing

How the layers sit together

Assembled, the engine has a clear shape. GitHub Actions triggers the containerized orchestrator. LangGraph drives the state machine, running the three scan agents in parallel and synchronizing them into a synthesizer that grounds its review in RAG. The synthesizer assigns a risk tier, and governance routing decides the outcome — from auto-merge to hard block. Every step logs to the SIEM.

LangGraph PR review agent architecture GitHub Actions triggers a LangGraph orchestrator with four sub-nodes (analyze_pr, terraform, security, k8s) that synthesize into a risk tier, then fan out to MCP BUS, RAG, and Governance layers. SIEM captures the full audit trail at the bottom. GitHub Actions — trigger PR opened → containerized orchestrator · OIDC least-privilege LangGraph Orchestrator — state machine analyze_pr terraform security k8s synthesize_review → risk tier MCP BUS terraform · k8s · trivy json-rpc tool bus RAG ADRs · policies hybrid search Governance auto-merge · review block · escalate SIEM — audit trail every MCP tool call and LLM API call, logged for forensic traceability
The autonomous DevSecOps engine. Trigger → orchestrate in parallel → ground in RAG → govern by risk → audit everything.

Reference

The complete stack, and why each layer earns its place

LayerRoleAdopt it when
LangGraphExecution flow, state, decisionsYou need durable, parallel, branching control flow — not a linear script
MCPStandardized tool accessThe fifth tool wrapper costs more than the first four combined
RAGEnterprise policy enforcementA generic answer is not enough; your policies must shape every review
GitHub Actions / Azure DevOpsDynamic PR-driven triggerYou want review and testing on every push, not a manual gate
SIEMRisk-tiered approval + auditAutonomy requires boundaries and traceability from day one

The whole point is not to surface more alerts — it is to reason about them. The engine filters out the noise, grounds its judgement in your policy, and writes the fix. That is the difference between a pipeline that reports and an engine that acts.


The Takeaway

The pipeline stops being a pipeline and becomes a teammate

By mapping LangGraph's dynamic execution over MCP's standardized integration layer, and grounding the decisions in RAG, you build an engine that doesn't just surface alerts — it reasons about them, filters out the noise, and writes the fix. This is the blueprint for the next generation of platform engineering.

Start small: one scan agent behind an MCP server, one RAG index of your security policies, one conditional edge. Prove the loop on a low-risk repo. Then add the parallel agents, the risk tiers, and the auto-merge path. Autonomy is a capability you grow into, not a switch you flip.

AIOps Insights · Agentic AI, observability, and enterprise automation. Framework versions and repository locations move quickly — verify against each project's README before pinning.

Add Comment

Related Posts