reqlog

reqlog

Provides AI coding agents with tools to query, search, and analyze persisted HTTP request logs, enabling efficient debugging without terminal noise.

Category
访问服务器

README

reqlog

HTTP logging middleware for Python with Rich formatting, SQLite persistence, and an MCP server for AI coding agents.

PyPI version Python 3.10+ Tests License: MIT

panel format

Drop-in middleware for FastAPI, Django, and any ASGI framework.


Quick Start

pip install reqlog
from fastapi import FastAPI
from reqlog import ReqlogMiddleware

app = FastAPI()
app.add_middleware(ReqlogMiddleware)
  ● GET     /api/users                                     200     8ms   14:23:46
  ● POST    /api/users                                     201   145ms   14:23:47
  ● GET     /api/users/999                                 404    15ms   14:23:48
  ✗ GET     /api/crash                                     500    89ms   14:23:49

Three lines of code. Bodies, headers, and richer formats are one kwarg away:

app.add_middleware(ReqlogMiddleware, capture_body=True, format="panel")

Inside Claude Code, Cursor, or Aider, reqlog auto-selects a token-efficient format — no configuration needed.

For Django, see Django Support.


Give Your AI Agent a Network Tab

Terminal output is a firehose. MCP is a faucet.

When an AI agent debugs your backend through terminal output, it sees everything — uvicorn startup messages, health checks, OPTIONS preflights, successful requests — all burning context tokens. It can't go back and ask "what was the request body for that 422?"

reqlog flips this. Persist requests to SQLite, point the MCP server at it, and your agent pulls exactly what it needs:

Without reqlog MCP:

  1. Something breaks
  2. Agent reads terminal — 200 lines of mixed output
  3. "Can you reproduce the error?"
  4. You curl the endpoint, paste the output
  5. Agent guesses at the request body

With reqlog MCP:

  1. Something breaks
  2. Agent calls get_error_summary() — sees "422 on POST /api/users, missing field 'email'"
  3. Agent calls get_request_detail(id) — sees the exact request body and validation error
  4. Agent writes the fix

No manual debugging. No pasting terminal output into chat.

Setup

Step 1: Persist requests to SQLite.

from reqlog import ReqlogMiddleware, ConsoleBackend, SQLiteBackend

app.add_middleware(
    ReqlogMiddleware,
    capture_body=True,
    backends=[ConsoleBackend(), SQLiteBackend("reqlog.db")],
)

Step 2: Add to your editor's MCP config.

<details> <summary><b>Claude Code</b> — <code>.mcp.json</code> in project root or <code>~/.claude/mcp.json</code></summary>

{
  "mcpServers": {
    "reqlog": {
      "command": "uvx",
      "args": ["--from", "reqlog[mcp]", "reqlog", "mcp", "--db", "reqlog.db"]
    }
  }
}

</details>

<details> <summary><b>Cursor</b> — <code>.cursor/mcp.json</code></summary>

{
  "mcpServers": {
    "reqlog": {
      "command": "uvx",
      "args": ["--from", "reqlog[mcp]", "reqlog", "mcp", "--db", "reqlog.db"]
    }
  }
}

</details>

<details> <summary><b>Local dev</b> — using <code>uv run</code> instead of <code>uvx</code></summary>

{
  "mcpServers": {
    "reqlog": {
      "command": "uv",
      "args": ["run", "--with", "mcp>=1.2.0", "reqlog", "mcp", "--db", "reqlog.db"]
    }
  }
}

</details>

The [mcp] extra is required for the MCP server. When using pip directly: pip install reqlog[mcp].

MCP Tools

Tool What the agent asks What it gets
get_recent_requests "What just happened?" Recent HTTP logs with filters for status, path, method, duration, time window
get_request_detail "Show me that 500." Full headers + bodies for a specific request ID
get_error_summary "What's broken?" Aggregated 4xx/5xx report grouped by status code
search_requests "Find requests containing 'user not found'" Full-text search across paths, bodies, and headers
get_endpoint_stats "Is /api/users slow?" Per-endpoint p50/p95/p99 latency and status breakdown

