0Pricing
MCP Academy · درس

التسجيل المنظم إلى العميل

أصدروا رسائل سجل بمستويات مختلفة عبر البروتوكول.

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

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

Logs the Client Can See

Printing to your terminal only helps you. MCP lets the server send log messages over the protocol so the host app can show them too.

The message Notification

Logs travel as a notifications/message notification. It carries a level, optional logger name, and the data you want recorded.

{"method": "notifications/message",
 "params": {"level": "info", "data": "Indexing started"}}

Use the Context

From inside a tool you reach logging through the Context object, the same handle you used for progress. No extra setup is needed.

from mcp.server.fastmcp import Context

ctx.info for Updates

The most common helper is ctx.info. Use it for normal, expected status notes that help a user follow what the tool is doing.

await ctx.info("Loaded 120 records from disk")

ctx.debug for Detail

Reach for ctx.debug when you want fine-grained traces, like a parsed value or a chosen branch, that are noisy in everyday use.

await ctx.debug(f"chosen strategy = {strategy}")

ctx.warning for Surprises

Use ctx.warning when something is off but recoverable, like a missing optional field that you filled with a default value.

await ctx.warning("timeout missing, using 30s default")

ctx.error for Failures

Call ctx.error for genuine problems. It tells the client a step failed, separate from raising an exception that ends the call.

await ctx.error("upstream API returned 503")

Standard Severity Levels

MCP follows the familiar syslog scale: debug, info, notice, warning, error, critical, and higher. Clients can sort and color by level.

Name Your Logger

Many helpers accept a logger name so messages can be grouped by component, much like Python's standard logging module does.

await ctx.info("cache miss", logger="db")

Never Log Secrets

Log messages leave your process and reach the client, so treat them as visible. Never write secrets like tokens or passwords into a log.

Logs Are Notifications

Like progress, each log is a notification, so it never blocks your tool or expects a reply. You can log freely as the work unfolds.

await ctx.info("step 1 done")
await ctx.info("step 2 done")

Quick Check

Pick the right helper for routine status updates.

Recap: Logging

You can now emit leveled logs with ctx.info, debug, warning, and error, name your loggers, and keep secrets out. Great progress!

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

هل درس «التسجيل المنظم إلى العميل» مجاني؟

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