0Pricing
MCP Academy · درس

إرجاع رسائل لا نص فقط

شكّلوا مخرجات التعليمة على هيئة رسائل محادثة منظمة.

إرجاع رسائل لا نص فقط درس مجاني في MCP Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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/7) وفتح باقي دورة MCP Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MCP Academy 4 دروس في المجموع.

ماذا ستتعلم في «إرجاع رسائل لا نص فقط»؟

شكّلوا مخرجات التعليمة على هيئة رسائل محادثة منظمة. تتمرن على MCP Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ MCP Academy؟

لا تُشترط خبرة سابقة. MCP Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «إرجاع رسائل لا نص فقط»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس MCP Academy هذا؟

نعم. كل درس في MCP Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تسجيل أول تعليمة
  2. إضافة وسيطات إلى تعليمة
  3. إرجاع رسائل لا نص فقط
  4. قالب تعليمة لمراجعة التعليمات البرمجية
← العودة إلى MCP Academy