تعريف المعلمات باستخدام تلميحات الأنواع
استخدموا تلميحات الأنواع في Python لتشكيل مخطط الأداة.
تعريف المعلمات باستخدام تلميحات الأنواع درس مجاني في MCP Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MCP Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MCP Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Parameters Become a Schema
Every argument of your tool function turns into part of an input schema the model must follow when it calls your tool. 🧩
Type Hints Do the Work
FastMCP reads your Python type hints and builds the JSON schema for you, so you rarely write schema by hand.
@mcp.tool()
def add(a: int, b: int) -> int:
return a + bstr, int, float, bool
The basic types map cleanly: str becomes string, int and float become number, and bool becomes boolean in the schema.
Untyped Means Unclear
Skip the type hint and the model only sees a loose value with no rules, which invites wrong or invalid input.
def add(a, b):
return a + bRequired by Default
A parameter with no default value is treated as required, so the model must always supply it when calling the tool.
Defaults Make It Optional
Give a parameter a default and it becomes optional. The model may omit it, and your function uses the fallback value.
@mcp.tool()
def greet(name: str, formal: bool = False) -> str:
...Lists and Dicts
You can hint collections too. A list argument maps to a JSON array, and a dict maps to an object the model can fill in.
def tag(items: list[str]) -> int:
return len(items)Optional Values
Use Optional when an argument may be a value or None, signaling that the model can leave it empty on purpose.
from typing import Optional
def find(q: str, limit: Optional[int] = None):
...Name Parameters Clearly
The model sees each parameter name in the schema, so city beats c and start_date beats arg2. Clear names guide better calls.
Hints Power Validation
Because hints define the schema, MCP can reject calls with the wrong type before your code runs, catching mistakes early.
Keep the Signature Small
Fewer, well-typed parameters are easier for the model to fill correctly than a long list of loosely related arguments.
Quick Check
What makes a tool parameter optional in FastMCP?
Recap
Your type hints build the tool schema: basic types map directly, defaults mean optional, and clear names guide the model. ✅
الأسئلة الشائعة
هل درس «تعريف المعلمات باستخدام تلميحات الأنواع» مجاني؟
نعم — نص درس «تعريف المعلمات باستخدام تلميحات الأنواع» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MCP Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MCP Academy 4 دروس في المجموع.
ماذا ستتعلم في «تعريف المعلمات باستخدام تلميحات الأنواع»؟
استخدموا تلميحات الأنواع في Python لتشكيل مخطط الأداة. تتمرن على MCP Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ MCP Academy؟
لا تُشترط خبرة سابقة. MCP Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «تعريف المعلمات باستخدام تلميحات الأنواع»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس MCP Academy هذا؟
نعم. كل درس في MCP Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تسمية الأداة ووصفها جيدًا
- تعريف المعلمات باستخدام تلميحات الأنواع
- إرجاع نتائج مفيدة
- أداة آلة حاسبة من البداية إلى النهاية