LLM Tool Calling and MCP (Model Context Protocol) Explained
How LLM function calling works, designing tool schemas, executing tools safely, and how the Model Context Protocol (MCP) connects agents to tools and data.
Tool calling (also called function calling) lets an LLM ask your application to run a function, such as searching an index, looking up an order or creating a ticket, and then use the result. The Model Context Protocol (MCP) is an open standard for exposing tools, data and prompts to AI applications through a common client-server protocol, so one integration works across many agents and hosts. This guide covers how tool calls flow, how to design tool schemas, how to execute them safely, and where MCP fits.
How a tool call works
Designing tool schemas
{
"name": "issue_refund",
"description": "Refund all or part of a paid order. Only for orders delivered in the last 30 days. Amounts above 100 USD require human approval and return status 'pending_approval'.",
"input_schema": {
"type": "object",
"required": ["order_id", "amount", "reason"],
"properties": {
"order_id": { "type": "string", "description": "Order id from get_order, e.g. '8812'" },
"amount": { "type": "number", "minimum": 0.01, "description": "USD, at most the order total" },
"reason": { "type": "string", "enum": ["damaged", "late", "wrong_item", "other"] }
}
}
}- Descriptions are prompts: say when to use the tool, when not to, and what the limits are. Most tool misuse is a vague description.
- Narrow tools beat generic ones:
get_orderandissue_refundare safer and easier to evaluate thancall_api(method, url, body). - Typed, constrained arguments: enums, minimums, formats. Validate them again in code.
- Useful errors: return structured errors the model can act on ("order not found", "refund window expired") instead of stack traces.
- Small results: return the fields the model needs, paginated, not entire database rows.
- Keep the tool count manageable: dozens of overlapping tools confuse models; group them, or load relevant tools per task.
Executing tools safely
| Concern | Control |
|---|---|
| Authorisation | Run every call as the end user, with their permissions, checked in code; the model's request is not proof of permission |
| Side effects | Idempotency keys on writes; confirm or approve irreversible actions |
| Injection through results | Treat tool output as untrusted data; it can contain instructions (see prompt injection) |
| Runaway usage | Rate limits and budgets per tool and per task |
| Code execution | Sandboxes with no network or secrets by default, CPU and time limits |
| Auditing | Log every call with arguments, caller, result and approval |
| Failures | Timeouts and retries for idempotent reads; surface errors to the model rather than hiding them |
Parallel tool calls (several independent lookups in one turn) cut latency; make sure your runtime executes them concurrently and returns all results together.
The Model Context Protocol (MCP)
Without a standard, every AI application writes its own integration for every system (N apps × M tools). MCP defines a common protocol: MCP servers expose capabilities from a system (a database, a ticketing tool, a file store), and MCP clients inside AI applications (hosts such as chat apps, IDEs or your own agent) connect to them.
| MCP concept | What it is |
|---|---|
| Tools | Functions the model can call, with JSON Schema inputs |
| Resources | Data the application can read into context (files, records) |
| Prompts | Reusable prompt templates a server offers |
| Transports | Local (standard input/output) for tools on the same machine; HTTP-based for remote servers |
| Discovery | Clients list a server's capabilities at connection time |
In a system design, MCP is an integration layer: it doesn't remove the need for authorisation, rate limiting, auditing or approvals. Remote MCP servers need authentication, per-user authorisation and the same least-privilege thinking as any API. Only connect servers you trust, since a malicious server's tool descriptions and results can carry injected instructions.
Function calling vs MCP vs plain APIs
| Function calling | MCP | Plain API calls in code | |
|---|---|---|---|
| Who decides to call | The model | The model (via the host) | Your code |
| Integration reuse | Per application | Across any MCP-capable host | Per application |
| Best for | A few app-specific tools | Many tools across many apps or teams | Fixed workflows |
Where it’s used
Narrow tools over order, billing and ticketing systems, with approvals on writes.
Teams publish MCP servers for their systems, so every assistant in the company can use them consistently.
Tools for reading files, searching code and running tests in a sandbox.
In an interview
- Show that the model only requests calls; your runtime validates and executes them.
- Design narrow, typed tools with descriptions that state limits.
- Authorise as the end user, add idempotency and approvals, and audit everything.
- Explain MCP as a standard integration layer that still needs auth and least privilege.
Frequently asked questions
How does LLM function calling work?
The model is given tool schemas and, instead of answering, emits a structured request naming a tool and its arguments. Your application validates and executes it, then returns the result to the model, which uses it to continue.
What is the Model Context Protocol (MCP)?
An open standard for connecting AI applications to tools and data. MCP servers expose tools, resources and prompts from a system, and MCP clients in host applications connect to them, so one integration works across many AI apps.
Further reading
- Model Context Protocol documentationModel Context Protocol
- Tool use with ClaudeAnthropic documentation