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
- Few, well-named tools with clear descriptions. The description is a prompt; write it for a smart newcomer.
- Strict schemas: enums over free text, required fields, sensible limits.
- Return useful errors the model can recover from ("no order A17; did you mean A71?").
- Idempotent where possible; separate read tools from write tools.
- Human approval for irreversible actions: payments, sending email, deleting data.
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()}// The same tool, executed server-side with the caller's identity.
public sealed record ToolResult(object? Data = null, string? Error = null);
public ToolResult RunTool(string name, JsonElement args, User user)
{
if (name != "get_order") return new(Error: $"unknown tool {name}");
var id = args.GetProperty("order_id").GetString();
var order = _orders.Find(id);
if (order is null || order.CustomerId != user.CustomerId) // authorise as the USER
return new(Error: "no such order for this customer");
return new(new { order.Id, order.Status, Eta = order.Eta.ToString("O") });
}Practice
Written for this site to drill the lesson. Not reported interview questions.
- Design the tool set for an assistant that helps employees book travel within policy. Which tools need human approval?
- A model keeps calling
searchwith the whole question as the query. How do you fix it without changing models? - 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
- Reference Model Context Protocol
- Official Anthropic Forward Deployed Engineer post