Enables integration with Express.js web applications, providing examples for implementing rate-limited endpoints, cached responses, and request handling with the MCP utilities.
Supports testing with Jest, including test structure, coverage reporting, and pattern-based test filtering for MCP server components.
Includes Kubernetes-compatible storage size formatting utilities for displaying resource metrics in standardized formats (e.g., Mi, Gi).
Available as an NPM package with installation instructions and dependency management for integrating MCP utilities into projects.
Built with TypeScript support, providing type-safe interfaces, error checking, and enhanced development experience for MCP server implementations.
Integrates with Zod schema validation for type-safe argument validation, resource operations, and structured data handling in MCP tools.
@haakco/mcp-utils
Comprehensive shared utilities library for MCP (Model Context Protocol) servers
Eliminates code duplication and provides standardized, production-ready utilities for building robust MCP servers.
Installation
Quick Start
🚀 Core Features
🏗️ MCP Architecture Components
BaseToolHandler - Standardized tool execution patterns
ResponseBuilder - Consistent MCP response formatting
InstanceManager - Multi-instance server support
ToolRegistry - Tool registration and management
🎨 Formatting & Presentation
Message Formatters - ✅ ❌ ⚠️ ℹ️ status indicators
Size Formatters - Bytes, storage units (KB, MB, GB, Ki, Mi, Gi)
Table Formatters - Structured data presentation
JSON/Text Utilities - Safe serialization and truncation
📅 DateTime Operations
Duration Formatting - Human-readable time spans
Age Calculation - "2 hours ago", "3 days old"
Relative Time - "in 5 minutes", "1 week ago"
Duration Parsing - "1h30m" → milliseconds
🧠 Advanced Caching
SimpleCache - TTL-based caching
LRUCache - Least Recently Used eviction
TTLCache - Combined TTL + LRU strategies
DebouncedCache - Batched operation caching
Memoization - Function result caching
🚦 Rate Limiting
Token Bucket - Burst capacity with refill
Sliding Window - Rolling time-based limits
Fixed Window - Period-based rate limiting
Leaky Bucket - Smooth rate control
Multi-Tier - Multiple simultaneous limits
Keyed Limiters - Per-user/per-resource limits
🔌 WebSocket Utilities
ReconnectingWebSocket - Auto-reconnection with backoff
Message Router - Type-based message handling
RPC Client - Request/response over WebSocket
Connection Pool - Managed connection lifecycle
📊 Logging & Monitoring
Structured Logging - Context-aware log entries
Performance Timing - Operation duration tracking
Environment-based - Debug/production configurations
Multiple Outputs - Console, silent, custom loggers
📚 API Reference
Core MCP Utilities
Response Creation
Argument Validation
Formatting Utilities
Message Formatting
Size & Number Formatting
Table & List Formatting
DateTime Utilities
Duration Formatting
Relative Time
Caching System
Simple TTL Cache
LRU Cache
Combined TTL + LRU Cache
Function Memoization
Rate Limiting
Token Bucket Rate Limiter
Sliding Window Rate Limiter
Multi-Tier Rate Limiting
Rate-Limited Functions
WebSocket Utilities
Reconnecting WebSocket
Message Router
WebSocket RPC
Logging System
Basic Logger
Structured Logger with Context
Performance Logger
Environment-based Logger
🏗️ Advanced Usage
Custom Tool Handler
Batch Response Builder
Resource Operation Mixin
📦 Integration Examples
Express.js Integration
WebSocket Server Integration
🧪 Testing
The library includes comprehensive test coverage (85/85 tests passing):
Test Structure
🚀 Development
📄 License
MIT License - see LICENSE file for details.
🤝 Contributing
Fork the repository
Create a feature branch
Make your changes with tests
Ensure all tests pass and linting is clean
Submit a pull request
Built with TypeScript, tested with Jest, and designed for production MCP servers.
This server cannot be installed
A comprehensive utilities library for building Model Context Protocol servers, providing standardized tools for response formatting, caching, rate limiting, logging, and WebSocket management.
Related MCP Servers
- -securityAlicense-qualityA toolkit for building Model Context Protocol servers and clients that provide standardized context for LLMs, allowing applications to expose resources, tools, and prompts through stdio or Streamable HTTP transports.Last updated -7,267,844MIT License
- AsecurityAlicenseAqualityA comprehensive Model Context Protocol server providing access to 70+ IT tools for developers and system administrators, including encoding/decoding, text manipulation, hashing, and network utilities.Last updated -7610112TypeScriptMIT License
- AsecurityFlicenseAqualityA Model Context Protocol server implementation that provides basic utility tools including echo, uppercase text conversion, and mathematical calculations.Last updated -3595
- -securityFlicense-qualityA clean, reusable TypeScript boilerplate for building Model Context Protocol servers with support for custom tools and resources.Last updated -