Skip to content

feat(mcp): structured error responses for agent coordination - #1687

Open
unicoderbot[bot] wants to merge 4 commits into
mainfrom
vgv-ai-bot/issue-1615
Open

feat(mcp): structured error responses for agent coordination#1687
unicoderbot[bot] wants to merge 4 commits into
mainfrom
vgv-ai-bot/issue-1615

Conversation

@unicoderbot

@unicoderbot unicoderbot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements structured error responses in the MCP server to provide agents with detailed failure context, partial results, and recovery suggestions. Error responses now follow a consistent JSON schema with:

  • status: failure or partial_failure (if partial results exist)
  • failureType: one of transient, validation, business, or permission
  • attemptedAction: the tool name, command, directory, and arguments that failed
  • reason: human-readable failure cause
  • partialResults: any output captured before failure
  • alternativeApproaches: context-aware recovery suggestions based on failure type

Changes

Core Implementation

  • Added buildStructuredErrorResult() function to generate consistent JSON error payloads
  • Added failureTypeForExitCode() to classify exit codes into semantic failure categories using sysexits.h conventions
  • Added alternativeApproachesFor() to suggest recovery strategies per failure type
  • Refactored _runToolCommand() to pass requestArguments through for error context
  • Updated all tool handlers (_handleCreate, _handleTest, _handlePackagesGet, _handlePackagesCheckLicenses) to include request arguments

Error Classification

  • validation: Bad input (exit codes: usage, data, noInput, config)
  • permission: Access denied (exit code: noPerm)
  • transient: Temporary failures likely to succeed on retry (exit codes: unavailable, tempFail, ioError, osError, osFile, cantCreate)
  • business: Rule violations or unexpected outcomes (default for unknown codes)

Testing

  • Updated 12+ test cases to validate structured error payloads instead of plain text
  • Added comprehensive test coverage for failureTypeForExitCode(), alternativeApproachesFor(), and buildStructuredErrorResult()
  • Verified partial results are preserved when output is captured before failure
  • Confirmed JSON payload structure matches agent requirements

Closes #1615

Closes #1615

Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com>
@unicoderbot
unicoderbot Bot requested a review from a team as a code owner August 11, 2026 10:35
Comment thread lib/src/mcp/structured_tool_error.dart Outdated
Comment thread test/src/mcp/structured_tool_error_test.dart Outdated
Comment thread test/src/mcp/structured_tool_error_test.dart Outdated
@marcossevilla

This comment was marked as outdated.

@unicoderbot

This comment was marked as outdated.

@marcossevilla

Copy link
Copy Markdown
Member

@vgvbot /address-review

@unicoderbot

unicoderbot Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

On it, I'll address the review comments and push the changes.

  • Preparing environment
    • Cloning repository
    • Setting up dev environment
  • Reviewing feedback
  • Working on changes
  • Pushing updates

I've pushed changes to address the feedback.

unicoderbot Bot and others added 2 commits August 11, 2026 16:46
Co-authored-by: marcossevilla <marcossevilla@users.noreply.github.com>
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.

feat(mcp): structured error responses

1 participant