文本与结构化内容
了解何时返回纯文本,何时返回数据。
文本与结构化内容 是 CoddyKit 上的免费 MCP Academy 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 MCP Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 MCP Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Two Ways to Reply
Every MCP tool result carries content, and you choose its shape. The big split is plain text versus structured data the client can parse.
What Text Content Is
A text result is just a string for the model to read, like a sentence or a paragraph. It is simple, human-friendly, and easy to drop into a prompt. 📝
What Structured Content Is
Structured content is real data, like a JSON object with named fields. Clients can read each field instead of guessing from prose.
{"temp_c": 21, "condition": "sunny", "city": "Cappadocia"}Why Text Alone Can Fail
If a tool returns "It is 21 degrees and sunny," the client must parse that English to use it. Wording changes break the parsing instantly.
Why Structure Wins for Code
With structured output, a client reads result.temp_c directly. The shape is predictable, so apps and agents can rely on it without scraping text.
You Can Send Both
MCP lets a tool return a readable text summary and structured data together. The model reads the prose; code reads the fields.
When Text Is the Right Call
Pick plain text when the answer is a message for a human to read, like an explanation, a status note, or a short summary.
When Structure Is the Right Call
Pick structured content when another program will consume the result, such as a price, a record, or a list of items to act on.
Default Is Text
If your tool just returns a string, MCP wraps it as text content automatically. Structured output is something you opt into on purpose.
def get_status() -> str:
return "All systems healthy"Think Consumer First
Ask who reads the result: a human, the model, or downstream code? That consumer decides whether you reach for text or structure.
Mixing Is Common
Mature tools usually return both: a friendly summary for the model plus a typed payload for the app. This keeps the result useful on every side.
Quick Check
A tool feeds prices into a billing app. Which output fits best?
Recap: Text vs Structure
You learned the two result shapes: readable text for humans and the model, and structured data for code. Match the shape to who reads it. ✅
常见问题解答
「文本与结构化内容」课时是免费的吗?
是的 — 「文本与结构化内容」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 MCP Academy 课程的其余内容,请升级到 CoddyKit PRO。 MCP Academy 课程共包含 4 节课。
「文本与结构化内容」这节课中我会学到什么?
了解何时返回纯文本,何时返回数据。 你通过在浏览器中直接运行的动手代码来练习 MCP Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 MCP Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 MCP Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。
「文本与结构化内容」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 MCP Academy 课中编写并运行代码吗?
能。每节 MCP Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 文本与结构化内容
- 返回带类型的结果对象
- 面向客户端的输出模式
- 返回图像和二进制数据