Content
# nestjs-dev-logs-mcp
An MCP server that exposes NestJS development server logs to AI coding agents (Claude Code, Cursor, Codex). Reads log files produced by a NestJS dev server and provides structured, filterable access through 7 MCP tools.
## Setup
### 1. Pipe NestJS logs to a file
```bash
# Option A: pipe via tee (keeps terminal output)
nest start --watch 2>&1 | tee /tmp/nest-dev.log
# Option B: redirect to file
nest start --watch > /tmp/nest-dev.log 2>&1
```
### 2. Build the server
```bash
npm install
npm run build
```
### 3. Configure your MCP client
**Claude Code** (`~/.claude/claude_desktop_config.json` or project `.mcp.json`):
```json
{
"mcpServers": {
"nestjs-logs": {
"command": "node",
"args": ["dist/index.js"],
"cwd": "/path/to/nestjs-dev-logs-mcp",
"env": {
"NEST_LOG_PATH": "/tmp/nest-dev.log"
}
}
}
}
```
**Cursor** (`.cursor/mcp.json`):
```json
{
"mcpServers": {
"nestjs-logs": {
"command": "node",
"args": ["/path/to/nestjs-dev-logs-mcp/dist/index.js"],
"env": {
"NEST_LOG_PATH": "/tmp/nest-dev.log"
}
}
}
}
```
## Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| `NEST_LOG_PATH` | `/tmp/nest-dev.log` | Path to the NestJS log file |
| `NEST_LOG_FORMAT` | `auto` | `auto`, `text`, or `json` |
| `NEST_LOG_MAX_LINES` | `10000` | Max lines to scan per query |
| `NEST_LOG_TAIL_BYTES` | `1048576` | Bytes to read from file end (1MB) |
## Tools
### `get_recent_errors`
Get recent errors and exceptions from logs.
- `since_minutes` — only errors from the last N minutes
- `module` — filter by NestJS module name
- `limit` — max errors to return (default 20, max 100)
### `get_request_logs`
Get HTTP request logs.
- `status_code` — filter by exact status code
- `status_range` — filter by range: `2xx`, `3xx`, `4xx`, `5xx`
- `path_pattern` — regex to match request paths
- `method` — filter by HTTP method
- `min_duration_ms` — only requests slower than N ms
- `since_minutes`, `limit`
### `get_db_queries`
Get database query logs (TypeORM, Prisma, Mongoose).
- `min_duration_ms` — only slow queries
- `failed_only` — only failed queries
- `table_pattern` — regex to match table names
- `since_minutes`, `limit`
### `get_di_errors`
Get NestJS dependency injection resolution errors.
- `since_minutes`, `limit`
### `tail_logs`
Get the last N lines from the log file (escape hatch for raw access).
- `lines` — number of lines (default 50, max 500)
- `grep` — regex to filter lines
### `get_log_summary`
Health check — counts by severity, top error patterns, status code distribution.
- `since_minutes`
### `truncate_logs`
Clear the log file. Uses file truncation (not deletion) so NestJS keeps writing.
- `confirm` — must be `true`
## Supported Log Formats
**NestJS text** (default logger):
```
[Nest] 12345 - 04/16/2026, 10:30:00 AM LOG [HTTP] GET /api/users 200 12ms
```
**nestjs-pino JSON** (recommended for full request data):
```json
{"level":30,"time":1713254465000,"msg":"GET /api/users 200","req":{"method":"GET","url":"/api/users"},"res":{"statusCode":200},"responseTime":12}
```
Format is auto-detected by sampling lines. Use `NEST_LOG_FORMAT` to override.
## Development
```bash
npm run dev # run with tsx (hot reload)
npm test # vitest
npm run test:watch # vitest --watch
npm run build # tsc → dist/
```
## Multiple Log Files
For multiple NestJS services, configure a separate MCP server entry per log file:
```json
{
"mcpServers": {
"api-logs": {
"command": "node",
"args": ["dist/index.js"],
"env": { "NEST_LOG_PATH": "/tmp/api-dev.log" }
},
"worker-logs": {
"command": "node",
"args": ["dist/index.js"],
"env": { "NEST_LOG_PATH": "/tmp/worker-dev.log" }
}
}
}
```