This Azure Logs MCP server enables secure querying of Azure Log Analytics Workspace (Application Insights) to retrieve request logs based on order numbers.
Core Capabilities:
Search logs by order number: Query request logs containing specific order numbers in request names, URLs, or custom dimensions
Flexible time ranges: Query logs over customizable periods using ISO 8601 duration format (e.g., P7D for 7 days, PT24H for 24 hours; default: 7 days)
Configurable results: Control returned entries (1-1000 results, default: 50)
Comprehensive log data: Access timestamps, URLs, response codes, duration, and custom dimensions
Security Features:
Input validation and sanitization to prevent injection attacks
Rate limiting (10 requests/minute per client)
Error sanitization to prevent information disclosure
Query timeout protection (30 minutes)
Authenticated access via Azure Service Principal credentials
Deployment & Operations:
Multiple transport modes: Supports stdio (traditional MCP) and SSE (web-based) protocols
OCI-compliant containers: Full Docker and Podman support
Health monitoring: Built-in health checks and structured logging with configurable levels
Development tools: Hot reloading, MCP inspector integration, and debugging support
Configuration Requirements:
Requires Azure credentials (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET) and AZURE_MONITOR_WORKSPACE_ID.
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 Logs MCPshow logs for order #123456 from the last 24 hours"
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 Logs MCP
A TypeScript-based MCP (Model Context Protocol) server that provides tools to fetch logs from Azure Log Analytics Workspace based on search terms (e.g., order numbers, transaction IDs). 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
Related MCP server: Azure Resource Graph MCP Server
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:
cp .env.example .envEdit the
.envfile 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:
npm installDevelopment
Building the Project
Compile TypeScript to JavaScript:
npm run buildDevelopment Mode
Run the server in development mode with hot reloading:
npm run devRun the SSE server in development mode:
npm run dev:sseRun with MCP inspector for debugging:
npm run dev:inspectorProduction Mode
Build and start the server:
npm run build
npm startCode Quality
Type check the code:
npm run type-checkLint the code:
npm run lintFormat the code:
npm run formatClean build artifacts:
npm run cleanContainer 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)
# Build and run with Podman
npm run container:build
npm run container:run
# Or manually
podman build -f Containerfile -t azure-logs-mcp .
podman run --env-file .env -p 3000:3000 azure-logs-mcpQuick Start with Docker
# Build and run with Docker
npm run docker:build
npm run docker:run
# Or manually
docker build -f Containerfile -t azure-logs-mcp .
docker run --env-file .env -p 3000:3000 azure-logs-mcpOCI 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
# Podman examples
podman run --env-file .env -e TRANSPORT_MODE=sse -p 3000:3000 azure-logs-mcp
podman run --env-file .env -e TRANSPORT_MODE=stdio azure-logs-mcp
# Docker examples
docker run --env-file .env -e TRANSPORT_MODE=sse -p 3000:3000 azure-logs-mcp
docker run --env-file .env -e TRANSPORT_MODE=stdio azure-logs-mcpFor 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:
node dist/index.jsOr for development:
npm run devAvailable Tools
searchLogs
Description: Searches request logs from Azure Log Analytics Workspace that contain the specified search term in the request name, URL, or custom dimensions.
Parameters:
searchTerm(required): The term to search for in the logs (e.g., order number, transaction ID)Type: string
Format: Alphanumeric characters, hyphens, underscores, and dots only
Length: 1-100 characters
Pattern:
^[A-Za-z0-9\-_.]+$
limit(optional): Maximum number of results to returnType: number
Range: 1-1000
Default: 50
duration(optional): Time range for the queryType: string
Format: ISO 8601 duration format
Examples: "P7D" (7 days), "PT24H" (24 hours), "P30D" (30 days)
Default: "P7D" (7 days)
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 specified duration (default: last 7 days)
Looks for the search term in request names, URLs, and custom dimensions
Returns up to the specified limit of 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-logs: Azure Monitor logs query client
@modelcontextprotocol/sdk: Official MCP SDK
cors: Cross-Origin Resource Sharing middleware
dotenv: Environment variable management
express: Fast, unopinionated web framework for Node.js
zod: Runtime type validation and parsing
Development Dependencies
typescript: TypeScript compiler and language support
@types/cors: TypeScript definitions for CORS
@types/express: TypeScript definitions for Express
@types/node: Node.js type definitions
tsx: TypeScript execution for development
eslint: Code linting and style enforcement
@typescript-eslint/eslint-plugin: TypeScript-specific ESLint rules
@typescript-eslint/parser: TypeScript parser for ESLint
rimraf: Cross-platform file deletion utility
Project Structure
azure-logs-mcp/
βββ src/ # TypeScript source files
β βββ index.ts # Main server entry point and transport mode selector
β βββ appinsights.ts # Azure Log Analytics Workspace integration
β βββ http-server.ts # HTTP server utilities for SSE mode
β βββ server-common.ts # Common server functionality and tools
β βββ sse-server.ts # Server-Sent Events (SSE) transport mode
β βββ stdio-server.ts # Standard I/O transport mode
β βββ types.ts # Type definitions and schemas
β βββ utils.ts # Utility functions (logging, rate limiting)
βββ dist/ # Compiled JavaScript output (generated)
βββ .containerignore # Container build ignore patterns
βββ .env.example # Environment variables template
βββ .eslintrc.json # ESLint configuration
βββ .gitignore # Git ignore patterns
βββ .prettierrc # Prettier code formatting configuration
βββ Containerfile # OCI-compliant container build instructions
βββ DEPLOYMENT.md # Detailed deployment instructions
βββ IMPLEMENTATION_GUIDE.md # Implementation and development guide
βββ LICENSE # Project license
βββ OCI-COMPLIANCE.md # Open Container Initiative compliance details
βββ package.json # Project configuration and dependencies
βββ package-lock.json # Locked dependency versions
βββ README.md # This file
βββ tsconfig.json # TypeScript configurationEnvironment 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:
import { healthCheck } from './appinsights';
try {
await healthCheck();
console.log('Azure connection verified');
} catch (error) {
console.error('Health check failed:', error);
}Logging
The server uses structured logging with configurable levels. You can control the log level using the LOG_LEVEL environment variable:
# Set log level to DEBUG for development
export LOG_LEVEL=3
npm run dev
# Set log level to ERROR for production (only errors)
export LOG_LEVEL=0
npm startLog 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
# Development
npm run dev # Run stdio mode in development
npm run dev:sse # Run SSE mode in development
npm run dev:inspector # Run with MCP inspector for debugging
# Production
npm run start # Run stdio mode in production
npm run start:sse # Run SSE mode in production
# Build and Quality
npm run build # Compile TypeScript to JavaScript
npm run clean # Clean build artifacts
npm run type-check # Type check without emitting files
npm run lint # Lint and fix TypeScript files
npm run format # Format code with Prettier
# Container (OCI-compliant, works with any runtime)
npm run container:build # Build with Podman (recommended)
npm run container:run # Run with Podman
# Docker (traditional)
npm run docker:build # Build Docker image
npm run docker:run # Run container with .env file
# Podman (explicit)
npm run podman:build # Build with Podman
npm run podman:run # Run with PodmanSSE Mode Features
When running in SSE mode, the server provides:
SSE Endpoint:
GET /sse- MCP Server-Sent Events endpointHealth Check:
GET /health- Service health verificationCORS 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.