Two MCP resources provide ambient context: reqlog://status (session summary, error rate) and reqlog://recent-errors (last 5 errors in compact format).

The --redact-bodies flag strips all bodies from MCP responses, serving only metadata. Standard sanitization (header masking, body field redaction) always applies.


Output Formats

Five built-in formats. Set via format= or the REQLOG_FORMAT env var. reqlog auto-detects your environment — ai format inside Claude Code/Cursor/Aider, compact in TTY, json otherwise.

panel — two-column request/response

Side-by-side layout with aligned headers and syntax-highlighted JSON bodies.

panel format

ai — token-efficient for LLMs

Automatically selected inside Claude Code, Cursor, and Aider. Compact JSON, no Rich overhead.

ai format

compact — default for terminals

Morgan-style one-liner with color-coded status and method.

compact format

verbose — vertical panels

Stacked Rich panels with full headers and response details.

verbose format

json — JSON-Lines

One object per request. Default when stderr is not a TTY.

{"method":"GET","path":"/api/users","status_code":200,"duration_ms":8.2,"timestamp":"2026-02-14T14:23:46"}

CLI

A built-in command-line interface for querying SQLite-persisted logs.

reqlog tail --db reqlog.db                        # Live-tail with color
reqlog tail --status 500 --slow 100               # Only slow errors
reqlog tail --method POST --path /api/users       # Filter by method + path
reqlog stats --db reqlog.db --minutes 60          # Aggregated stats with p50/p95/p99
reqlog export --db reqlog.db --format json        # Export as JSON-Lines
reqlog export --format csv --since "1 hour ago"   # Time-filtered CSV export

<details> <summary>Example <code>reqlog stats</code> output</summary>

Request Stats (last 60 min)

  Total requests: 847
  Avg duration:   45.2ms
  P50:            12.3ms
  P95:            234.5ms
  P99:            890.1ms

  Status Codes        HTTP Methods       Top 10 Slowest Endpoints
  Class  Count        Method  Count      Method  Path               Avg (ms)
  2xx    723          GET     612        GET     /api/reports        520.1
  4xx    98           POST    187        POST    /api/auth/login     230.4
  5xx    26           PUT     32         POST    /api/users          145.2
                      DELETE  16

</details>


Backends

reqlog fans out to multiple backends in parallel. When no backends= list is provided, it defaults to a single ConsoleBackend with the auto-detected format.

from reqlog import ReqlogMiddleware, ConsoleBackend, SQLiteBackend
from reqlog.backends.file import FileBackend

app.add_middleware(
    ReqlogMiddleware,
    capture_body=True,
    backends=[
        ConsoleBackend(format="compact"),        # Terminal output
        SQLiteBackend(db_path="reqlog.db"),       # Queryable storage (CLI + MCP)
        FileBackend(path="requests.jsonl"),       # Rotating log files
    ],
)
Backend Use case Key options
ConsoleBackend Terminal output via Rich format, max_body_display
SQLiteBackend Persistent storage for CLI + MCP db_path, max_rows (auto-prune), wal_mode
FileBackend Rotating log files (JSON/text/AI) path, format, max_size_mb, max_files
MemoryBackend Testing and debugging max_size (ring buffer capacity)

SQLiteBackend uses a background writer thread — non-blocking, queue-bounded, with graceful shutdown via atexit. See Backends Guide for the full API and custom backend protocol.


Configuration

All options work as keyword arguments to ReqlogMiddleware, as fields on ReqlogConfig, or as REQLOG_* environment variables.

app.add_middleware(
    ReqlogMiddleware,
    capture_body=True,           # Log request/response bodies (default: False)
    capture_headers=True,        # Log headers (default: False)
    format="compact",            # "compact" | "verbose" | "panel" | "ai" | "json"
    exclude_paths=["/health"],   # Paths to skip
    sample_rate=1.0,             # 1.0 = all, 0.1 = 10%
)

<details> <summary><b>Full configuration reference</b></summary>

