Skip to content

Conversation

sreenaths
Copy link
Contributor

@sreenaths sreenaths commented Aug 26, 2025

The JSON-RPC version is fixed at 2.0 for MCP messages. However, as the value is not set by default, we have to pass the correct value every time a model is instantiated.

Motivation and Context

This change simplifies model instantiation by automatically setting the JSON-RPC version. Additionally, if the version ever needs to change in the future, it only has to be updated in a single place.

For example

JSONRPCMessage(
    root=JSONRPCRequest(
        # jsonrpc="2.0", - This wouldn't be required
        id=1,
        method="ping"
    )
),

How Has This Been Tested?

Tests were improved and are working as expected.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

None

@sreenaths sreenaths requested review from a team and ihrpr August 26, 2025 22:53
@sreenaths sreenaths force-pushed the setting-default-jsonrpc-version branch from 0302041 to d626174 Compare August 26, 2025 22:58
@sreenaths
Copy link
Contributor Author

Hi @ochafik
When you have a chance, please review this PR.
It is similar to PR #1292 that you had helped with before.
Thank you.

@sreenaths sreenaths force-pushed the setting-default-jsonrpc-version branch from d626174 to 18051bc Compare September 1, 2025 04:44
Copy link
Contributor

@hesreallyhim hesreallyhim left a comment

Choose a reason for hiding this comment

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

this seems like a move in the right direction but my feeling is - why isn't this just defined at the type that is at the top of the message hierarchy? It's mandatory in every protocol message that goes over the wire. Intuitively, I would expect that to be JSONRPCMessage, I think maybe it's not, but this is the "correct" ontology in my opinion. Whatever type is at the root of all message types (if there is one, which there should be) should have this field set always.

@sreenaths
Copy link
Contributor Author

sreenaths commented Sep 18, 2025

Hi @hesreallyhim
Thank you so much for the suggestion. It would be nice to have a common base class for JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, and JSONRPCError.

But, as the original schema is defined in TypeScript, and types.py depends on it... I am not sure if we can change the base structure in Python SDK. Additionally, we might have to use multiple inheritance as JSONRPCRequest already inherits from Request and JSONRPCNotification from Notification.

I hope one of the maintainers can guide us.

\cc @ochafik

@hesreallyhim
Copy link
Contributor

But, as the original schema is defined in TypeScript, and types.py depends on it... I am not sure if we can change the base structure in Python SDK. Additionally, we might have to use multiple inheritance as JSONRPCRequest already inherits from Request and JSONRPCNotification from Notification.

yeah... well i think they've kind of fixed this in the draft spec, but the sdk may still choose to do things a little differently.

@Kludex
Copy link
Member

Kludex commented Sep 19, 2025

Copy link

@ochafik ochafik left a comment

Choose a reason for hiding this comment

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

Thanks @sreenaths !

@ochafik
Copy link

ochafik commented Sep 19, 2025

We need to migrate to this: https://github.com/Kludex/mcp/blob/main/src/mcp-types/mcp_types/__init__.py

@Kludex not sure it would support passing the literal values as defaults?

@hesreallyhim
Copy link
Contributor

sorry, perhaps I should have been more direct - i would need to study the codebase more closely to understand how the sdk consumes the spec schema.ts - in the case of the typescript SDK i think they had decided to declare the internal types as not including jsonprc, and adding this in at a "protocol" layer before sending the message over the wire. In any case, the observations made above by @sreenaths, such as:

It would be nice to have a common base class for JSONRPCRequest, JSONRPCNotification, JSONRPCResponse, and JSONRPCError.

was actually just an oversight in the MCP schema.ts (or so I argued) - the schema hierarchy was not type-theoretically correct. I merged a change into the draft so that all requests inherit from JSONRPCRequest, and notifications extend JSONRPCNotification - see modelcontextprotocol/modelcontextprotocol#1026 for more info if interested. I hope this is relevant, sorry if it's not, just flagging that there is an upcoming change surrounding this part of the schema.

@sreenaths sreenaths force-pushed the setting-default-jsonrpc-version branch from 18051bc to becfff2 Compare September 19, 2025 15:54
@sreenaths
Copy link
Contributor Author

Thank you for the review, @ochafik.

@hesreallyhim It looks like your changes are one level down the class hierarchy, so I believe our changes are independent.

Thanks, @Kludex. Will mcp_types be included in the Python SDK? As @ochafik mentioned, does mcp_types set literal values as defaults? From what I can see, it only defines the types here: mcp_types

@sreenaths sreenaths force-pushed the setting-default-jsonrpc-version branch from becfff2 to 7e2292a Compare September 23, 2025 05:23
@felixweinberger felixweinberger added the needs more eyes Needs alignment among maintainers whether this is something we want to add label Sep 23, 2025
@felixweinberger felixweinberger self-assigned this Sep 30, 2025
@felixweinberger felixweinberger added needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention enhancement New feature or request and removed needs more eyes Needs alignment among maintainers whether this is something we want to add labels Sep 30, 2025
@sreenaths
Copy link
Contributor Author

Thank you, @felixweinberger
Hope this can be merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants