Session 5 — Local tools and APIs
Goals
- Connect a local tool and a tool that calls a free service.
- Reject invalid input and a forbidden action before execution.
- Keep a log in which the request, the decision and the result are visible.
- Return a tool failure as a result the agent can read, instead of crashing.
Two tools
calculator takes an operation and two numbers. It does not take a string to run.
weather calls Open-Meteo for coordinates that appear in a closed list, for example Tel Aviv. A city that is not on the list is rejected without a network call. This is how you learn permission even when the service itself is free. Open-Meteo's terms of use apply to the call, and here it is meant for non-commercial practice.
MCP comes in here as a second way to expose the same calculator: tools/list returns the schema, tools/call runs it. The local server does not replace the permission check.
The order of the checks
Every call goes through the same order, and only the last stage touches the world:
- Schema: the required fields are there, and the types are right.
"1400"as text is rejected. - Permission: the action is allowed for this user and this value. A city outside the list stops here.
- Rule: the value meets the business rule, for example a price floor.
- Execution: only now do you write or go to the network.
Each stage returns its own status. invalid_request, forbidden and policy_rejected are three different answers, and the agent needs to know which one it got.
The playground above is the shop version from session 2. In lab 2 you add the call log and the weather service.
A log you can read
A log line holds the tool name, the arguments, the status, and what changed: how many writes, how many network calls. A line like this answers "what happened" without guessing from the text the model wrote afterwards.
weather {"city": "paris"} forbidden network_calls=0
weather {"city": "tel-aviv"} unavailable network_calls=0
A failure you return to the model
If Open-Meteo is unavailable, the result is a network error, not a made-up forecast. One more attempt is allowed. After it, you stop and report what is missing. A permission error does not get another attempt: a city outside the list will stay outside the list.
Run lab 2 without a network. Make sure an allowed city returns unavailable and not a temperature. Then add a third city to the list, and show in the log that a call for a city not on the list still records zero network calls.
Check your understanding
Summary
Found a mistake on this page? Email the lecturer