Fix errors when title is not specified

Since the optional `title` becomes `title: null` when not provided, the following error occurs.
This occurs with Claude Code 1.0.100.

```console
[DEBUG] MCP server "example": Connection failed after 1591ms: [
  {
    "code": "invalid_type",
    "expected": "string",
    "received": "null",
    "path": [
      "serverInfo",
      "title"
    ],
    "message": "Expected string, received null"
  }
]
```

By adding `compact`, the `title` key will be removed if the optional `title` keyword argument is not specified.
This commit is contained in:
Koichi ITO 2025-09-03 02:13:39 +09:00
commit 47d29e8014
2 changed files with 12 additions and 4 deletions

View file

@ -222,7 +222,7 @@ module MCP
name:,
title:,
version:,
}
}.compact
end
def init(request)

View file

@ -19,7 +19,7 @@ module MCP
title: title_value,
description: description_value,
inputSchema: input_schema_value.to_h,
}
}.compact
result[:annotations] = annotations_value.to_h if annotations_value
result
end