mcp: render blank text field in TextContent instead of omitempty (#91)

The text field is required, but current implementation omits the text
field when it is a blank string.

Some clients fail to parse the response if the text field is omitted. A
blank text result is a valid MCP response.

Claude desktop error message:
```
ClaudeAiToolResultRequest.content.0.text.text: Field required
```

The solution is to return the field even when it is blank by removing
`omitempty`.
This commit is contained in:
Martin Emde 2025-07-04 10:46:41 -07:00 • committed by GitHub
commit c6b229c855
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,6 +22,14 @@ func TestContent(t *testing.T) {
&mcp.TextContent{Text: "hello"},
`{"type":"text","text":"hello"}`,
},
{
&mcp.TextContent{Text: ""},
`{"type":"text","text":""}`,
},
{
&mcp.TextContent{},
`{"type":"text","text":""}`,
},
{
&mcp.TextContent{
Text: "hello",