Skip to main content
Glama
IMPLEMENTATION_GUIDE.mdโ€ข7.79 kB
# Azure Logs MCP Server - Implementation Guide ## Table of Contents - [Server Implementations](#-server-implementations) - [Stdio Server (`src/index.ts`)](#1--stdio-server-srcindexts) - [HTTP Server (`src/sse-server.ts`)](#2--http-server-srcsse-serverts--recommended-for-web) - [Key Features Implemented](#-key-features-implemented) - [Enhanced Rate Limiting](#1--enhanced-rate-limiting) - [Modern MCP API](#2--modern-mcp-api) - [Security Enhancements](#3--security-enhancements) - [Protocol Compliance](#4--protocol-compliance) - [Comparison Matrix](#-comparison-matrix) - [Security Features](#-security-features) - [Containerization](#-containerization) - [Performance Optimizations](#-performance-optimizations) - [Future Enhancements](#-future-enhancements) - [Development Workflow](#-development-workflow) - [Recommendations](#-recommendations) - [Quick Start](#-quick-start) - [CLI Integration](#cli-integration) - [Web Integration](#web-integration) - [Container Deployment](#container-deployment) ## ๐Ÿš€ **Server Implementations** This project provides **two MCP server implementations** for different deployment scenarios: ### 1. **Stdio Server** (`src/index.ts`) - โœ… **McpServer API** - clean, maintainable implementation - โœ… Stdio transport for CLI integration - โœ… Simplified tool registration with Zod schemas - โœ… Enhanced rate limiting and error handling - ๐ŸŽฏ **Use case**: CLI integrations, development tools, desktop applications **Run with:** ```bash npm run dev # Development npm run start # Production ``` ### 2. **HTTP Server** (`src/sse-server.ts`) โญ **RECOMMENDED FOR WEB** - โœ… **McpServer API** with HTTP transport - โœ… **Streamable HTTP transport** (latest MCP protocol) - โœ… Session management with automatic cleanup - โœ… Enhanced security and CORS configuration - โœ… Production-ready with proper error handling - ๐ŸŽฏ **Use case**: Production HTTP deployments, web integrations, containerized apps **Run with:** ```bash npm run dev:sse # Development npm run start:sse # Production ``` ## ๐Ÿ”ง **Key Features Implemented** ### 1. **Enhanced Rate Limiting** - โœ… **Per-client identification** using headers or IP address - โœ… **Configurable limits** (10 requests/minute by default) - โœ… **Automatic cleanup** of expired entries ```typescript // Extracts client ID from request headers or IP const clientId = RateLimiter.extractClientId(req); if (!rateLimiter.checkLimit(clientId)) { // Rate limit exceeded } ``` ### 2. **Modern MCP API** - โœ… **Simplified tool registration** with `registerTool()` - โœ… **Built-in Zod validation** for input schemas - โœ… **Better error handling** and type safety - โœ… **Cleaner code structure** and maintainability ```typescript server.registerTool( 'searchLogs', { title: 'Search Logs', description: 'Searches request logs from Azure Log Analytics Workspace', inputSchema: { searchTerm: z .string() .min(1) .max(100) .regex(/^[A-Za-z0-9\-_.]+$/), limit: z.number().int().min(1).max(1000).default(50), duration: z .string() .regex(/^P(\d+D|T\d+H|\d+DT\d+H)$/) .default('P7D'), }, }, async ({ searchTerm, limit = 50, duration = 'P7D' }) => { // Tool implementation with configurable limit and duration }, ); ``` ### 3. **Security Enhancements** - โœ… **Input sanitization** prevents injection attacks - โœ… **Error message sanitization** prevents information leakage - โœ… **Environment validation** ensures required credentials - โœ… **TypeScript strict mode** for compile-time safety ### 4. **Protocol Compliance** - โœ… **Proper MCP response format** (single content block) - โœ… **Correct capabilities declaration** (`tools: { listChanged: true }`) - โœ… **Standard error handling** with appropriate error codes ## ๐Ÿ“Š **Comparison Matrix** | Feature | Stdio Server | HTTP Server | | ---------------------- | ------------ | --------------- | | **Transport** | Stdio | Streamable HTTP | | **Browser Support** | โŒ | โœ… | | **Session Management** | N/A | โœ… Automatic | | **CORS Support** | N/A | โœ… | | **Rate Limiting** | โœ… | โœ… | | **Type Safety** | โœ… Excellent | โœ… Excellent | | **Maintainability** | โœ… High | โœ… High | | **Performance** | โœ… Excellent | โœ… Excellent | | **Use Case** | CLI/Desktop | Web/Container | ## ๐Ÿ›ก๏ธ **Security Features** ### Input Validation ```typescript // Zod schema validation with new parameters searchTerm: z.string() .min(1, "Search term cannot be empty") .max(100, "Search term too long") .regex(/^[A-Za-z0-9\-_.]+$/, "Invalid format"), limit: z.number() .int("Limit must be an integer") .min(1, "Limit must be at least 1") .max(1000, "Limit cannot exceed 1000") .default(50), duration: z.string() .regex(/^P(\d+D|T\d+H|\d+DT\d+H)$/, "Duration must be in ISO 8601 format") .default("P7D") ``` ### Rate Limiting ```typescript // Per-client rate limiting const clientId = RateLimiter.extractClientId(req); // 10 requests per minute per client ``` ### Error Sanitization ```typescript // Prevents sensitive information leakage function sanitizeError(error: unknown): string { // Returns safe error messages only } ``` ## ๐Ÿณ **Containerization** The project includes Docker support using the HTTP server for web deployments: ```bash # Build and run with Docker npm run docker:build npm run docker:run # Or use Docker Compose npm run docker:compose ``` The container exposes port 3000 and uses the HTTP server implementation for maximum compatibility with web-based MCP clients. ## ๐Ÿ“ˆ **Performance Optimizations** 1. **Connection Pooling**: Reuse Azure client connections 2. **Rate Limiting**: Prevent abuse and ensure fair usage 3. **Session Management**: Efficient HTTP session handling 4. **Memory Management**: Automatic cleanup of expired sessions 5. **Error Caching**: Prevent repeated failed requests ## ๐Ÿ”ฎ **Future Enhancements** - [ ] **Metrics Collection**: Prometheus/OpenTelemetry integration - [ ] **Caching Layer**: Redis for query result caching - [ ] **Authentication**: OAuth2/JWT token validation - [ ] **Multi-tenant Support**: Workspace isolation - [ ] **Query Optimization**: Smart query building - [ ] **Real-time Streaming**: WebSocket support for live logs ## ๐Ÿ“ **Development Workflow** 1. **Choose Implementation**: - Use **Stdio** for CLI tools and desktop applications - Use **HTTP** for web applications and containerized deployments 2. **Environment Setup**: Copy `.env.example` to `.env` 3. **Development**: Use `npm run dev` or `npm run dev:sse` 4. **Testing**: Validate with MCP clients 5. **Production**: Use `npm run start` or `npm run start:sse` ## ๐ŸŽฏ **Recommendations** - **For CLI tools**: Use `src/index.ts` (Stdio Server) - **For web apps**: Use `src/sse-server.ts` (HTTP Server) - **For containers**: Use HTTP Server (already configured in Dockerfile) - **For new projects**: Both implementations use the modern McpServer API Both implementations provide excellent developer experience, enhanced security, and improved maintainability while maintaining full MCP protocol compliance. ## ๐Ÿš€ **Quick Start** ### CLI Integration ```bash npm run dev # Server starts on stdio transport ``` ### Web Integration ```bash npm run dev:sse # Server starts on http://localhost:3000 ``` ### Container Deployment ```bash docker-compose up --build # Server available at http://localhost:3000 ``` The implementations are production-ready and include comprehensive error handling, logging, health checks, and security features.

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