Skip to content

Server unusable - JSONRPCResponse fields must not serialize to null #581

@fluidsonic

Description

@fluidsonic

Describe the bug
null-value properties of JSONRPCResponse (like _meta of RequestResult) incorrectly serialize to null in the response JSON, instead of being omitted.

According to the Spec, null is not an allowed value. It allows either omitting the property or an object value.

The MCP server is unusable.
⚠️ Claude & Claude Code do strict schema checking, which is valid. They reject the MCP response and assume the MCP connection fails.

To Reproduce
Steps to reproduce the behavior:

  1. Connect to a kotlin-sdk MCP server with Claude Code.
  2. Connection fails.

Expected behavior
Connection succeeds.

Logs
From Claude Code's debug log:

[DEBUG] MCP server "<name>": Connection failed after 36ms: [
  {
    "code": "invalid_union",
    "errors": [
      [
        {
          "expected": "string",
          "code": "invalid_type",
          "path": [
            "method"
          ],
          "message": "Invalid input: expected string, received undefined"
        },
        {
          "code": "unrecognized_keys",
          "keys": [
            "result"
          ],
          "path": [],
          "message": "Unrecognized key: \"result\""
        }
      ],
      [
        {
          "expected": "string",
          "code": "invalid_type",
          "path": [
            "method"
          ],
          "message": "Invalid input: expected string, received undefined"
        },
        {
          "code": "unrecognized_keys",
          "keys": [
            "id",
            "result"
          ],
          "path": [],
          "message": "Unrecognized keys: \"id\", \"result\""
        }
      ],
      [
        {
          "expected": "object",
          "code": "invalid_type",
          "path": [
            "result",
            "_meta"
          ],
          "message": "Invalid input: expected object, received null"
        }
      ],
      [
        {
          "expected": "object",
          "code": "invalid_type",
          "path": [
            "error"
          ],
          "message": "Invalid input: expected object, received undefined"
        },
        {
          "code": "unrecognized_keys",
          "keys": [
            "result"
          ],
          "path": [],
          "message": "Unrecognized key: \"result\""
        }
      ]
    ],
    "path": [],
    "message": "Invalid input"
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions