إرسال التقدم للمهام الطويلة
ابثوا تحديثات نسبة الإنجاز إلى العميل.
إرسال التقدم للمهام الطويلة درس مجاني في MCP Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MCP Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MCP Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Progress Matters
When a tool takes seconds or minutes, the client should not just hang. MCP lets your server send progress updates so the user sees movement.
The Progress Token
The client opts in by attaching a progressToken to the request. Without that token, your server simply skips sending updates.
Reach the Context Object
In the Python SDK, a tool receives a Context object. It is your handle for talking back to the client mid-call, including progress.
from mcp.server.fastmcp import Context
@mcp.tool()
async def crunch(n: int, ctx: Context) -> str:
return "done"Call report_progress
To push an update, you call ctx.report_progress. Each call tells the client how far along the work has come.
await ctx.report_progress(progress=3, total=10)Progress and Total
The total argument is the finish line. The client can divide progress by total to draw a percent-done bar for the user.
await ctx.report_progress(progress=5, total=10) # 50%Update Inside a Loop
The natural place to report is inside your work loop. After each chunk finishes, send one update so the bar climbs steadily.
for i, item in enumerate(items):
process(item)
await ctx.report_progress(i + 1, len(items))Progress Without a Total
Sometimes you cannot know the total upfront. You may omit it; the client then shows an indeterminate spinner instead of a precise bar.
await ctx.report_progress(progress=42) # total unknownAdd an Optional Message
Many SDK versions let you attach a short message to a progress call, like "Indexing files", giving the user friendly human context.
await ctx.report_progress(2, 5, message="Fetching pages")It Is a Notification
Progress travels as a JSON-RPC notification, so it has no reply and never blocks. Your tool keeps working while updates flow out.
Keep Updates Reasonable
Do not flood the client with thousands of tiny updates. Report at meaningful steps so the stream stays useful and lightweight.
Progress Plus a Result
Progress notifications are separate from your tool's return value. You stream updates as you go, then hand back the final result at the end.
await ctx.report_progress(10, 10)
return "index built"Quick Check
Test your grasp of how progress reporting begins.
Recap: Progress
You learned to call ctx.report_progress with progress and total, loop your updates, and let the client draw a live bar. Nice work!
الأسئلة الشائعة
هل درس «إرسال التقدم للمهام الطويلة» مجاني؟
نعم — نص درس «إرسال التقدم للمهام الطويلة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- إرسال التقدم للمهام الطويلة
- معالجة طلبات الإلغاء
- التسجيل المنظم إلى العميل
- ضبط مستويات السجل أثناء التشغيل