ToolResult always returns as "Text" with without be decoded

Open
#962 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp
Domain
api

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.

Description

enhancement needs confirmation P3

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

Dominant language
C#
Stars
4.5k
Forks
814
Avg merge
9d 19h
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from modelcontextprotocol/csharp-sdk

All issues in modelcontextprotocol/csharp-sdk

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.