Repository navigation
feat(mcp): add MCP error normalizer and code classifier (fixes #745) - #784
Merged
SHAURYASANYAL3 merged 1 commit intoOct 26, 2026
Conversation
Contributor
🧪 PR Test Results
Python 3.12 · commit ba6b71e |
SHAURYASANYAL3
approved these changes
Oct 26, 2026
SHAURYASANYAL3
left a comment
Collaborator
There was a problem hiding this comment.
👁️ MCP Error Classification Review: PR #784 (classify_mcp_error) — APPROVED ✅
Outstanding implementation by @Subodh-17 on this Level 1 feature!
Architectural Highlights:
- Pristine JSON-RPC 2.0 Taxonomy:
agentwatch/sensors/mcp_error.pyimplementsMCPErrorCode(IntEnum)covering-32700through-32000, cleanly mapped to high-levelMCPErrorCategorycategories (SCHEMA_VIOLATION,TOOL_NOT_FOUND,DOWNSTREAM_TIMEOUT,INTERNAL_SERVER_ERROR). - Defensive Normalization:
classify_mcp_error()safely parses nestedresponse["error"]or direct dictionaries, performs safe integer coercion on error codes, detects timeout heuristics without false positives, and preserves vendor code/data payloads. - Pure Standard Library & Plane A Compliance: Zero external dependencies, pure in-memory evaluation, strictly respecting Plane A boundaries (<80 lines of clean code).
- Exhaustive Testing: 18 unit tests in
tests/sensors/test_mcp_error.pyasserting standard codes, timeout heuristics, vendor extensions, malformed inputs, and envelope immutability. - 100% Green CI: All 12 GitHub Actions checks passing green.
Merging into main! 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Description
Implements a typed error classifier and normalized envelope for Model Context Protocol (MCP) JSON-RPC responses in Plane A (
agentwatch.sensors).Problem & Motivation
MCP protocol servers return standard JSON-RPC 2.0 error codes (
-32700 Parse error,-32601 Method not found,-32602 Invalid params,-32000 Server error). Previously, raw MCP errors lacked structured taxonomy, preventing contract evaluators from distinguishing between client parameter hallucinations, missing tools, downstream timeouts, or unhandled server crashes.Key Changes
agentwatch/sensors/mcp_error.py(<80 LOC, Pure Standard Library):MCPErrorCode(IntEnum): Standard JSON-RPC 2.0 error codes (PARSE_ERROR,INVALID_REQUEST,METHOD_NOT_FOUND,INVALID_PARAMS,INTERNAL_ERROR,SERVER_ERROR_MIN/MAX).MCPErrorCategory(str, Enum): High-level failure categories (SCHEMA_VIOLATION,TOOL_NOT_FOUND,DOWNSTREAM_TIMEOUT,INTERNAL_SERVER_ERROR).MCPErrorEnvelope: Immutable@dataclass(frozen=True)storingcode: int,category: MCPErrorCategory,message: str, anddata: Any = None.classify_mcp_error(response: dict) -> MCPErrorEnvelope: Classifies error payloads from either nestedresponse["error"]or direct dictionaries. Handles safe integer parsing, case-insensitive timeout detection in message or data payloads, schema violation mapping, and vendor code/data preservation.tests/sensors/test_mcp_error.py:Fixes #745
🏛️ Architectural Plane & Classification
Which architectural plane does this change target? (
docs/v3/V3_ARCHITECTURE.md)🧪 Verification & Evidence of Testing
Executed locally against Python 3.11:
pytest tests/v3/test_architecture_contracts.py,pytest tests/v3/test_normalizers_genai_mcp.py).🛡️ Security & Linter Quality Checklist
bandit-baseline.jsonwas NOT created or edited.ruff format --check agentwatch/sensors/mcp_error.py tests/sensors/test_mcp_error.py(Clean pass).ruff check agentwatch/sensors/mcp_error.py tests/sensors/test_mcp_error.py(Clean pass).tests/v3/test_architecture_contracts.pyPASSED).✍️ Contributor Integrity Declaration
By submitting this pull request, I certify that:
origin/main(9715d04fc1b0bb9dafbb7439c5a17b378678d14b).