Skip to content

Fix #45: Add MCPConnectionErrorFilter for cleaner production logs - #72

Open
Mr-Neutr0n wants to merge 1 commit into
redhat-data-and-ai:mainfrom
Mr-Neutr0n:agent/issue-45-add-mcpconnectionerrorfi
Open

Fix #45: Add MCPConnectionErrorFilter for cleaner production logs#72
Mr-Neutr0n wants to merge 1 commit into
redhat-data-and-ai:mainfrom
Mr-Neutr0n:agent/issue-45-add-mcpconnectionerrorfi

Conversation

@Mr-Neutr0n

@Mr-Neutr0n Mr-Neutr0n commented Jul 6, 2026

Copy link
Copy Markdown

Fixes #45

Added MCPConnectionErrorFilter class (downgrades expected disconnect patterns to DEBUG) and ENABLE_MCP_CONNECTION_FILTER feature flag (default True), wired into the app lifespan, applied to mcp, uvicorn.error, and starlette loggers, with tests and docs.

Local test infra unavailable in CI sandbox.


This change was prepared with AI assistance under human direction and review.

Summary by CodeRabbit

  • New Features

    • Added an environment setting to control filtering of expected MCP connection errors.
    • Expected disconnect, reset, and broken-pipe errors are now reduced from ERROR to DEBUG logs by default, minimizing log noise.
    • Filtering can be disabled through configuration when full error logging is needed.
  • Documentation

    • Documented the new configuration option and its default behavior in the development guide.

…roduction logs

Signed-off-by: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com>
@Mr-Neutr0n
Mr-Neutr0n marked this pull request as ready for review July 28, 2026 03:35
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ef18f564-8b64-487b-8cb4-eed64f2655d2

📥 Commits

Reviewing files that changed from the base of the PR and between 7112f47 and 49c6d68.

📒 Files selected for processing (6)
  • .env.example
  • docs/development.md
  • template_mcp_server/src/api.py
  • template_mcp_server/src/settings.py
  • template_mcp_server/utils/pylogger.py
  • tests/test_utils.py

📝 Walkthrough

Walkthrough

Adds a default-enabled configuration flag and logging filter that downgrades expected MCP disconnect, reset, and broken-pipe errors to DEBUG. The filter is attached during application startup to MCP-related loggers and covered by unit tests.

Changes

MCP connection error filtering

Layer / File(s) Summary
Filtering configuration contract
.env.example, template_mcp_server/src/settings.py, docs/development.md
Adds ENABLE_MCP_CONNECTION_FILTER, defaulting to True, with documentation describing the filtered connection errors.
Filter behavior and validation
template_mcp_server/utils/pylogger.py, tests/test_utils.py
Adds case-insensitive matching for expected connection error patterns, downgrades matches to DEBUG, preserves unrelated errors, and tests the behavior.
Application startup wiring
template_mcp_server/src/api.py, template_mcp_server/utils/pylogger.py, tests/test_utils.py
Attaches the filter to mcp, uvicorn.error, and starlette during lifespan startup, with enabled and disabled attachment tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FastAPI lifespan
  participant Logging setup
  participant MCP loggers
  FastAPI lifespan->>Logging setup: pass ENABLE_MCP_CONNECTION_FILTER
  Logging setup->>MCP loggers: attach MCPConnectionErrorFilter when enabled
  MCP loggers->>MCP loggers: downgrade expected connection errors to DEBUG
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding MCPConnectionErrorFilter to reduce production log noise.
Linked Issues check ✅ Passed The PR appears to meet #45 by adding the feature flag, filter behavior, logger attachment, tests, and docs.
Out of Scope Changes check ✅ Passed The changes stay focused on MCP logging cleanup, configuration, docs, and tests with no obvious unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add MCPConnectionErrorFilter for cleaner production logs

1 participant