Skip to content

fix: structure MCP tool error envelopes - #1122

Open
mckornfield wants to merge 2 commits into
mainfrom
6556550-mcp-error-envelope/mck
Open

fix: structure MCP tool error envelopes#1122
mckornfield wants to merge 2 commits into
mainfrom
6556550-mcp-error-envelope/mck

Conversation

@mckornfield

@mckornfield mckornfield commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Change shared MCP format_error_response to return a nested error object with stable code, message, and hint fields.
  • Remove the old top-level error_type shape from the shared helper.
  • Update MCP smoke tests to assert the structured error envelope deterministically.
  • Document the MCP error response shape.

NVBug

  • 6556550

Validation

  • uv run --frozen pytest packages/nmp_common/tests/mcp/test_error_handling.py services/core/mcp/tests/integration/smoke_test.py::TestMCPServerSmoke::test_list_workspaces_error_handling services/core/entities/tests/integration/smoke_test_mcp.py::TestEntitiesMCPServerSmoke::test_list_workspaces_error_handling -q: 4 passed
  • uv run --frozen ruff check ... on touched MCP files
  • uv run --frozen ty check ... on touched MCP files

Summary by CodeRabbit

  • New Features

    • Error responses now provide structured details, including an error code, message, remediation hint, and retryability status.
    • Connection and timeout errors are identified as retryable.
    • Empty error messages now fall back to a meaningful error description.
  • Documentation

    • Updated MCP error-handling documentation to describe the structured response format and retry guidance.
  • Bug Fixes

    • Removed the legacy error_type field from error responses.

Review follow-up

  • Pushed 4c66b6b05 (fix: include retryable MCP error metadata).
  • Validation: MCP formatter and smoke tests 6 passed; targeted Ruff and ty checks passed.
  • Note: uv run pre-commit run -a is blocked by the same helm-docs hook fetch HTTP 503 noted on the related PR.

@mckornfield
mckornfield requested review from a team as code owners August 5, 2026 23:07
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

MCP error responses now contain nested code, message, hint, and retryable fields. The formatter uses exception class names as codes and preserves retryability for connection and timeout errors. Unit and integration tests validate the new format.

Changes

MCP error response format

Layer / File(s) Summary
Structured error formatter and contract
packages/nmp_common/src/nmp/common/mcp/error_handling.py, packages/nmp_common/src/nmp/common/mcp/README.md
The formatter returns nested error metadata with fallback-safe messages, default hints, and retryability flags. The documentation describes the new structure and retry guidance.
Formatter unit coverage
packages/nmp_common/tests/mcp/test_error_handling.py
Tests validate error codes, messages, hints, retryable classifications, empty-message fallback, and removal of error_type.
MCP integration coverage
services/core/entities/tests/integration/smoke_test_mcp.py, services/core/mcp/tests/integration/smoke_test.py
Smoke tests use typed text extraction and controlled failing MCP services to validate structured error responses.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: structuring MCP tool error envelopes.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 6556550-mcp-error-envelope/mck

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/nmp_common/src/nmp/common/mcp/error_handling.py`:
- Around line 36-42: Update format_error_response in
packages/nmp_common/src/nmp/common/mcp/error_handling.py#L36-L42 to include
error.retryable, true only for ConnectionError or TimeoutError. Update the
canonical response example in
packages/nmp_common/src/nmp/common/mcp/README.md#L44-L48, align the
empty-message example with the fallback at
packages/nmp_common/src/nmp/common/mcp/README.md#L196-L203, and extend
packages/nmp_common/tests/mcp/test_error_handling.py#L11-L30 to assert both
retryable and non-retryable errors.

In `@services/core/mcp/tests/integration/smoke_test.py`:
- Around line 134-141: Update both controlled-error assertions in
services/core/mcp/tests/integration/smoke_test.py lines 134-141 and
services/core/entities/tests/integration/smoke_test_mcp.py lines 132-138 to
compare result["error"] against the exact expected structured error object for
RuntimeError("platform unavailable"), while retaining the success and error_type
assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9b164d0a-c211-473a-9608-a104c549ac92

📥 Commits

Reviewing files that changed from the base of the PR and between 96cb643 and b8bf649.

📒 Files selected for processing (5)
  • packages/nmp_common/src/nmp/common/mcp/README.md
  • packages/nmp_common/src/nmp/common/mcp/error_handling.py
  • packages/nmp_common/tests/mcp/test_error_handling.py
  • services/core/entities/tests/integration/smoke_test_mcp.py
  • services/core/mcp/tests/integration/smoke_test.py

Comment thread packages/nmp_common/src/nmp/common/mcp/error_handling.py
Comment thread services/core/mcp/tests/integration/smoke_test.py Outdated
NVBug: 6556550
Signed-off-by: Matt Kornfield <mkornfield@nvidia.com>
@mckornfield
mckornfield force-pushed the 6556550-mcp-error-envelope/mck branch from b8bf649 to 2e29794 Compare August 5, 2026 23:10
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@mckornfield mckornfield changed the title Structure MCP tool error envelopes fix: structure MCP tool error envelopes Aug 5, 2026
@github-actions github-actions Bot added the fix label Aug 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
services/core/mcp/tests/integration/smoke_test.py (1)

134-141: ⚠️ Potential issue | 🟡 Minor

Assert the controlled error envelope exactly.

Both tests raise RuntimeError("platform unavailable") and only check that the structured fields are non-empty. Compare result["error"] with the exact expected object, including the documented default hint.

  • services/core/mcp/tests/integration/smoke_test.py#L134-L141: assert the exact RuntimeError error object.
  • services/core/entities/tests/integration/smoke_test_mcp.py#L132-L138: assert the same exact error object.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@services/core/mcp/tests/integration/smoke_test.py` around lines 134 - 141,
Replace the non-empty field checks in the error-response assertions with an
exact comparison against the documented structured error object for
RuntimeError("platform unavailable"), including its stable code, message, and
default hint. Apply the same assertion update in
services/core/mcp/tests/integration/smoke_test.py lines 134-141 and
services/core/entities/tests/integration/smoke_test_mcp.py lines 132-138.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@services/core/mcp/tests/integration/smoke_test.py`:
- Around line 134-141: Replace the non-empty field checks in the error-response
assertions with an exact comparison against the documented structured error
object for RuntimeError("platform unavailable"), including its stable code,
message, and default hint. Apply the same assertion update in
services/core/mcp/tests/integration/smoke_test.py lines 134-141 and
services/core/entities/tests/integration/smoke_test_mcp.py lines 132-138.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2594d50e-ed03-4f52-8d6a-3964c34b2a3b

📥 Commits

Reviewing files that changed from the base of the PR and between 96cb643 and 2e29794.

📒 Files selected for processing (5)
  • packages/nmp_common/src/nmp/common/mcp/README.md
  • packages/nmp_common/src/nmp/common/mcp/error_handling.py
  • packages/nmp_common/tests/mcp/test_error_handling.py
  • services/core/entities/tests/integration/smoke_test_mcp.py
  • services/core/mcp/tests/integration/smoke_test.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/nmp_common/tests/mcp/test_error_handling.py
  • packages/nmp_common/src/nmp/common/mcp/error_handling.py
  • packages/nmp_common/src/nmp/common/mcp/README.md

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 31270/39880 78.4% 62.8%
Integration Tests 18214/37832 48.1% 20.6%

Comment thread packages/nmp_common/src/nmp/common/mcp/README.md Outdated
Signed-off-by: Matt Kornfield <mkornfield@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant