Skip to main content
Glama
rlaput

Azure Logs MCP

by rlaput

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: Kibana 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

  1. Navigate to the Azure Portal

  2. Go to Azure Active Directory > App registrations

  3. Click New registration

  4. Provide a name for your application (e.g., "Azure Logs MCP")

  5. Select the appropriate account types

  6. Click Register

  7. Note down the Application (client) ID and Directory (tenant) ID

  8. Go to Certificates & secrets > Client secrets

  9. Click New client secret

  10. Add a description and set expiration

  11. Click Add and copy the Value (this is your client secret)

2. Grant Log Analytics Reader Permissions

  1. Navigate to your Log Analytics Workspace resource in the Azure Portal

  2. Go to Access control (IAM)

  3. Click Add > Add role assignment

  4. Select Log Analytics Reader role

  5. In the Members tab, search for and select your Service Principal

  6. Click Review + assign

3. Get Log Analytics Workspace ID

  1. Navigate to your Log Analytics Workspace resource

  2. Go to Overview

  3. Copy the Workspace ID (this will be used as AZURE_MONITOR_WORKSPACE_ID)

Configuration

  1. Copy the environment variables template:

    cp .env.example .env
  2. 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:

npm install

Development

Building the Project

Compile TypeScript to JavaScript:

npm run build

Development Mode

Run the server in development mode with hot reloading:

npm run dev

Run the SSE server in development mode:

npm run dev:sse

Run with MCP inspector for debugging:

npm run dev:inspector

Production Mode

Build and start the server:

npm run build
npm start

Code Quality

Type check the code:

npm run type-check

Lint the code:

npm run lint

Format the code:

npm run format

Clean build artifacts:

npm run clean

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.

# 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-mcp

Quick 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-mcp

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

# 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-mcp

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:

node dist/index.js

Or for development:

npm run dev

Available 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 return

    • Type: number

    • Range: 1-1000

    • Default: 50

  • duration (optional): Time range for the query

    • Type: 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 occurred

  • name: The request name

  • url: The request URL

  • resultCode: HTTP response code

  • duration: Request duration

  • customDimensions: 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

  1. ValidationError: Invalid input format or missing required fields

  2. ConfigurationError: Missing or invalid environment configuration

  3. QueryError: Azure Log Analytics Workspace query failures

  4. 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 configuration

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 Principal

  • AZURE_TENANT_ID: Directory (tenant) ID from your Azure AD

  • AZURE_CLIENT_SECRET: Client secret value you created

  • AZURE_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 level

    • 0 = ERROR (only error messages)

    • 1 = WARN (warnings and errors)

    • 2 = INFO (info, warnings, and errors) - default for production

    • 3 = 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 start

Log levels:

  • 0 = ERROR: Only critical errors

  • 1 = WARN: Warnings and errors

  • 2 = 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 Podman

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.

Available Tools

1 tool
getRequestLogsByOrderNumberGet Request Logs by Order NumberB

Retrieves request logs from Azure Application Insights by order number. Searches through request logs containing the order number in name, URL, or custom dimensions.

ParametersJSON Schema
NameRequiredDescriptionDefault
durationNoTime range for the query in ISO 8601 duration format (default: P7D for 7 days)P7D
limitNoMaximum number of log entries to return (default: 50)
orderNumberYesThe order number to search for in the Azure Application Insights logs

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions retrieval and search behavior but fails to cover critical aspects like authentication requirements, rate limits, error handling, or the format of returned logs. This leaves significant gaps for a tool interacting with a cloud service.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and includes essential details about the search scope. Every word contributes value without redundancy, making it appropriately sized and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of querying Azure Application Insights, no annotations, and no output schema, the description is insufficient. It lacks details on authentication, response format, error cases, or operational constraints, leaving the agent with incomplete context for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with each parameter well-documented in the schema (e.g., duration format, limit range, orderNumber pattern). The description adds no additional parameter semantics beyond what the schema provides, so it meets the baseline but does not enhance understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('retrieves') and resource ('request logs from Azure Application Insights'), specifying the search scope (by order number in name, URL, or custom dimensions). However, with no sibling tools provided, it cannot demonstrate differentiation from alternatives, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for searching logs by order number in Azure Application Insights, but it does not explicitly state when to use this tool versus other methods or tools, nor does it provide exclusions or prerequisites. With no sibling tools, it lacks comparative guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

TDQS

B3.3/5.0
Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap between tools. The tool's purpose is clearly defined and distinct by default.

Naming Consistency5/5

A single tool inherently has perfect naming consistency, as there are no other tools to compare against. The name follows a clear verb_noun pattern (getRequestLogsByOrderNumber).

Tool Count2/5

One tool is too few for a server named 'Azure Logs MCP', which suggests a broader scope for interacting with Azure logs. This limits functionality to a single, specific query type, making the server feel incomplete for general log management.

Completeness2/5

The server is severely incomplete for its implied domain of Azure logs. It only supports retrieving logs by order number, with no tools for other common operations like querying by time range, filtering by other criteria, or managing log data.

Maintenance

ActivityInactive
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    Enables natural language exploration of Azure environments by generating and executing KQL queries against Azure Resource Graph. Supports multi-tenant configurations, subscription scoping, and provides direct access to Azure resource information through conversational interactions.
    8
    2
    Apache 2.0
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides seamless access to Kibana and Periscope logs through a unified API with KQL and SQL querying, AI-powered log analysis, and support for searching across 1.3+ billion logs in 9 indexes.
    1
  • F
    license
    A
    quality
    D
    maintenance
    Enables AI agents to access New Relic logs and APM data through the NerdGraph API. It allows users to execute NRQL queries, retrieve application performance metrics, and analyze transaction traces using natural language.
    6
    1

Latest Blog Posts

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/rlaput/azure-logs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server