0Pricing
MCP Academy · درس

إرجاع نتائج مفيدة

أعيدوا نصًا يستطيع النموذج والمستخدم الاستفادة منه.

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

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

The Result Goes Back to the Model

Whatever your tool returns is fed back to the AI as context, so it shapes the model's next answer to the user. 🔁

Return a String

The simplest useful result is a plain string. FastMCP wraps it as text content the model reads directly.

@mcp.tool()
def greet(name: str) -> str:
    return "Hello, " + name

Make Text Self-Explaining

The model has no other context, so your text should explain itself. Return The total is 42, not just 42.

Numbers Are Stringified

If you return an int or float, FastMCP converts it to text for you, but adding a label makes the value clearer to the model.

@mcp.tool()
def add(a: int, b: int) -> int:
    return a + b

Return Structured Data

Return a dict or list and FastMCP serializes it to JSON, giving the model clean, parseable fields instead of loose prose.

@mcp.tool()
def stats() -> dict:
    return {"users": 12, "active": 9}

Keep Results Concise

Every returned token costs the model context budget, so trim your result to what actually answers the request. Less noise, sharper replies.

Format for Reading

When a result has parts, a little structure helps. Short labeled lines beat one long sentence the model has to untangle.

Return Errors as Text

When something goes wrong, returning a clear message lets the model explain the problem and try a fix, instead of guessing.

if not city:
    return "Error: city is required."

Don't Return Secrets

The result reaches the model and often the user, so never include secrets like API keys or raw passwords in what you return.

Consistent Shapes Help

Return the same shape every call so the model learns what to expect. Surprises in structure lead to misread answers.

Match the Tool's Promise

Your result should deliver exactly what the description promised. If you said it returns the price, return the price, not a whole report.

Quick Check

What happens when your tool returns a Python dict?

Recap

Your result becomes the model's context: return clear, concise, self-explaining text or JSON, keep shapes consistent, and never leak secrets. ✅

الأسئلة الشائعة

هل درس «إرجاع نتائج مفيدة» مجاني؟

نعم — نص درس «إرجاع نتائج مفيدة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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