@leanmcp/utils
Utility functions and helpers for LeanMCP SDK.Features
- π Retry logic - Exponential backoff for resilient operations
- π Response formatting - Format data as JSON, Markdown, HTML, or tables
- π Object utilities - Deep merge, validation, and manipulation
- β±οΈ Async helpers - Sleep, timeout, and promise utilities
Installation
API Reference
Response Formatting
formatResponse(data, format)
Format data based on specified format type.json- Pretty-printed JSONmarkdown- JSON wrapped in markdown code blockhtml- JSON wrapped in HTML pre tagtable- Markdown table (for arrays of objects)- Default - String conversion
formatAsTable(data)
Format array of objects as a Markdown table.Object Utilities
deepMerge(target, β¦sources)
Deep merge multiple objects.isObject(item)
Check if value is a plain object.Async Utilities
retry(fn, options)
Retry a function with exponential backoff.- Attempt 1: Immediate
- Attempt 2: Wait 1000ms
- Attempt 3: Wait 2000ms
- Attempt 4: Wait 4000ms
sleep(ms)
Async sleep function.timeout(promise, ms)
Add timeout to a promise.Usage Examples
Formatting API Responses
Resilient API Calls
Deep Configuration Merging
Type Definitions
All functions are fully typed with TypeScript:Related Packages
- @leanmcp/core - Core MCP server functionality
- @leanmcp/auth - Authentication decorators
- @leanmcp/cli - CLI tool for creating new projects