Skip to content

Result types should inherit from JSONRPCResponse #1730

@maxisbey

Description

@maxisbey

Problem

Result types like CallToolResult inherit from Result, not JSONRPCResponse. This means they're missing the jsonrpc: "2.0" and id fields.

Current inheritance:

Result (types.py:133)
└── meta: dict | None

JSONRPCResponse (types.py:168) - separate, not inheriting from Result
├── jsonrpc: Literal["2.0"]
├── id: RequestId
└── result: dict

CallToolResult (types.py:1363) extends Result
└── Missing jsonrpc, id fields

The SDK has to manually wrap every result to add the JSON-RPC envelope before sending (session.py:386-389):

jsonrpc_response = JSONRPCResponse(
    jsonrpc="2.0",
    id=request_id,
    result=response.model_dump(by_alias=True, mode="json", exclude_none=True),
)

Same pattern as the notification inheritance issue - might be worth rethinking the type hierarchy.

Related

AI Disclaimer

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Broken core functionality, security issues, critical missing featurebreaking changeWill break existing deployments when updated without changesenhancementRequest for a new feature that's not currently supportedv2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions