gitops-drift-agent
Enables generating Pull Requests for drift remediation in GitOps repositories hosted on GitHub.
Enables generating Pull Requests for drift remediation in GitOps repositories hosted on GitLab.
Provides drift detection, policy evaluation, and remediation (patches) against Kubernetes clusters.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@gitops-drift-agentDetect drift in the production namespace and list the critical changes"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
GitOps Drift Remediation Agent
A production-grade autonomous agent that connects to Kubernetes clusters and GitOps repositories, identifies unauthorized state drift, generates safe remediation strategies, and executes automated API patches or Pull Requests.
Table of Contents
Related MCP server: kube-lint-mcp
Overview
The GitOps Drift Remediation Agent is an autonomous, policy-driven platform that continuously monitors the live state of Kubernetes resources against their declared GitOps source of truth. When drift is detected, the agent evaluates applicable remediation policies, computes minimal JSON Patch operations, and either applies them directly via the Kubernetes API or opens Pull Requests against the GitOps repository — all with full audit trails.
Core Principles
Minimal blast radius: patches are computed as the smallest possible diff, never full resource replacements
Policy-first: every remediation action is gate-kept by configurable, versioned policies with risk tiers
Immutable audit log: every decision, detection and mutation is recorded with cryptographic context
GitOps-native: the agent is itself managed by GitOps and emits PRs back to the repository
MCP-ready: exposes all capabilities as MCP tools for LLM-agent integration
Architecture
┌─────────────────────────────────────────────────────────────────────┐
│ GitOps Drift Remediation Agent │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌────────────────────────┐ │
│ │ AST Differ │───▶│ Policy Engine│───▶│ Patch Engine │ │
│ │ │ │ │ │ │ │
│ │ • Deep diff │ │ • Risk tiers │ │ • JSON Patch RFC 6902 │ │
│ │ • Field │ │ • Allow/deny │ │ • K8s API apply │ │
│ │ tracking │ │ • Dry-run │ │ • PR generation │ │
│ │ • Severity │ │ • Approvals │ │ • Rollback support │ │
│ └─────────────┘ └──────────────┘ └────────────────────────┘ │
│ │ │ │ │
│ └──────────────────┴───────────────────────┘ │
│ │ │
│ ┌────────▼────────┐ │
│ │ Audit Logger │ │
│ │ │ │
│ │ • Structured │ │
│ │ JSON logs │ │
│ │ • Event chain │ │
│ │ • Pino backend │ │
│ └─────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ MCP Server │ │
│ │ detect_drift │ list_policies │ remediate │ get_audit_trail │ │
│ └──────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
│ │
▼ ▼
┌─────────────┐ ┌───────────────┐
│ Kubernetes │ │ GitOps Repo │
│ Cluster(s) │ │ (Git/GitHub) │
└─────────────┘ └───────────────┘Features
Feature | Description |
Drift Detection | Deep AST-based diffing of live vs desired Kubernetes resource state |
Risk Classification | Automated severity scoring (critical / high / medium / low) per field path |
Policy Engine | Declarative, versioned policies with allow/deny rules, dry-run, and approval gates |
Patch Engine | RFC 6902 JSON Patch computation with K8s server-side apply support |
GitOps PRs | Automated Pull Request generation with drift diff and remediation rationale |
Audit Trail | Immutable structured audit logs with full decision chains |
MCP Server | All agent capabilities exposed as MCP tools for AI agent orchestration |
CLI | Full-featured CLI for interactive and automated operation |
Installation
Prerequisites
Node.js >= 20.0.0
kubectl configured with target cluster access
Git credentials for GitOps repository (for PR mode)
Install from source
git clone https://github.com/your-org/gitops-drift-remediation-agent.git
cd gitops-drift-remediation-agent
npm install
npm run build
npm link # optional: makes `drift-agent` available globallyConfiguration
All configuration is passed via environment variables or a config file.
Environment Variables
Variable | Required | Default | Description |
| No |
| Path to kubeconfig file |
| No | current-context | Kubernetes context to use |
| No | — | GitOps repository URL for PR mode |
| No |
| Target branch for PRs |
| No | — | Git provider token (GitHub/GitLab) |
| No |
| Path to remediation policy config |
| No |
| Audit log output path |
| No |
| Log level (debug/info/warn/error) |
| No |
| Global dry-run mode |
| No |
| MCP server HTTP port |
| No |
| Comma-separated namespace filter |
Usage
CLI Commands
# Detect drift across all namespaces
drift-agent detect --namespace production --output json
# Detect and auto-remediate with policy gate
drift-agent remediate --namespace production --policy strict --dry-run
# List active policies
drift-agent policy list
# Show audit trail for a resource
drift-agent audit --resource deployments/my-app --namespace production
# Start MCP server
drift-agent mcp-server --port 3000Programmatic API
import { AstDiffer } from './src/detector/ast-differ';
import { RemediationPolicy } from './src/policy/remediation-policy';
import { PatchEngine } from './src/remediator/patch-engine';
const differ = new AstDiffer();
const drifts = await differ.detectDrift(liveResource, desiredResource);
const policy = new RemediationPolicy(policyConfig);
const decision = await policy.evaluate(drifts, resourceContext);
if (decision.approved) {
const engine = new PatchEngine(k8sClient);
await engine.applyRemediation(decision.patches, resourceRef);
}MCP Server
The agent exposes an MCP (Model Context Protocol) server that makes all agent capabilities available as tools for LLM-based agents (Claude, GPT-4, etc.).
Starting the Server
drift-agent mcp-server --port 3000
# or
npm run mcp:serverAvailable MCP Tools
Tool | Description |
| Detect drift for a resource or namespace |
| List all configured remediation policies |
| Evaluate drift against a specific policy |
| Apply computed remediation patches |
| Retrieve audit events for a resource |
| Generate a GitOps PR for drift remediation |
| Roll back a previously applied remediation |
MCP Client Configuration
{
"mcpServers": {
"gitops-drift-agent": {
"url": "http://localhost:3000/mcp",
"transport": "http"
}
}
}Policy Engine
Policies are defined declaratively and control every aspect of the remediation lifecycle.
Policy Structure
apiVersion: drift.gitops.io/v1
kind: RemediationPolicy
metadata:
name: production-strict
spec:
riskTier: high
autoRemediate: false
requireApproval: true
dryRunFirst: true
rules:
- field: "spec.replicas"
action: restore
severity: high
- field: "spec.template.spec.containers[*].image"
action: block
severity: critical
excludeFields:
- "metadata.annotations['kubectl.kubernetes.io/last-applied-configuration']"
- "metadata.resourceVersion"
- "metadata.uid"Audit & Telemetry
Every agent action is recorded in structured JSON format:
{
"timestamp": "2024-06-01T12:00:00.000Z",
"eventId": "evt_01J0ABC123",
"eventType": "DRIFT_DETECTED",
"severity": "high",
"resource": {
"kind": "Deployment",
"name": "my-app",
"namespace": "production",
"apiVersion": "apps/v1"
},
"drift": {
"field": "spec.replicas",
"desired": 3,
"live": 1,
"changeType": "edited"
},
"policy": {
"name": "production-strict",
"decision": "remediate",
"riskTier": "high"
},
"actor": {
"agentVersion": "1.0.0",
"kubeContext": "prod-cluster"
}
}Development
# Install dependencies
npm install
# Run in development mode (ts-node)
npm run dev -- detect --namespace default
# Type check only
npm run typecheck
# Lint
npm run lint
# Format
npm run format
# Build
npm run buildTesting
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run in watch mode
npm run test:watchTests are organized under tests/ and use Jest with ts-jest. Mocks are provided for the Kubernetes client and file system operations.
Security Considerations
Least privilege: The agent requires only
get,list,watch, andpatchpermissions on target resources — neverdeleteorcreateDry-run by default: All policy tiers default to dry-run until explicitly enabled
Approval gates: High and critical risk changes require explicit approval via policy
Audit immutability: Audit logs are append-only; log rotation is handled externally
Secret masking: Secret resource values are always redacted in logs and PRs
Kubeconfig isolation: The agent never mutates the kubeconfig
Contributing
See CONTRIBUTING.md. All contributions require:
Passing test suite with >= 80% coverage
No new lint warnings
Audit log entries for any new mutation paths
Policy evaluation for any new remediation actions
License
Apache 2.0 — see LICENSE.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides MCP multi-cluster Kubernetes management and operations. It can be integrated as an SDK into your own project and includes nearly 50 built-in tools covering common DevOps and development scenarios. Supports both standard and CRD resources.149MIT
- AlicenseNot gradedqualityAmaintenanceMCP server to lint and validate Kubernetes-related manifests(Helm, FluxCD, ArgoCD, Kustomize, etc.)MIT
- AlicenseNot gradedqualityDmaintenanceEnables Git repository operations and real-time monitoring via MCP tools, with support for WebSocket events, authentication, and observability.174MIT
- FlicenseNot gradedqualityBmaintenancePolicy-as-code gate for AI-SDLC, providing MCP tools to review prompts, diff tool manifests, vet MCP servers, and run evaluation suites for LLM agent repos.1
Related MCP Connectors
Remote MCP for Copilot CLI switch gate MCP, structured receipts, audit logs, and reviewer-ready evid
Monitor MCP servers, API contracts and AI outputs for schema drift. Alerts on breaking changes.
Control plane for autonomous software labor. Agents claim objectives over MCP with audit trail.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/felipeassis10/gitops-drift-remediation-agent'
If you have feedback or need assistance with the MCP directory API, please join our Discord server