Description
Describe the bug
In my implementation I am returning a complex object from my tool, so I JsonSerializer.Serialize(obj)
it and return string
from my tool.
When I get the value back on the other side, numerous characters in the JSON are escaped (\u\\\....
) and so attempting to deserialize the value in .Text
blows up.
To Reproduce
Steps to reproduce the behavior:
- Return a string created from JSON-serializing an object from an McpServerTool implementation.
- Attempt to deserialize the value of
.Text
on the client.
Expected behavior
Strings shouldn't get munged by anything from return time to arrival on the client.
Logs
String value upon return from Tool:
{"completion":[{"Role":{"Label":"system"},"Items":[{"$type":"TextContent","Text":"You are an expert data search ass
String value on client side when attempting to deserialize:
{"text":"{\u0022completion\u0022:[{\u0022Role\u0022:{\u0022Label\u0022:\u0022system\u0022},\u0022Items\u0022:[{\u0022$type\u0022:\u0022TextContent\u0022,\u0022Text\u0022:\u0022You are an expert data search
Additional context
I've tried taking the bytes of the JSON value and wrapping them up in DataContent
but this fails as well. Similarly, I've tried returning not just a string
but a TextContent
object also to no avail, even if I set RawRepresentation
on it.