0Pricing
MCP Academy · درس

أخطاء الأدوات التي يستطيع النموذج رؤيتها

أعيدوا أخطاء يستطيع الذكاء الاصطناعي قراءتها والتعافي منها.

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

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

Errors Are Just More Context

When a tool fails, the AI does not crash. It simply reads your error as context and decides what to do next, just like any result.

A Good Error Is Actionable

Write the error for a reader who can act on it. City not found beats Exception, because the model can ask the user to fix the city.

Return an Error String

The simplest pattern is returning a clear message string when something is wrong, so the model reads exactly what failed.

@mcp.tool()
def get_user(uid: int) -> str:
    if uid < 1:
        return "Error: uid must be positive."

Raise to Flag a Tool Error

You can also raise a normal Python exception. FastMCP catches it and reports a tool error back to the model, not a server crash.

@mcp.tool()
def divide(a: float, b: float) -> float:
    if b == 0:
        raise ValueError("b cannot be zero")
    return a / b

isError Marks the Result

Under the hood, a failed tool call returns content with isError set true. That flag tells the client this result describes a failure.

The Model Can Recover

A readable error lets the AI retry with better input or explain the issue to the user, turning a failure into a helpful next step. 🔁

Say What and Why

Good errors name what failed and why. File missing: report.csv is far more useful to the model than a bare Not found.

Suggest a Fix

When you can, hint at the remedy inside the error. Date must be YYYY-MM-DD lets the model correct itself on the very next call.

if not iso_date:
    raise ValueError("Date must be in YYYY-MM-DD format")

Never Leak Internals

Errors reach the model and often the user, so keep secrets, raw stack traces, and connection strings out of the message you return.

Validate, Then Error Early

Check arguments first and return the error before doing real work. Failing fast keeps your tool predictable and easy to reason about.

Errors Are Part of the Contract

Treat failures as designed output. A tool that names its likely errors is as useful to the model as one that documents its success.

Quick Check

Why write tool errors as clear, readable messages?

Recap

Tool errors are context the model reads: make them clear, say what and why, suggest a fix, and never leak internals. ✅

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

هل درس «أخطاء الأدوات التي يستطيع النموذج رؤيتها» مجاني؟

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

ماذا ستتعلم في «أخطاء الأدوات التي يستطيع النموذج رؤيتها»؟

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

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

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

كم من الوقت يستغرق درس «أخطاء الأدوات التي يستطيع النموذج رؤيتها»؟

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

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

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

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

  1. أخطاء الأدوات التي يستطيع النموذج رؤيتها
  2. أخطاء البروتوكول في مقابل أعطال الأدوات
  3. التحقق من المدخلات قبل التنفيذ
  4. الفشل بأمان دون تعليق التنفيذ
← العودة إلى MCP Academy