Azure Logs MCP
A TypeScript-based MCP (Model Context Protocol) server that provides tools to fetch logs from Azure Log Analytics Workspace based on order numbers. This service queries Azure Monitor logs using the Azure SDK and exposes the functionality through MCP tools for use with compatible clients.
Table of Contents
- Features
- Prerequisites
- Configuration
- Installation
- Development
- Container Deployment
- MCP Server Usage
- Error Handling
- Dependencies
- Project Structure
- Environment Variables
- Health Checks
- Logging
- Container Support
Features
- 🔒 Security: Input validation, sanitization, and rate limiting
- 📝 TypeScript: Full type safety and modern development experience
- 🚀 Performance: Efficient querying with timeouts and error handling
- 📊 Logging: Structured logging with configurable levels
- 🛡️ Validation: Comprehensive input validation using Zod schemas
- ⚡ Rate Limiting: Built-in protection against API abuse
- 🐳 OCI Compliant: Full Open Container Initiative compliance with Docker and Podman support
- 🔧 Multi-Runtime: Works with Docker, Podman, and any OCI-compatible container runtime
Prerequisites
Before using this application, you need to set up the following in Azure:
1. Create a Service Principal
- Navigate to the Azure Portal
- Go to Azure Active Directory > App registrations
- Click New registration
- Provide a name for your application (e.g., "Azure Logs MCP")
- Select the appropriate account types
- Click Register
- Note down the Application (client) ID and Directory (tenant) ID
- Go to Certificates & secrets > Client secrets
- Click New client secret
- Add a description and set expiration
- Click Add and copy the Value (this is your client secret)
2. Grant Log Analytics Reader Permissions
- Navigate to your Log Analytics Workspace resource in the Azure Portal
- Go to Access control (IAM)
- Click Add > Add role assignment
- Select Log Analytics Reader role
- In the Members tab, search for and select your Service Principal
- Click Review + assign
3. Get Log Analytics Workspace ID
- Navigate to your Log Analytics Workspace resource
- Go to Overview
- Copy the Workspace ID (this will be used as
AZURE_MONITOR_WORKSPACE_ID
)
Configuration
- Copy the environment variables template:
- Edit the
.env
file with your Azure credentials:- AZURE_CLIENT_ID: The Application (client) ID from your Service Principal
- AZURE_TENANT_ID: The Directory (tenant) ID from your Azure AD
- AZURE_CLIENT_SECRET: The client secret value you created
- AZURE_MONITOR_WORKSPACE_ID: The Workspace ID from your Log Analytics Workspace resource
Installation
Install the required dependencies:
Development
Building the Project
Compile TypeScript to JavaScript:
Development Mode
Run the server in development mode with hot reloading:
Production Mode
Build and start the server:
Code Quality
Type check the code:
Lint the code:
Clean build artifacts:
Container Deployment
This MCP server is fully OCI-compliant and supports multiple container runtimes including Docker, Podman, and any OCI-compatible runtime. Both stdio and SSE transport modes are supported.
Quick Start with Podman (Recommended)
Quick Start with Docker
OCI Compliance
This project follows Open Container Initiative standards:
- ✅ Multi-runtime support: Docker, Podman, Buildah, CRI-O, containerd
- ✅ Rootless containers: Enhanced security with Podman
- ✅ OCI labels: Proper metadata and annotations
- ✅ Standard formats: Containerfile and Dockerfile support
Transport Modes
- stdio mode (default): Traditional MCP protocol for direct connections
- SSE mode: Web-based transport for browser clients and remote connections
For detailed deployment instructions, see DEPLOYMENT.md. For OCI compliance details, see OCI-COMPLIANCE.md.
MCP Server Usage
Server Connection
Server Name: Azure Logs MCP
Transport: stdio (standard MCP protocol)
Connection Command:
Or for development:
Available Tools
getLogsByOrderNumber
Description: Retrieves logs from Azure Log Analytics Workspace that contain the specified order number in the request name, URL, or custom dimensions.
Parameters:
orderNumber
(required): The order number to search for in the logs- Type: string
- Format: Alphanumeric characters, hyphens, and underscores only
- Length: 1-50 characters
- Pattern:
^[A-Za-z0-9\-_]+$
Security Features:
- Input validation and sanitization
- Rate limiting (10 requests per minute per client)
- Error message sanitization
- Query timeout protection
Query Details:
- Searches logs from the last 30 days
- Looks for the order number in request names, URLs, and custom dimensions
- Returns up to 100 results ordered by timestamp (most recent first)
- Query timeout is set to 30 minutes
- Uses parameterized queries to prevent injection attacks
Response: The tool returns query results from Log Analytics Workspace, including:
timestamp
: When the request occurredname
: The request nameurl
: The request URLresultCode
: HTTP response codeduration
: Request durationcustomDimensions
: Additional custom data
Rate Limiting:
- Maximum 10 requests per minute per client
- Automatic cleanup of expired rate limit entries
- Graceful error messages when limits are exceeded
Error Handling
The server includes comprehensive error handling:
- Validation Errors: Input validation with detailed error messages
- Configuration Errors: Missing environment variables detected on startup
- Query Errors: Azure API failures with sanitized error messages
- Rate Limiting: Graceful handling of rate limit exceeded scenarios
- Timeout Protection: Query timeouts to prevent hanging requests
- Structured Logging: All errors logged with context and timestamps
Error Types
- ValidationError: Invalid input format or missing required fields
- ConfigurationError: Missing or invalid environment configuration
- QueryError: Azure Log Analytics Workspace query failures
- Rate Limit Exceeded: Too many requests from a single client
Security
- Error messages are sanitized to prevent information disclosure
- Sensitive information is redacted from logs
- Input validation prevents injection attacks
- Rate limiting protects against abuse
Dependencies
Runtime Dependencies
- @azure/identity: Azure authentication library
- @azure/monitor-query: Azure Monitor query client
- @modelcontextprotocol/sdk: Official MCP SDK
- dotenv: Environment variable management
- zod: Runtime type validation and parsing
Development Dependencies
- typescript: TypeScript compiler and language support
- @types/node: Node.js type definitions
- tsx: TypeScript execution for development
- eslint: Code linting and style enforcement
- @typescript-eslint/: TypeScript-specific ESLint rules
- rimraf: Cross-platform file deletion utility
Project Structure
Environment Variables
All environment variables are validated on startup. Missing required variables will cause the server to exit with an error.
Required Variables
AZURE_CLIENT_ID
: Application (client) ID from your Service PrincipalAZURE_TENANT_ID
: Directory (tenant) ID from your Azure ADAZURE_CLIENT_SECRET
: Client secret value you createdAZURE_MONITOR_WORKSPACE_ID
: Workspace ID from your Log Analytics Workspace resource
Optional Variables
NODE_ENV
: Set to 'development' for debug logging (default: 'production')LOG_LEVEL
: Override default log level0
= ERROR (only error messages)1
= WARN (warnings and errors)2
= INFO (info, warnings, and errors) - default for production3
= DEBUG (all messages) - default for development
Health Checks
The server includes a health check function that verifies Azure connectivity on startup:
Logging
The server uses structured logging with configurable levels. You can control the log level using the LOG_LEVEL
environment variable:
Log levels:
0
= ERROR: Only critical errors1
= WARN: Warnings and errors2
= INFO: General information, warnings, and errors (default for production)3
= DEBUG: All messages including debug information (default for development)
Container Support
Available Scripts
SSE Mode Features
When running in SSE mode, the server provides:
- SSE Endpoint:
GET /sse
- MCP Server-Sent Events endpoint - Health Check:
GET /health
- Service health verification - CORS Support: Configurable cross-origin resource sharing
- Web Integration: Compatible with browser-based MCP clients
Container Configuration
Additional environment variables for containerized deployments:
PORT
: Server port (default: 3000)TRANSPORT_MODE
: 'sse' or 'stdio' (default: sse)CORS_ORIGIN
: Allowed CORS origins (default: *)
For comprehensive deployment guidance, see DEPLOYMENT.md.
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Enables querying Azure Application Insights logs by order number through natural language. Provides secure access to Azure Monitor logs with comprehensive error handling and rate limiting.
Related MCP Servers
- AsecurityAlicenseAqualityAI assistants to query and analyze Azure Data Explorer databases through standardized interfaces.Last updated -445PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server for querying and analyzing Azure resources at scale using Azure Resource Graph, enabling AI assistants to explore and monitor Azure infrastructure.Last updated -110TypeScriptMIT License
- AsecurityFlicenseAqualityEnables large language models to automatically report customer-facing issues with Azure resources by parsing natural language requests and submitting impact reports through the Azure Management API.Last updated -12Python
- AsecurityFlicenseAqualityEnables AI systems to analyze documents and extract form data through Azure Form Recognizer/Document Intelligence, supporting various document types including receipts, invoices, and ID documents.Last updated -26102TypeScript