0Pricing
MCP Academy · درس

استدعاء الأدوات من التعليمات البرمجية

استدعوا أداة خادم واقرؤوا نتيجتها.

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

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

From Listing to Doing

Discovery told you what exists. Now you actually invoke a tool, sending arguments and reading back the result from your own code.

Call by Name

Use session.call_tool() with the tool name and a dictionary of arguments. The names must match the inputSchema you discovered.

result = await session.call_tool(
    "add",
    {"a": 2, "b": 3},
)

Arguments Must Validate

Your arguments dictionary should satisfy the tool inputSchema. Sending the wrong shape leads the server to reject the call.

await session.call_tool("greet", {"name": "Ada"})

Read the Content

The result carries a content list of blocks. Most tools return text, so you read the text off the first block.

print(result.content[0].text)

Check for Errors

A tool that fails sets isError to true on the result instead of raising. Inspect it so your client can react gracefully.

if result.isError:
    print("tool failed")

Structured Output Too

Newer tools may also return structuredContent, a typed object alongside the text, when the server defines an output schema.

print(result.structuredContent)

Pass Real Arguments

Arguments come from your program, a user, or a model. The client simply forwards them as a plain dict to the named tool.

args = {"city": "Paris"}
await session.call_tool("weather", args)

It Is Still Async

Like every network call, call_tool is awaited. The await pauses until the server finishes the work and the result returns.

One Call, One Result

Each invocation is a request-response pair. The session matches the reply to your request by id, so results never get crossed.

Handle Slow Tools

Some tools take time. A robust client sets a timeout so a hung tool does not freeze your whole program.

You Are the Orchestrator

Calling tools from code means your program decides the order, combines results, and turns raw output into something useful for the user.

Quick Check

How do you run a discovered tool from client code?

Recap: Making the Call

You invoked tools end to end: call by name with valid arguments, read the content blocks, and check isError before trusting the output.

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

هل درس «استدعاء الأدوات من التعليمات البرمجية» مجاني؟

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