0Pricing
MCP Academy · درس

معرّفات URI ذات المعلمات للموارد

استخرجوا المتغيرات مباشرةً من مسار URI.

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

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

One Pattern, Many Resources

A static resource has one fixed address. A parameterized URI is a pattern that stands in for a whole family of resources at once. ✨

Placeholders in Curly Braces

You mark the variable part of a URI with a placeholder in curly braces, like users://{user_id}/profile. That brace is a slot to fill.

users://{user_id}/profile

The Template Is a Promise

A resource template tells the client: any URI matching this shape is valid. The model can plug in real values to ask for exactly what it needs.

Decorate to Register

In the Python SDK you register a template the same way as a tool: with the @mcp.resource decorator, passing the URI pattern as its argument.

@mcp.resource("users://{user_id}/profile")
def get_profile(user_id: str) -> str:
    return f"Profile for {user_id}"

Names Must Match

Every placeholder in the URI must appear as a function parameter with the same name. The SDK wires {user_id} straight into your user_id argument.

Capture More Than One

You can capture several variables in one URI. Multiple placeholders each map to their own parameter, so one pattern can pinpoint very specific data.

@mcp.resource("repos://{owner}/{name}/readme")
def readme(owner: str, name: str) -> str:
    return load_readme(owner, name)

Values Arrive as Strings

Captured pieces come in as text from the URI. If you need a number, convert it yourself inside the function before using it.

def get_page(page: str) -> str:
    n = int(page)
    return render_page(n)

One Segment Per Placeholder

By default a placeholder captures a single path segment, the text between two slashes. It stops at the next slash, so it won't swallow the rest of the path.

Templates Don't List Themselves

A plain resource shows up in the resource list. A templated resource usually does not, since there are endless possible URIs. The client reads it by filling the pattern.

Keep URIs Meaningful

Design URIs that read like clear addresses, such as weather://{city}/today. A model picks the right resource far more reliably when the path explains itself.

weather://{city}/today

Why This Matters

Parameterized URIs let one tidy function serve thousands of resources. You write the shape once, and the variable parts do the rest. 🎯

Quick Check

How does a captured URI placeholder reach your function?

Recap

You learned that parameterized URIs use curly-brace placeholders to serve a whole family of resources, each one mapped to a matching function parameter. Next: building their content. 🚀

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

هل درس «معرّفات URI ذات المعلمات للموارد» مجاني؟

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

ماذا ستتعلم في «معرّفات URI ذات المعلمات للموارد»؟

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

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

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

كم من الوقت يستغرق درس «معرّفات URI ذات المعلمات للموارد»؟

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

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

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

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

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