McpServer: let a tool choose its structuredContent together with its content

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
47/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript
领域
api

调研方向

Start by reading the implementations and tests for McpServer.registerToolkit and toModelOutput, along with the behavior introduced by issues #10733 and #10740. Trace how content mappers produce CallToolResult values and how structuredContent and outputSchema are handled. Done means a mapper can provide both media content and structured data while preserving the output schema, with existing array mapper behavior unchanged.

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

描述

Note: everything below was written by an AI agent working on the author's behalf and may not have been reviewed by a human.

This is AI-generated; I don't have strong opinions on the API or developer experience and am glad to take whatever shape you prefer, but I do need the functionality.

Problem

#10733 and #10740 let a toolkit tool choose its result content, which covers most of what I needed. One case is left: a result that holds both structured data and media.

My tools return a JSON value that can contain images and audio (base64, as the MCP wire encoding has them). I want the client to get:

  • the media as image / audio content blocks, so the model sees them, and
  • the rest of the value as structuredContent, without the media, so the bytes are not sent twice and do not count against a client's text limits twice.

Today neither option gives that:

  • toModelOutput sets content, but structuredContent is always the whole encoded result, media included.
  • A content mapper sets content, but then structuredContent and outputSchema are dropped.

What I do today

I carry a patch adding a tool annotation, McpServer.ResultContent, a function from the encoded success value to { content, structuredContent? }. The server decodes what it returns as a CallToolResult, so it uses the wire encoding, and a block that does not decode is an internal tool error. Declared failures, and tools without the annotation, keep the default result.

Proposal

The smallest change that covers it: let the content mapper of registerToolkit (or toModelOutput) return structuredContent as well:

McpServer.registerToolkit(tools, {
  content: {
    run: (value) => ({
      content: mediaBlocks(value),
      structuredContent: withoutMedia(value)
    })
  }
})

Returning an array, as today, keeps the current behaviour. When a mapper returns structuredContent, the tool would keep its outputSchema, and the mapper is then responsible for matching it.

Would you take this, or would you prefer another place for it? I can open a PR.

主要语言
TypeScript
星标
16.7k
派生
808
平均合并
21 小时 22 分钟
30 天内合并 PR
486

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

Effect-TS/effect 的其他 Issue

查看 Effect-TS/effect 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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