0Pricing
MCP Academy · درس

تقديم مورد نصي ثابت

أتِيحوا مستندًا ثابتًا ليقرأه النموذج.

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

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

A Fixed Document

The simplest resource is a static one: a fixed string your server returns every time. Great for help text, policies, or config notes.

One Function, One URI

You expose it by writing a Python function and tagging it with a resource URI. When a client reads that URI, your function runs and returns text.

The Decorator

The resource decorator registers the function under its URI. The string you pass becomes the address clients use to fetch the content.

@mcp.resource("info://welcome")
def welcome():
    return "Welcome to the server!"

Return Plain Text

For a text resource, just return a Python string. The SDK wraps it into the proper MCP read response so the client receives clean content.

Name and Describe It

Give the resource a clear description so the model knows when to read it. A docstring on the function is used as that description.

@mcp.resource("info://welcome")
def welcome():
    "Greeting shown to new users."
    return "Hello there!"

Static Means No Inputs

A static resource takes no parameters; it always yields the same body. If you need to vary output, that is a job for templates, covered later.

Build Text in Code

The return value can be assembled in Python before sending. The result is still static to the client, since the same call gives the same text.

@mcp.resource("config://limits")
def limits():
    return "max_items=100\ntimeout=30"

Why Resources, Not Tools

Use a resource when the model only needs to read context. Tools are for actions; reading reference text is exactly what resources are for.

The Model Pulls It In

Many hosts let the user attach a resource to a chat, dropping its content into context. The model then reasons over that text alongside the prompt.

Keep It Lightweight

Static resources load fast since there is no work to do. Reserve them for small, stable text so you do not flood the model with tokens.

Test Your Resource

Run the server and use a client to list and read the URI. Seeing your exact string come back confirms the resource is wired correctly.

Quick Check

Choosing the right primitive for fixed text.

Recap

A static resource is a function under a URI that returns fixed text. Add a docstring description and keep the body small. 📄

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

هل درس «تقديم مورد نصي ثابت» مجاني؟

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

ماذا ستتعلم في «تقديم مورد نصي ثابت»؟

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

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

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

كم من الوقت يستغرق درس «تقديم مورد نصي ثابت»؟

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

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

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

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

  1. شرح معرّفات URI الخاصة بالموارد
  2. تقديم مورد نصي ثابت
  3. قراءة ملف من القرص
  4. ضبط نوع MIME الصحيح
← العودة إلى MCP Academy