Skip to content

Conversation

dak2
Copy link

@dak2 dak2 commented Sep 2, 2025

Motivation / Background

This PR is a proposal.

Currently, the modelcontextprotocol/ruby-sdk delegates the handling of JSON-RPC error objects to the json-rpc-handler, which prevents flexible configuration of error objects returned by the SDK.

For example, The logging utility should return the JSON-RPC error object -32602, Invalid params, when the log level is invalid.
https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#error-handling

Currently, however, the modelcontextprotocol/ruby-sdk side cannot freely configure the Invalid params error object. Therefore, we implemented a solution in which you can return the intended JSON-RPC error object by including code in the error class and raising it.

The modelcontextprotocol/ruby-sdk could define and return JSON-RPC error objects directly. However, I believe that delegating this responsibility to the json-rpc-handler keeps things simpler.

For this use case, setting ErrorCode::InvalidParams flexibly would have been sufficient.
However, I implemented it this way because I thought that allowing the flexible invocation of other error classes would make it more universally reusable.

Currently, the `modelcontextprotocol/ruby-sdk` delegates the handling of JSON-RPC error objects to the `json-rpc-handler`, which prevents flexible configuration of error objects returned by the SDK.

For example, The logging utility should return the `JSON-RPC` error object `-32602`, `Invalid params`, when the log level is invalid.
https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#error-handling

Currently, however, the `modelcontextprotocol/ruby-sdk` side cannot freely configure the `Invalid params` error object.
Therefore, we implemented a solution in which you can return the intended `JSON-RPC` error object by including code in the error class and raising it.

The modelcontextprotocol/ruby-sdk could define and return `JSON-RPC` error objects directly. However, I believe that delegating this responsibility to the `json-rpc-handler` keeps things simpler.

For this use case, setting `ErrorCode::InvalidParams` flexibly would have been sufficient.
However, I implemented it this way because I thought that allowing the flexible invocation of other error classes would make it more universally reusable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant