@edicarlos.lds/businessmap-mcp
Version:
Model Context Protocol server for BusinessMap (Kanbanize) integration
170 lines (119 loc) âĸ 4.82 kB
Markdown
The BusinessMap MCP Server uses a structured logging system that ensures compatibility with the Model Context Protocol (MCP) while providing clear, categorized log output.
## Why STDERR?
The MCP protocol uses **STDOUT exclusively for JSON-RPC communication**. Any output to STDOUT that is not valid JSON-RPC will corrupt the protocol and cause errors like:
```
MCP businessmap: Unexpected token 'â
', "â
Configur"... is not valid JSON
```
Therefore, **all logging must go to STDERR** (`console.error` or `process.stderr.write`).
## Logger Utility
Instead of using raw `console.error` for all messages (which can be misleading), we provide a `logger` utility that categorizes messages while still outputting to STDERR.
### Log Levels
```typescript
export enum LogLevel {
DEBUG = 0, // Detailed debugging information
INFO = 1, // Informational messages (default)
WARN = 2, // Warning messages
ERROR = 3, // Error messages
NONE = 4, // Disable all logging
}
```
```typescript
import { logger } from './utils/logger.js';
// Success messages (shown at INFO level)
logger.success('Successfully connected to BusinessMap API');
// Informational messages (shown at INFO level)
logger.info('đ Starting BusinessMap MCP Server v1.0.0');
logger.info('đĄ BusinessMap API: https://account.kanbanize.com/api/v2');
// Debug messages (shown at DEBUG level only)
logger.debug('Fetching effective cycle time columns for board 123');
// Warning messages (shown at WARN level and above)
logger.warn('Direct board lookup failed, trying fallback method');
// Error messages (shown at ERROR level and above)
logger.error('Failed to connect to API', errorObject);
```
All log messages include timestamps and clear prefixes:
```
[] â
SUCCESS: Successfully connected to BusinessMap API
[] âšī¸ INFO: đ Starting BusinessMap MCP Server v1.0.0
[] đ DEBUG: Fetching effective cycle time columns for board 123
[] â ī¸ WARN: Direct board lookup failed, trying fallback method
[] â ERROR: Failed to connect to API
```
Set the `LOG_LEVEL` environment variable to control verbosity:
```bash
LOG_LEVEL=0 npx @edicarlos.lds/businessmap-mcp
LOG_LEVEL=1 npx @edicarlos.lds/businessmap-mcp
LOG_LEVEL=2 npx @edicarlos.lds/businessmap-mcp
LOG_LEVEL=3 npx @edicarlos.lds/businessmap-mcp
LOG_LEVEL=4 npx @edicarlos.lds/businessmap-mcp
```
```json
{
"mcpServers": {
"Businessmap": {
"command": "npx",
"args": ["-y", "@edicarlos.lds/businessmap-mcp"],
"env": {
"BUSINESSMAP_API_TOKEN": "your_token",
"BUSINESSMAP_API_URL": "https://account.kanbanize.com/api/v2",
"LOG_LEVEL": "1"
}
}
}
}
```
Instead of everything being "errors" (when using `console.error`), messages are properly categorized:
- **SUCCESS**: Operations completed successfully
- **INFO**: General informational messages
- **DEBUG**: Detailed debugging information
- **WARN**: Non-critical issues or fallback scenarios
- **ERROR**: Actual errors and failures
All output goes to STDERR, keeping STDOUT clean for JSON-RPC:
```typescript
// â BAD - Breaks MCP protocol
console.log('Starting server...');
// â
GOOD - Uses STDERR
console.error('Starting server...');
// â
BETTER - Categorized and uses STDERR
logger.info('Starting server...');
```
Control what gets logged without changing code:
```bash
LOG_LEVEL=2
LOG_LEVEL=0
```
All messages follow the same format with timestamps and clear prefixes, making logs easier to read and parse.
When migrating from `console.error` to the logger utility, choose the appropriate method:
```typescript
// Before
console.error('â
Successfully connected');
console.error('đ Retrying connection...');
console.error('â ī¸ Fallback method used');
console.error('â Connection failed');
// After
logger.success('Successfully connected');
logger.info('Retrying connection...');
logger.warn('Fallback method used');
logger.error('Connection failed');
```
The logger is implemented in `src/utils/logger.ts` and uses a singleton pattern. All methods internally call `console.error` to ensure output goes to STDERR, maintaining MCP protocol compatibility.