Skip to content

Filter expected MCP errors from Sentry#70

Merged
ChiragAgg5k merged 3 commits into
mainfrom
codex/filter-expected-sentry-errors
Jul 8, 2026
Merged

Filter expected MCP errors from Sentry#70
ChiragAgg5k merged 3 commits into
mainfrom
codex/filter-expected-sentry-errors

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

  • filter expected wrapped MCP input errors and Appwrite 4xx chains out of Sentry capture
  • apply the same filtering in Sentry before_send for integration-captured handled exceptions
  • truncate very large Appwrite error bodies before returning MCP error text

Tests

  • uv run --group dev ruff check src tests
  • uv run --group dev black --check src tests
  • uv run --group dev pyright
  • uv run python -m unittest discover -s tests/unit -v

@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR improves Sentry noise reduction for the Appwrite MCP server by filtering expected MCP input errors and Appwrite 4xx exception chains from being captured, applying the same filtering inside _before_send so Sentry's own integrations (e.g. StarletteIntegration) also respect the policy.

  • _before_send now calls _should_capture so integration-captured events are filtered consistently with manually captured ones; it also calls the new _normalize_transaction to replace raw HTTP transaction URLs with semantic mcp.* names derived from event tags.
  • _mcp_request_context extracts MCP client name, version, and protocol version from the active request context and merges them into the tags and context passed to every capture_exception call-site.
  • _format_appwrite_error collapses newlines and truncates the stringified exception to 500 characters to prevent large HTML error bodies from being surfaced in MCP tool results.

Confidence Score: 5/5

Safe to merge. The filtering logic is well-bounded, all new helpers are defensive, and the added tests cover the key new paths.

All changes are additive and exception-safe. The _before_send filter correctly reuses the existing _should_capture predicate, de-duplication via _already_captured works correctly because manual capture_exception marks the exception before re-raising, and _normalize_transaction only mutates events when tags unambiguously identify the MCP method. No silent data loss or behavioral regressions were found.

No files require special attention.

Important Files Changed

Filename Overview
src/mcp_server_appwrite/error_monitoring.py Adds _find_exception generic helper, filters expected exceptions in _before_send, and introduces _normalize_transaction/_event_tags for cleaner Sentry transaction names. Logic is correct and defensively handles both dict and list tag formats.
src/mcp_server_appwrite/server.py Adds _mcp_request_context to extract MCP client metadata for richer Sentry tags/context, spreads it into all four error handler call-sites, and truncates large Appwrite error bodies in _format_appwrite_error. All changes are defensive and correct.
tests/unit/test_error_monitoring.py Good coverage for the new filtering paths: wrapped 4xx chains, _before_send drop, transaction normalization from both dict and list tag formats, and the early-return guard for already-semantic transactions.
tests/unit/test_server.py New tests cover truncation of large HTML bodies and McpRequestContext extraction with both populated and None client_params. Coverage is appropriate.

Reviews (2): Last reviewed commit: "Narrow ValueError Sentry suppression" | Re-trigger Greptile

Comment thread src/mcp_server_appwrite/error_monitoring.py Outdated
@ChiragAgg5k ChiragAgg5k force-pushed the codex/filter-expected-sentry-errors branch from 233d1d5 to cb2ebea Compare July 8, 2026 12:47
@ChiragAgg5k ChiragAgg5k merged commit 2b25c27 into main Jul 8, 2026
5 checks passed
@ChiragAgg5k ChiragAgg5k deleted the codex/filter-expected-sentry-errors branch July 8, 2026 12:52
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.

1 participant