0Pricing
MCP Academy · レッスン

テキストだけでなくメッセージを返す

プロンプトの出力を構造化されたチャットメッセージとして整形します。

「テキストだけでなくメッセージを返す」はCoddyKit上の無料MCP Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMCP Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 MCP Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Beyond a Single String

A prompt can do more than return one line. It can return a list of messages to seed a richer, multi-turn opener. 🗂️

Messages Have Roles

Each message carries a role, usually user or assistant. Roles let you stage a short back-and-forth before the user even types.

The Message Helpers

The SDK gives you UserMessage and AssistantMessage helpers so you can build chat turns without hand-writing the raw structure.

from mcp.server.fastmcp.prompts import base

@mcp.prompt()
def ask() -> list[base.Message]:
    return [base.UserMessage("Help me debug.")]

Return a List

To send several turns, return a list of these message objects. The host replays them in order as the conversation's start.

return [
    base.UserMessage("Explain this error."),
    base.AssistantMessage("Sure, paste it in.")
]

A Single String Still Works

Returning a plain string is just shorthand: the SDK wraps it as one user message. Lists give you finer control over the setup.

Stage the Assistant

An AssistantMessage can prime the model's persona or remind it of rules, so the conversation begins already on the right track.

Set Up Context

Use opening messages to plant context, like coding standards or a role, that the model should keep in mind throughout the task.

Mix Arguments In

You can still slot arguments into any message in the list. The user's inputs flow into a structured conversation, not just one line.

@mcp.prompt()
def debug(error: str) -> list[base.Message]:
    return [base.UserMessage(f"Fix this error:\n{error}")]

Order Matters

The list order is the turn order. Lead with context or a system-style note, then the user's request, so the model reads it naturally.

Why Use Messages

Structured messages shape a better starting point than one blob of text, especially for tasks that need setup before the real ask.

Keep It Lean

A couple of well-placed turns beat many. Each extra message costs tokens, so include only what truly improves the result.

Quick Check

Let's pin down the richer return type.

Recap: Message Output

Well done! Prompts can return a list of role-tagged messages built with UserMessage and AssistantMessage to stage a richer opener. ✅

よくある質問

「テキストだけでなくメッセージを返す」レッスンは無料ですか?

はい。「テキストだけでなくメッセージを返す」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、MCP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 MCP Academyコースには全4レッスンが含まれています。

「テキストだけでなくメッセージを返す」で何を学びますか?

プロンプトの出力を構造化されたチャットメッセージとして整形します。 ブラウザで直接実行するハンズオンコードでMCP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

MCP Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのMCP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「テキストだけでなくメッセージを返す」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このMCP Academyレッスンでコードを書いて実行できますか?

はい。すべてのMCP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 最初のプロンプトを登録する
  2. プロンプトに引数を追加する
  3. テキストだけでなくメッセージを返す
  4. コードレビュー用プロンプトテンプレート
← MCP Academyに戻る