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.

Intermediate 3 min read · Updated

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

UserApp / runtimeLLMOrder APIWhere is my order 8812?messages + tool schemastool_call: get_order(order_id=8812)validate args · check user owns orderGET /orders/8812{status: shipped, eta: Fri}tool_result"It shipped and arrives Friday."answer
A tool call round trip. The model never executes anything itself: it emits a structured request, your code validates and runs it, and the result goes back to the model.

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_order and issue_refund are safer and easier to evaluate than call_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

ConcernControl
AuthorisationRun every call as the end user, with their permissions, checked in code; the model's request is not proof of permission
Side effectsIdempotency keys on writes; confirm or approve irreversible actions
Injection through resultsTreat tool output as untrusted data; it can contain instructions (see prompt injection)
Runaway usageRate limits and budgets per tool and per task
Code executionSandboxes with no network or secrets by default, CPU and time limits
AuditingLog every call with arguments, caller, result and approval
FailuresTimeouts 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.

host applicationLLMMCP clientsMCP serverticketsMCP serverdatabaseMCP serverfilesTicketing systemPostgresDocument store
MCP architecture. A host application runs MCP clients that connect to MCP servers; each server wraps a system and exposes its tools, resources and prompts in a standard way.
MCP conceptWhat it is
ToolsFunctions the model can call, with JSON Schema inputs
ResourcesData the application can read into context (files, records)
PromptsReusable prompt templates a server offers
TransportsLocal (standard input/output) for tools on the same machine; HTTP-based for remote servers
DiscoveryClients 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 callingMCPPlain API calls in code
Who decides to callThe modelThe model (via the host)Your code
Integration reusePer applicationAcross any MCP-capable hostPer application
Best forA few app-specific toolsMany tools across many apps or teamsFixed workflows

Where it’s used

Support and operations agents

Narrow tools over order, billing and ticketing systems, with approvals on writes.

Internal AI platforms

Teams publish MCP servers for their systems, so every assistant in the company can use them consistently.

Coding agents

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