modelcontextprotocol / modelcontextprotocol/csharp-sdk
ToolResult always returns as "Text" with without be decoded
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Description
Is your feature request related to a problem? Please describe.
I've created a tool using the McpServerTool attribute that returns a list of DTOs.
I'm using this tool through a MCP Client inside a chat, everything works fine but I noticed that the result of the tool is a JSON serialized with the result of the tool like this:
{"content":[{"type":"text","text":"[\r\n {\r\n \u0022id\u0022: \u00224309-76-LQ21\u0022,\r\n \u0022procuringEntityName\u0022: \u0022HOSPITAL GUILLERMO GRANT BENAVENTE DE CO\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00221380-4-LQ21\u0022,\r\n \u0022procuringEntityName\u0022: \u0022Hospital Doctor Hern\\u00E1n Henr\\u00EDquez Aravena\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00221058095-30-LE21\u0022,\r\n \u0022procuringEntityName\u0022: \u0022COMPLEJO ASISTENCIAL DR. SOTERO DEL RIO\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u00221058095-34-LE21\u0022,\r\n \u0022procuringEntityName\u0022: \u0022COMPLEJO ASISTENCIAL DR. SOTERO DEL RIO\u0022\r\n },\r\n {\r\n \u0022id\u0022: \u0022359-30-LP21\u0022,\r\n \u0022procuringEntityName\u0022: \u0022Instituto Nacional del Cancer\u0022\r\n }\r\n]"}]}
That content contains a lot of extra characters that causes that the token consumption be more than the expected.
Describe the solution you'd like
Is there any chance to modify the standard result to avoid this behavior?
Describe alternatives you've considered
I went deep into the codebase looking for any option that help me to accomplish that but I found nothing.
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no source files, tests, or entry points; begin by tracing how an MCP tool returning DTO lists becomes the standard ToolResult text content. Compare the serialized result with the requested representation and define the expected behavior with maintainers. Done when the result avoids unnecessary encoding and tests cover the DTO-list case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100