from reqlog import ReqlogMiddleware, ReqlogConfig

config = ReqlogConfig(
    capture_body=True,
    capture_headers=True,
    format="compact",
    max_body_size=64_000,                        # Truncate bodies larger than this (bytes)
    exclude_paths=["/health", "/healthz", "/ready", "/metrics", "/favicon.ico"],
    exclude_methods=["OPTIONS"],
    include_paths=None,                          # If set, only log these paths
    sample_rate=1.0,
    sanitize_headers=[                           # Glob patterns supported
        "Authorization", "Cookie", "Set-Cookie", "X-API-Key", "X-Auth-Token",
    ],
    sanitize_body_fields=[                       # Recursive JSON walk
        "password", "secret", "token", "access_token", "credit_card",
    ],
    generate_request_id=True,
    request_id_header="X-Request-ID",
)

app.add_middleware(ReqlogMiddleware, config=config)

Environment variable overrides — take precedence over programmatic defaults:

Variable Type Example
REQLOG_FORMAT str compact, panel, ai, json
REQLOG_CAPTURE_BODY bool true, 1, yes
REQLOG_CAPTURE_HEADERS bool true
REQLOG_SAMPLE_RATE float 0.1
REQLOG_MAX_BODY_SIZE int 128000
REQLOG_EXCLUDE_PATHS list /health,/metrics,/ready
REQLOG_EXCLUDE_METHODS list OPTIONS,HEAD
REQLOG_REQUEST_ID_HEADER str X-Trace-ID

</details>

Sanitization is on by default — Authorization, Cookie, and API key headers are redacted, along with password/token/secret body fields. Redaction uses glob matching on headers and recursive JSON walks on bodies.


Django Support

# settings.py

MIDDLEWARE = [
    "reqlog.middleware.django.ReqlogMiddleware",
    # ... other middleware
]

REQLOG = {
    "CAPTURE_BODY": True,
    "CAPTURE_HEADERS": True,
    "FORMAT": "compact",
    "EXCLUDE_PATHS": ["/health", "/admin/jsi18n/"],
}

The Django middleware auto-detects sync (WSGI) vs. async (ASGI) and handles both. In WSGI mode, logging runs in a background thread — zero latency impact on the request cycle.

<details> <summary>Django with persistent backends</summary>

from reqlog import ConsoleBackend, SQLiteBackend

REQLOG = {
    "CAPTURE_BODY": True,
    "FORMAT": "compact",
    "BACKENDS": [
        ConsoleBackend(format="compact"),
        SQLiteBackend(db_path="reqlog.db"),
    ],
}

</details>


Documentation

Detailed guides for each component:

  • Backends — Console, SQLite, File, Memory backends and custom backend protocol
  • CLItail, stats, export, mcp commands with examples
  • Configuration — All options, env vars, and Django settings
  • Formatters — Compact, verbose, panel, AI, and JSON formats
  • Middleware — FastAPI/ASGI and Django integration details

Development

git clone https://github.com/ankitksr/reqlog.git
cd reqlog && uv sync

uv run pytest tests/ -v          # 184 tests
uv run mypy src/                 # Type checking (strict)
uv run ruff check src/ tests/    # Linting
uv build                         # Build package
uv run uvicorn examples.demo:app --reload    # FastAPI demo
uv run python examples/preview_cli.py        # All formatters + CLI features
uv run python examples/demo_mcp.py           # MCP demo (sample DB + SSE server)

<details> <summary>Project structure</summary>

src/reqlog/
  core/         models.py · config.py · pipeline.py · buffer.py
  middleware/   asgi.py (pure ASGI) · django.py (sync + async)
  backends/     console.py · sqlite.py · file.py · memory.py · protocols.py
  formatters/   compact · verbose · panel · ai · json · text_format (shared)
  sanitize/     redact.py (header glob + recursive JSON walk)
  mcp/          server.py (5 tools + 2 resources) · formatting.py
  cli/          main.py (tail · stats · export · mcp · demo)

</details>

License

MIT. See LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选