TechPrep
Building blocksReadPracticeCheck

Tool use, function calling and MCP

Give the model typed tools, validate every call, and keep side effects behind permissions you would grant a junior engineer.

With tool use, the model returns a structured request ("call get_order with {"id": "A17"}"); your code runs it and returns the result for the next turn. The model never executes anything itself, which is what makes tools governable.

Designing good tools

Model Context Protocol (MCP)

MCP is an open protocol for exposing tools, resources and prompts to AI applications through a standard client-server interface, so one integration (an MCP server for your ticketing system, say) works across compatible clients. Anthropic's Forward Deployed Engineer posts list delivering "MCP servers, sub-agents and agent skills" to customers (official, Sources A8).

# A tool definition in the JSON-schema style most model APIs accept.
get_order_tool = {
    "name": "get_order",
    "description": "Look up one customer order by its id. Read-only.",
    "input_schema": {
        "type": "object",
        "properties": {"order_id": {"type": "string", "pattern": "^[A-Z][0-9]{2,8}$"}},
        "required": ["order_id"],
    },
}

def run_tool(name: str, args: dict, user) -> dict:
    if name != "get_order":
        return {"error": f"unknown tool {name}"}
    order = orders.find(args["order_id"])
    if order is None or order.customer_id != user.customer_id:   # authorise as the USER
        return {"error": "no such order for this customer"}
    return {"id": order.id, "status": order.status, "eta": order.eta.isoformat()}
Authorise every tool call as the end user, not as the service. A model that can be talked into calling a tool with someone else's id must still be refused by your code.

Practice

Written for this site to drill the lesson. Not reported interview questions.

  1. Design the tool set for an assistant that helps employees book travel within policy. Which tools need human approval?
  2. A model keeps calling search with the whole question as the query. How do you fix it without changing models?
  3. Sketch an MCP server for your team's deployment system. What would you expose as tools versus resources?

Check yourself

Who executes a tool call?

Your code; the model only requests it.

As whom must tool calls be authorised?

As the end user on whose behalf the model is acting.

Sources

Saved in this browser.