[Server] Allow tools to return structured content without text content
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 69/100
- Issue-Typ
- Feature
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- php
- Bereich
- backend-api-design
Rechercherichtung
Read ToolReference::formatResult(), ToolReference::extractStructuredContent(), and the tool call handler that builds CallToolResult to understand the existing result-formatting flow. Add the explicitly opt-in per-tool behavior while preserving the default, and verify that opted-in results omit generated text content but retain structured content; existing or new tests around this pipeline should cover both modes.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Is your feature request related to a problem? Please describe.
When a tool returns structured data, the SDK currently produces both:
- a serialized JSON
TextContentrepresentation incontent; - the same data in
structuredContent.
For clients that consume structuredContent, the text representation is redundant and can significantly increase the size of the tool response. In some integrations, large duplicated JSON content may also be stored, truncated, or paginated unnecessarily.
This was discussed in symfony/ai#2200.
The current workaround is for every tool to inject RequestContext and manually construct a CallToolResult, deciding whether to include content depending on the client.
This also couples individual tools to client-specific behavior.
Describe the solution you'd like
Allow a tool to explicitly opt into structured-content-only results.
For example, an attribute-level option:
#[McpTool(structuredContentOnly: true)]
public function getData(): array
{
return [
'foo' => 'bar',
];
}
When enabled, the SDK would produce a CallToolResult with:
new CallToolResult(
content: [],
structuredContent: [
'foo' => 'bar',
],
);
The default behavior should remain unchanged.
Ideally, the option should be handled inside the SDK's existing tool result formatting pipeline, rather than requiring individual tools to construct CallToolResult themselves.
This would provide an explicit per-tool opt-in without introducing client-specific logic into the SDK.
Describe alternatives you've considered
-
Manually construct
CallToolResultin every toolA tool can currently return a
CallToolResultdirectly and decide whether to includecontentorstructuredContent.However, this requires application-level code to know about the response-shaping details and duplicates the same logic across tools.
-
Use
RequestContextand inspect the connected clientA tool can inspect the client information through
RequestContextand choose the response shape dynamically.This works as a workaround, but it couples every tool to client detection and requires repetitive boilerplate.
-
Automatically detect the client and choose the response format
This could be useful as a future enhancement, but it seems like a separate concern from the basic SDK capability.
A per-tool opt-in would provide a small, predictable first step while keeping automatic client-aware shaping as a possible follow-up.
Additional context
The Symfony AI discussion identified that this behavior belongs in mcp/sdk, rather than symfony/mcp-bundle, because the actual result shaping is implemented by the SDK.
Relevant SDK code includes:
ToolReference::formatResult()ToolReference::extractStructuredContent()- the tool call handler that builds
CallToolResult
See the discussion in symfony/ai#2200 and the follow-up documentation PR #2506.
The MCP protocol already models content and structuredContent as separate parts of CallToolResult; content is an array, so an empty content array can represent a structured-content-only result.
The SDK could preserve the current behavior by default and only omit the generated TextContent when the new option is explicitly enabled.
- Vorherrschende Sprache
- PHP
- Sterne
- 1.6k
- Forks
- 173
- Ø Merge
- 19 Std. 19 Min.
- Gemergte PRs (30 T.)
- 8
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/php-sdk
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
modelcontextprotocol/php-sdk#516 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Server] Handler type uses bare Closure, hard to decorate RegistryInterface under strict PHPStanOffenServer
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
modelcontextprotocol/php-sdk#468 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
needs confirmation needs maintainer action Server
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
modelcontextprotocol/php-sdk#398 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
modelcontextprotocol/php-sdk#370 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
modelcontextprotocol/php-sdk#522 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in modelcontextprotocol/php-sdk
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 2 Tagen
-
UX
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
ProfessionalWiki/NeoWiki#1573 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
endoflife-date/endoflife.date#11194 ·
Maintainer antworten meist innerhalb von 1 Tag