modelcontextprotocol / modelcontextprotocol/csharp-sdk

ToolResult always returns as "Text" with without be decoded

Offen
#962 14 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

enhancement needs confirmation P3
Vorherrschende Sprache
C#
Sterne
4.5k
Forks
814
Ø Merge
9 T. 19 Std.
Gemergte PRs (30 T.)
4

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue nennt keine Quelldateien, Tests oder Einstiegspunkte; beginne damit nachzuverfolgen, wie ein MCP-Tool, das DTO-Listen zurückgibt, zum standardmäßigen Textinhalt von ToolResult wird. Vergleiche das serialisierte Ergebnis mit der angeforderten Darstellung und lege das erwartete Verhalten mit den Maintainer:innen fest. Fertig, wenn das Ergebnis unnötige Kodierung vermeidet und Tests den DTO-Listen-Fall abdecken.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
api
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.