AI Hints
Home›MCP Tutorial›Servers and Models
MCP · Lesson 56 of 120

MCP Tools for an LLM

Converting schemas.

⏱ 2 min read▶ Video at 49:45🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

A model needs tool definitions in its own format. Luckily, MCP tools already have a name, a description, and a JSON schema. That's almost exactly what models expect.

MCP Tools for an LLM
From the video: MCP Tools for an LLM
  • Models need definitions
  • MCP has them
  • Almost the same

Converting tool definitions

For each MCP tool, we build a dictionary with the name, description, and the input schema as parameters. Bind tools gives them to Gemini. We ask a question. Run it. The model asks to call order status, with the right argument.

convert.pypython
import asyncio
from mcp import Client
from langchain.chat_models import init_chat_model
from northwind import mcp

llm = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)

async def main():
    async with Client(mcp) as client:
        tools = [{"name": t.name, "description": t.description, "parameters": t.input_schema}
                 for t in (await client.list_tools()).tools]
    reply = llm.bind_tools(tools).invoke("Has order 1042 shipped?")
    print(reply.tool_calls[0]["name"], reply.tool_calls[0]["args"])

asyncio.run(main())
Output
order_status {'order_id': 1042}
Also uses northwind.py
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.exceptions import ToolError

mcp = MCPServer("northwind")
ORDERS = {1042: "shipped", 1043: "packing", 1044: "delivered"}

@mcp.tool()
def order_status(order_id: int) -> str:
    """Look up the status of a Northwind order by its number."""
    if order_id not in ORDERS:
        raise ToolError(f"Order {order_id} not found")
    return ORDERS[order_id]

@mcp.tool()
def delivery_cost(order_total: float) -> str:
    """UK delivery cost for an order total in pounds."""
    return "free" if order_total >= 50 else "£4.99"

@mcp.resource("policy://returns")
def returns_policy() -> str:
    """Northwind's returns policy."""
    return "You can return any unused item within 30 days of delivery."

@mcp.prompt()
def support_reply(question: str) -> str:
    """Draft a polite reply to a customer."""
    return f"Write a short, polite reply to this Northwind customer: {question}"

if __name__ == "__main__":
    mcp.run()

The mapping

MCP name becomes the function name. Description stays the description. Input schema becomes parameters. The model doesn't run the tool, it only asks for it. Our code makes the real call.

keyvalue
namename
descriptiondescription
input_schemaparameters
The callmade by our code

Summary

MCP tool definitions map straight onto model tool definitions. Next, the full agent loop.

Key takeaways
  • name
  • description
  • parameters
Next up: The Agent Loop — model, tool, model