Skip to content

[Feature Request] Include McpError 'data' payload in JSON-RPC error response #774

@victorRadu

Description

@victorRadu

Problem:
When a tool throws an McpError with a data payload for structured error context, the server's error handler correctly catches the error but only includes the code and message in the final JSON-RPC response. The data field is ignored and not sent to the client.

This limits the ability to provide rich, machine-readable error context from tools as intended by the JSON-RPC specification.

To Reproduce:
Create a tool that throws an McpError with a data payload:

  throw new McpError(
    ErrorCode.InvalidParams,
    'Invalid parameters provided.',
    {
      'field': 'experienceId',
      'issue': 'The experience ID is not valid.',
    }
  );
});

Expected Outcome:

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32602,
    "message": "Invalid parameters provided.",
    "data": {
      "field": "experienceId",
      "issue": "The experience ID is not valid."
    }
  },
  "id": "1"
}

Actual Outcome:

{
  "type": "text",
  "text": "MCP error -32602: Invalid parameters provided."
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions