إرجاع الصور والبيانات الثنائية
أرسلوا محتوى غير نصي عبر أداة.
إرجاع الصور والبيانات الثنائية درس مجاني في MCP Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MCP Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MCP Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Beyond Text and JSON
Some tools produce pictures or files, not words. MCP can return binary content like images and other blobs, not just text.
The Image Content Type
MCP defines an image content type carrying the raw bytes plus a media type. Clients that support it can render the picture directly. 🖼️
Bytes Travel as Base64
Binary data is encoded as base64 text so it survives the JSON message. The client decodes it back into real bytes on arrival.
The Image Helper
The Python SDK offers an Image helper so you do not hand-encode anything. You point it at bytes or a path and return it.
from mcp.server.fastmcp import Image
return Image(data=png_bytes, format="png")Set the Media Type
Always state the format, like png or jpeg, so the client knows how to decode and display the image correctly.
Returning a File on Disk
Read the file into bytes, then wrap it for return. The tool turns a saved chart into a viewable result for the model and user.
data = open("chart.png", "rb").read()
return Image(data=data, format="png")Not Only Images
Beyond pictures, MCP supports generic blob content for other binary data, like a PDF or audio, with its own media type.
Client Support Varies
Not every client can show every type. A host that cannot render an image may fall back to a reference or a download link.
Watch the Size
Base64 inflates data by about a third, and large blobs eat tokens and bandwidth. Keep returned media small when you can.
Prefer Resources for Big Files
For very large or shared files, expose a resource by URI instead of inlining bytes in a tool result. The client fetches on demand.
Combine With Text
You can pair an image with a short text caption in the same result, giving the model both a picture and words to reason about.
Quick Check
How does binary data ride inside an MCP message?
Recap: Images & Blobs
You can return images and binary blobs via base64 with a media type, set the format, mind size, and prefer resources for big files. ✅
الأسئلة الشائعة
هل درس «إرجاع الصور والبيانات الثنائية» مجاني؟
نعم — نص درس «إرجاع الصور والبيانات الثنائية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MCP Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MCP Academy 4 دروس في المجموع.
ماذا ستتعلم في «إرجاع الصور والبيانات الثنائية»؟
أرسلوا محتوى غير نصي عبر أداة. تتمرن على MCP Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ MCP Academy؟
لا تُشترط خبرة سابقة. MCP Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «إرجاع الصور والبيانات الثنائية»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس MCP Academy هذا؟
نعم. كل درس في MCP Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- المحتوى النصي في مقابل المنظم
- إرجاع كائن نتيجة مكتوب الأنواع
- مخططات المخرجات للعملاء
- إرجاع الصور والبيانات الثنائية