MCP Academy · Lesson

Invoke Tools from Code

Call a server tool and read its result.

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},
)

All lessons in this course

  1. Open a Client Session
  2. Discover Tools & Resources
  3. Invoke Tools from Code
  4. Route Tool Calls Through an LLM
← Back to MCP Academy