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., "@Azure Security MCP AgentAudit my Azure infrastructure for security misconfigurations."
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.
Azure Security MCP Agent
An AI-powered agent that uses Model Context Protocol (MCP) tools and a Groq LLM to analyze the security of your Azure infrastructure.
The design is inspired by the YouTube example yt-mcp-agent github.com/ShawhinT/yt-mcp-agent but adapted for cloud security and Azure.
Overview
This project shows how to build a security-focused AI agent that can:
Discover resources across an Azure subscription
Analyze Network Security Groups (NSGs) for dangerous rules
Audit storage accounts for insecure configuration
List public IPs and identify exposed assets
Check basic VM security posture
Explain risks and relate them to CIS Azure best practices (you can reference the included CIS PDF)
There are three main entry points:
main.py– OpenAI Agents SDK + MCP tools (Groq model) – recommended pathagent.py– LangChain/LangGraph ReAct-style agent using the same MCP toolsdemo.py– Offline Groq-only demo using mock Azure data (no Azure access required)
Architecture
Key Components
server.py
FastMCP-based MCP server (FastMCP("azure-security-analyzer")) exposing tools like:azure_list_resource_groupsazure_list_nsgsazure_list_storage_accountsazure_list_resourcesazure_check_nsg_rulesazure_check_storage_securityazure_list_public_ipsazure_check_vm_security
It also exposes asystem_promptvia@mcp.prompt()that reads fromprompts/system_instructions.md.
main.py
Uses the OpenAI Agents SDK (agents.Agent,MCPServerStdio) to:Start the MCP server (
server.py) as a subprocess over stdioAttach all MCP tools to the agent automatically
Use Groq as the model via the OpenAI-compatible API
Provide a simple terminal loop where you type natural-language security questions
agent.py
An alternative LangChain/LangGraph implementation that:Connects to the same MCP server
Wraps MCP tools into LangChain tools
Uses a ReAct-style graph to decide which Azure tools to call
demo.py
Offline demo that feeds mock Azure findings (e.g. open NSG rules, insecure storage settings) into Groq and asks it to produce a security report. Useful when you don’t have real Azure access.prompts/system_instructions.md
System instructions for the agent (how to interpret tool results, severity levels, report format, etc.). You can customize this to align more strictly with the CIS Microsoft Azure Compute Services Benchmark (the PDF included in this repo).
Prerequisites
Python 3.10+
Azure subscription with at least some test resources
Azure CLI (
az) for local authenticationGroq account + API key (
https://console.groq.com)(Optional) Basic familiarity with CIS Azure benchmarks
Setup
1. Create and activate a virtual environment
Windows (PowerShell):
Linux / macOS:
Re-activate the venv in each new terminal before running the project.
2. Authenticate to Azure
3. Configure environment variables
Create a .env file in the project root:
These are read by both main.py and agent.py.
Running the Agent (OpenAI Agents SDK + MCP tools)
This path is closest to the yt-mcp-agent example and is the recommended way to use the project.
You’ll see a prompt like:
Example questions you can ask:
“Discover my Azure resource groups and list any NSGs with open SSH or RDP.”
“List storage accounts in my subscription and tell me which ones violate CIS recommendations.”
“Give me a security review of NSG rules in resource group
rg-security-demo.”“Find all public IPs and summarize which services they expose.”
Behind the scenes the agent will:
Use MCP tools (e.g.
azure_list_resource_groups,azure_list_nsgs,azure_check_nsg_rules)Combine those results with the system instructions and your question
Ask Groq’s model to produce a structured security analysis and recommendations
Alternative: LangChain / LangGraph CLI (agent.py)
If you want to see how the same MCP tools plug into LangChain/LangGraph, run:
This script:
Connects to the MCP server via stdio
Wraps Azure MCP tools as LangChain tools
Uses a ReAct-style graph to decide which tools to call and in what order
Use this when you want to experiment with chain/graph-based orchestration rather than the OpenAI Agents SDK.
Offline Demo (demo.py)
If you don’t have Azure access or just want to see the security reasoning piece:
demo.py feeds mock NSG, storage, public IP, and VM findings into Groq and asks the model to:
Prioritize findings by severity
Explain risks in plain language
Suggest remediation steps (e.g. align with CIS controls)
No Azure calls or MCP server are needed for this demo, just your GROQ_API_KEY.
MCP Tools (Server-Side Capabilities)
The MCP server (server.py) exposes the following tools to whichever agent you use.
Discovery tools (use these when you don’t know exact resource names):
azure_list_resource_groups(subscription_id)– List all resource groups in the subscription.azure_list_nsgs(subscription_id, resource_group=None)– List NSGs across the subscription or within a specific resource group.azure_list_storage_accounts(subscription_id, resource_group=None)– List storage accounts.azure_list_resources(subscription_id, resource_group=None)– Generic resource inventory (name, type, location, resource group).
Analysis tools:
azure_check_nsg_rules(subscription_id, resource_group, nsg_name)Flags wildcard sources (
*,Internet)Detects dangerous ports (22, 3389, 1433, 3306, 5432, 27017, 6379)
Warns on “all ports open” (
destination_port_range="*")
azure_check_storage_security(subscription_id, resource_group, storage_account_name)Checks public blob access, HTTPS-only, TLS version, encryption status.
azure_list_public_ips(subscription_id, resource_group=None)Lists all public IPs, where they live, and notes that they expose resources to the internet.
azure_check_vm_security(subscription_id, resource_group, vm_name)Looks for missing managed identities and disk encryption issues.
The agent doesn’t hard-code Azure logic; it just calls these tools and reasons over their JSON outputs.
What the Agent Detects (Examples)
Network Security
Wildcard source addresses (
*,Internet,0.0.0.0/0)Open SSH/RDP/SQL ports to the internet
Rules that allow all ports
Storage Security
Public blob access enabled
HTTPS-only not enforced
Weak TLS minimum version
Missing or misconfigured encryption
VM Security
VMs without managed identity
Unencrypted OS disks (or encryption not explicitly configured)
Exposure & Posture
Public IP inventory
Resource misconfigurations compared to baseline best practices
You can refine or formalize these checks against the provided CIS Azure PDF.
Security & Best Practices
Do not commit – it contains secrets.
Run initially against non-production subscriptions.
Ensure you have at least Reader permissions for the subscription.
Treat the agent’s output as advice, not an automatic “source of truth” – always validate before making changes.
Extending the Project
Ideas for next steps:
Add more Azure services (Key Vault, SQL, App Service, AKS, etc.).
Encode more CIS controls directly into
server.pytools.Add a small web UI on top of
main.pyflows.Persist findings and generate trend/compliance reports.
Add multi-cloud support (AWS, GCP) with additional MCP servers.
Inspiration & References
Inspiration:
yt-mcp-agent– YouTube analysis agent using MCP and the OpenAI Agents SDK.MCP Documentation:
https://modelcontextprotocol.ioAzure SDK for Python:
https://learn.microsoft.com/azure/developer/python/Groq API Docs:
https://console.groq.com/docsCIS Azure Benchmark:
https://www.cisecurity.org/benchmark/azure
License
MIT – feel free to use and adapt this project for your own experiments and learning.
Azure Security MCP Agent
An AI-powered agent for analyzing Azure infrastructure security using Model Context Protocol (MCP) and Groq's free LLM API.
🎯 Project Overview
This project demonstrates a simple but powerful AI agent that can:
Discover Azure resources across your subscription
Analyze Network Security Groups (NSGs) for misconfigurations
Check storage account security settings
Identify public IP exposure
Audit VM security configurations
Provide actionable security recommendations based on CIS benchmarks
🏗️ Architecture
🚀 Quick Start
1. Prerequisites
Python 3.8+
Azure subscription with resources to analyze
Groq API key (free from https://console.groq.com)
Azure credentials (Azure CLI recommended)
2. Installation (avec environnement virtuel recommandé)
Oui, utilisez un virtual env pour éviter les conflits de paquets.
Windows (PowerShell ou CMD) :
Linux / macOS :
Ensuite, à chaque nouvelle session, réactivez le venv avant de lancer le projet :
Windows :
.\venv\Scripts\Activate.ps1Linux/macOS :
source venv/bin/activate
3. Azure Setup (Simple Test Infrastructure)
Simplest way to prove the agent works: Create one resource group, one NSG with one insecure rule, and one storage account with one bad setting. Then run the agent and choose option 6 (Full discovery and security scan) — the agent will discover everything and report the issues.
Option A: Using Azure Portal (Easiest for beginners)
Create a Resource Group:
Go to Azure Portal (portal.azure.com)
Click "Resource groups" → "Create"
Name:
rg-security-demoRegion:
East USClick "Review + Create" → "Create"
Create a Storage Account:
Search for "Storage accounts" → "Create"
Resource group:
rg-security-demoName:
secdemostorage<random>(must be globally unique)Region:
East USPerformance:
StandardRedundancy:
LRSAdvanced tab:
Enable "Allow Blob public access" (for testing - we'll flag this!)
Disable "Require secure transfer" (for testing - we'll catch this!)
Click "Review + Create" → "Create"
Create a Network Security Group:
Search for "Network security groups" → "Create"
Resource group:
rg-security-demoName:
nsg-demoRegion:
East USClick "Review + Create" → "Create"
After creation, click "Inbound security rules" → "Add"
Add a rule:
Source:
Any(*)Destination port:
22(SSH)Action:
AllowName:
allow-ssh-any
This creates a security issue for the agent to find!
Create a Virtual Machine (Optional):
Search for "Virtual machines" → "Create"
Resource group:
rg-security-demoVM name:
vm-demoRegion:
East USImage:
Ubuntu Server 20.04 LTSSize:
B1s(cheapest)Authentication: SSH public key
Select inbound ports: SSH (22)
Click "Next" through tabs, then "Review + Create"
Option B: Using Azure CLI (Faster)
4. Configure Authentication
Azure CLI (Recommended)
Environment Variables
Add:
Get your subscription ID:
5. Lancer le projet (Run the Agent)
Résumé des étapes :
Créer et activer le virtual env (une seule fois) :
cd c:\Users\MSI\mcp_project python -m venv venv .\venv\Scripts\Activate.ps1 pip install -r requirements.txtFichier à la racine du projet avec :
GROQ_API_KEY=gsk_xxxx AZURE_SUBSCRIPTION_ID=votre-subscription-id(Clé Groq : https://console.groq.com — Subscription ID :
az account show --query id -o tsv)Se connecter à Azure (dans le même terminal où vous lancez l’agent) :
az loginLancer l’agent (avec le venv activé) :
python agent.pyDans le menu, taper 6 pour un scan complet (découverte + analyse) sans saisir de noms de ressources.
To show the agent working end-to-end: Choose 6 (Full discovery and security scan). The agent will list resource groups, discover NSGs and storage accounts, run security checks, and return a report — no need to type resource names.
📋 Usage Examples
Quick proof (no resource names needed)
Create a simple Azure setup: one resource group (e.g.
rg-security-demo), one NSG with an “allow SSH from Any” rule, and one storage account with “Allow public blob access” enabled.Run
python agent.py, then choose 6 (Full discovery and security scan).The agent will discover your resource groups, NSGs, and storage accounts, run security checks, and output a report with findings and recommendations.
Example 1: Analyze NSG Rules
The agent will:
Call the
azure_check_nsg_rulestoolAnalyze all inbound/outbound rules
Flag dangerous configurations (open ports, wildcard sources)
Provide recommendations
Example 2: Audit Storage Account
The agent will check:
Public access settings
HTTPS enforcement
Encryption status
TLS version
Example 3: Custom Query
🛠️ Available Tools
The MCP server provides these tools:
Discovery (use these first when you don’t know resource names):
azure_list_resource_groups - List all resource groups in the subscription
azure_list_nsgs - List all NSGs (optionally in a resource group)
azure_list_storage_accounts - List all storage accounts (optionally in a resource group)
azure_list_resources - List all resources in subscription or resource group
Analysis: 5. azure_check_nsg_rules - Analyze NSG for security issues (open ports, wildcard rules) 6. azure_check_storage_security - Audit storage account configuration 7. azure_list_public_ips - Find all public IP addresses 8. azure_check_vm_security - Check VM security settings
🔍 What the Agent Detects
Network Security
✓ Wildcard source addresses (*)
✓ Exposed dangerous ports (22, 3389, 1433, etc.)
✓ Overly permissive rules
✓ All ports open (*)
Storage Security
✓ Public blob access enabled
✓ HTTPS-only not enforced
✓ Weak TLS versions
✓ Encryption status
VM Security
✓ Missing managed identities
✓ Unencrypted disks
✓ Missing security extensions
General
✓ Public IP exposure
✓ Resource misconfigurations
✓ CIS benchmark violations
📊 Sample Output
🔐 Security Best Practices
Never commit - It contains secrets
Use Azure CLI for local development - Easiest auth method
Use service principals for production - More secure
Review agent recommendations - Human oversight is important
Test on non-production first - Always test safely
🚧 Extending the Agent
Adding New Tools
Edit server.py and add new tool functions:
Adding More Azure Services
Install additional Azure SDK packages:
Then add clients in server.py:
📝 Troubleshooting
Nothing displays when I run python agent.py
You should see at least:
Azure Security Agent — starting...thenStarting MCP server...thenConnecting to MCP server.... If you see nothing at all, run from the project folder:cd c:\Users\MSI\mcp_projectand ensure your venv is activated.If it stops at Connecting to MCP server... and hangs, the MCP handshake may be stuck (e.g. server and client waiting on each other). Try running again; if it persists, check that
server.pyruns alone:python server.py(it will wait for stdin — that’s normal; press Ctrl+C to exit).If it asks for Azure Subscription ID, type your subscription ID and press Enter (or add
AZURE_SUBSCRIPTION_IDto.env).
"Failed to initialize Azure clients"
Run
az loginto authenticateVerify subscription ID is correct
Check Azure permissions (Reader role minimum)
"Error: GROQ_API_KEY not found"
Create
.envfile from.env.exampleAdd your Groq API key from console.groq.com
"Resource not found"
Verify resource names are correct
Check you're using the right subscription
Ensure resource group exists
Rate Limiting
Groq free tier: 30 requests/minute
Add delays if needed
Use smaller queries
🎯 Next Steps
Add more security checks:
Key Vault configuration
SQL database security
App Service settings
Kubernetes cluster security
Implement CIS benchmarks:
Azure CIS Benchmark v2.0
Automated compliance scoring
Remediation scripts
Add visualization:
Security score dashboard
Risk heat maps
Compliance reports
Multi-cloud support:
AWS security tools
GCP security tools
Cross-cloud comparison
📚 Resources
📄 License
MIT License - Feel free to use and modify for your project!
🤝 Contributing
This is a demo project for learning. Feel free to extend it for your needs!
Note: This is a simple demonstration. For production use, add:
Error handling
Logging
Rate limiting
Caching
Comprehensive test coverage
Remediation automation