MCP Fundamentals

LLM Tool Calling Explained: How It Works

By Antoine van der Lee·

When an AI agent deletes the wrong records because it was handed a malicious document — that is an LLM tool calling failure. LLM tool calling is the mechanism that lets a model request external actions; it is also the mechanism that turns a compromised prompt into a real-world incident.

Understanding the full call lifecycle — and where the risk concentrates — is prerequisite work before deploying any agentic AI in an enterprise environment.


What Is LLM Tool Calling?

Tool calling (also called function calling) is a structured mechanism that lets a language model request that an external function be executed on its behalf. The model does not run the function itself. It outputs a structured description of which function to call and what arguments to pass. The surrounding runtime intercepts that output, runs the actual function, and feeds the result back into the model's context.

The model acts as a reasoning layer that delegates execution to external systems — it never directly touches a database, API, or shell. That separation is intentional, and it is where most security risk concentrates.


The Per-Vendor Era: Why Fragmentation Was Expensive

Tool calling was not always standardized. OpenAI introduced function calling in mid-2023, followed quickly by incompatible implementations from Anthropic, Google, Mistral, Cohere, and others. Each vendor defined its own JSON schema for declaring tools, its own message format for returning results, and its own conventions for multi-step tool use.

An application wired to one provider's format could not move to another without rewriting the integration layer. Middleware emerged to paper over the gaps, but it added latency, cost, and a new single point of failure. Meanwhile, the number of tools an agent needed kept growing — each one a new bespoke integration, often duplicating work another team had already done.


MCP: A Shared Protocol Layer

The Model Context Protocol, introduced by Anthropic in late 2024 and now backed by a cross-vendor working group, defines a single open standard for how models discover and invoke tools. Instead of each application negotiating a private contract with a model provider, MCP separates three concerns:

  • MCP Servers expose tools — functions, data sources, actions — over a standardized interface.
  • MCP Clients (model runtimes, agent frameworks) discover and call those tools using a common protocol.
  • Hosts (the applications users interact with) orchestrate both sides.

An MCP server written for a ticketing system works with any MCP-compatible model client — Claude, GPT-4o, or an open-weight model running on-premises. The integration is written once. For platform teams managing dozens of internal tools, that is the difference between a compounding maintenance burden and a reusable internal service.

Compare this with traditional API integration approaches to see where the boundaries lie.


How a Tool Call Works End to End

The lifecycle of a single tool call moves through five stages:

1. Tool declaration. Before inference begins, available tools are described to the model — names, descriptions, and input schemas. Descriptions are critical: the model uses them to decide when and whether to invoke a tool. Vague descriptions produce unpredictable call behavior.

2. Model decision. During generation, the model determines it needs external information or an action. Rather than hallucinating an answer, it emits a structured tool-call object.

3. Runtime intercept. The application runtime detects the tool-call output and pauses generation. It extracts the function name and arguments.

4. Execution and result injection. The runtime calls the actual function — an API, a database query, a shell command — and injects the result back into the model's context as a new message.

5. Continued generation. The model resumes, now reasoning over the real result.

A minimal illustration of the model's structured output at step 2:

{
  "tool": "get_customer_record",
  "arguments": { "customer_id": "acct_8821" }
}

The model never touches the database. The runtime does. Steps 3 and 4 are where authorization, validation, and audit controls must sit.


Reliability Failure Modes

Tool calling introduces failure modes that pure text generation does not have.

Hallucinated tool calls. A model may invoke a function that does not exist, or pass arguments with the wrong shape. Strong input validation at the runtime layer is non-negotiable — downstream systems should never receive unvalidated model output as direct arguments.

Cascading failures. In multi-step agentic workflows, one failed tool call can corrupt the model's context for every subsequent step. Retry logic, timeouts, and circuit breakers belong at the runtime level, not inside individual tools.

Context window pressure. Injecting tool results back into context is cheap for a single call. In long agent loops with large result payloads, context windows fill quickly — degrading reasoning quality on later steps. Teams that skip result truncation strategies discover this in production, not in testing.

Latency compounds. Each tool call is a round trip. Sequential calls serialize; parallel execution requires explicit orchestration logic that most early implementations omit.


Security Failure Modes

The execution gap between model output and tool invocation is the largest attack surface in agentic AI.

Prompt injection is the primary threat. Malicious content in data the model reads — an email, a document, a web page — can be crafted to trigger unauthorized tool calls. The model cannot reliably distinguish instructions from content. See prompt injection in MCP environments for defense patterns specific to tool-calling architectures.

Overprivileged tools amplify blast radius. If a tool available to the model can delete records, send email, or modify access controls, a successful injection can do real damage. Least-privilege tool scoping is as important as least-privilege IAM — and AI agent access control covers how to enforce it.

Tool result poisoning is underappreciated. If an attacker controls the data source a tool reads from, they can inject instructions into the result payload that the model then acts on in subsequent steps.

The MCP security guide for enterprise teams covers the full threat model across all three vectors.


Practical Guidance for Platform Teams

For teams moving from ad-hoc function calling to a governed tool layer, three principles reduce both risk and maintenance cost:

  • Treat MCP servers as microservices. They need versioning, authentication, rate limiting, and audit logs — the same operational requirements as any internal API. MCP best practices covers the operational checklist.
  • Enforce tool scoping at the registry level. Not every agent should see every tool. Access control belongs in the layer that brokers tool discovery, not inside individual tool implementations. A centralized MCP server registry makes this tractable.
  • Audit tool call logs alongside model outputs. The tool call record — what was called, with what arguments, what was returned — is as important as the model's final response for compliance and incident investigation. AI agent audit logs explains what to capture and retain.

Frequently Asked Questions

Is MCP the same as OpenAI's function calling?

No. OpenAI function calling is a proprietary, provider-specific feature. MCP is an open protocol designed to be model- and vendor-neutral. The two serve the same conceptual purpose, but MCP adds a standardized transport layer, tool discovery, and portability across providers — so an integration built once works across any compliant runtime.

Can existing function-calling integrations be migrated to MCP?

Yes, with moderate effort. The core logic of each tool typically remains unchanged. What changes is the wrapper: instead of a provider-specific schema, the tool is exposed through an MCP server that handles protocol-level concerns. Several open-source adapter libraries handle common cases.

How does MCP handle authentication between the model runtime and tool servers?

MCP defines the protocol, not the authentication mechanism. In practice, MCP servers are secured the same way internal APIs are — mTLS, API keys, OAuth tokens, or service accounts — depending on the deployment environment. MCP authentication and OAuth patterns details the options. Centralizing auth through a control plane is strongly recommended over per-server configuration.

MCP Beast

Tool-calling governance is only tractable if there is a single place to define which agents access which tools, under what conditions, and with a full audit trail. MCP Beast provides that control plane: a centralized MCP gateway and policy engine that enforces scoping and logs every call — without touching individual MCP server implementations.

Explore MCP Beast to see how enterprise teams govern tool access at scale.


Related: