Skip to content

fix(mcp): surface HTTP status and API error details in MCP tool error responses#153

Open
JayDS22 wants to merge 2 commits intoaccordproject:mainfrom
JayDS22:fix/mcp-descriptive-error-messages
Open

fix(mcp): surface HTTP status and API error details in MCP tool error responses#153
JayDS22 wants to merge 2 commits intoaccordproject:mainfrom
JayDS22:fix/mcp-descriptive-error-messages

Conversation

@JayDS22
Copy link
Copy Markdown

@JayDS22 JayDS22 commented Mar 28, 2026

Closes #152

Problem

All MCP tools and resource handlers in handlers/mcp.ts discard the HTTP status code and error body when makeApiRequest() returns a non-ok response. Every failure produces a generic throw new Error('Failed to load ...') regardless of whether the REST API returned 400, 404, or 500. MCP clients receive identical error messages for completely different failure modes.

Changes

Added buildApiErrorMessage() helper that extracts the HTTP status code and response body from failed API responses, producing errors like:
Failed to load template 'abc-123' (HTTP 404): {"error": "Template not found"}

instead of:
Failed to load template

Updated all 8 error paths in mcp.ts:

  • getAgreement() - now includes agreement ID and HTTP status
  • getTemplates() - now includes HTTP status and API error body
  • getAgreements() - now includes HTTP status and API error body
  • draftAgreement() - now includes agreement ID, format, and HTTP status
  • triggerAgreement() - now includes agreement ID and HTTP status
  • Template resource handler (single fetch) - now includes template ID and HTTP status
  • getTemplate tool - now includes template ID and HTTP status
  • getAgreement tool - now includes agreement ID and HTTP status

Also improved error logging in the two resource list handlers (agreements and templates) which already returned empty arrays on failure but were logging without status context.

Why This Matters

MCP clients like Claude Desktop and ChatGPT need to distinguish between "this template doesn't exist" (404) and "the server is down" (500) to provide useful feedback to users. This change makes every MCP error actionable.

@JayDS22 JayDS22 force-pushed the fix/mcp-descriptive-error-messages branch from c4dc499 to 8093333 Compare March 28, 2026 16:02
Jay added 2 commits March 28, 2026 12:02
… responses

Previously, all MCP tool and resource handlers threw generic error messages
like 'Failed to load template' regardless of whether the REST API returned
a 400, 404, or 500. MCP clients had no way to distinguish between different
failure modes.

Added buildApiErrorMessage() helper that captures the HTTP status code and
response body from failed API calls. Updated all 8 error paths in mcp.ts
to include this context in thrown errors.

Signed-off-by: Jay <DELL@MacBook-Air-34.local>
Signed-off-by: Jay Guwalani <guwalanijj@gmail.com>
…ilure modes

Covers 404, 400, 500, and body-read-failure scenarios. Verifies that
different HTTP status codes produce distinct error messages so MCP
clients can tell apart a missing resource from a validation error
from a server crash.

Signed-off-by: Jay <DELL@MacBook-Air-34.local>
Signed-off-by: Jay Guwalani <guwalanijj@gmail.com>
@JayDS22 JayDS22 force-pushed the fix/mcp-descriptive-error-messages branch from 8093333 to d3def87 Compare March 28, 2026 16:03
@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Apr 13, 2026
@JayDS22
Copy link
Copy Markdown
Author

JayDS22 commented Apr 13, 2026

@github-actions unstale

@github-actions github-actions bot removed the Stale label Apr 15, 2026
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.

MCP tool errors are generic and discard HTTP status context from the REST API

1 participant