Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Server] Allow tools to return structured content without text content

未关闭
#521 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
69/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
php

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

enhancement

Is your feature request related to a problem? Please describe.

When a tool returns structured data, the SDK currently produces both:

  • a serialized JSON TextContent representation in content;
  • 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

  1. Manually construct CallToolResult in every tool

    A tool can currently return a CallToolResult directly and decide whether to include content or structuredContent.

    However, this requires application-level code to know about the response-shaping details and duplicates the same logic across tools.

  2. Use RequestContext and inspect the connected client

    A tool can inspect the client information through RequestContext and choose the response shape dynamically.

    This works as a workaround, but it couples every tool to client detection and requires repetitive boilerplate.

  3. 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.

主要语言
PHP
星标
1.6k
派生
173
平均合并
19 小时 19 分钟
30 天内合并 PR
8

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/php-sdk 的其他 Issue

查看 modelcontextprotocol/php-sdk 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。