Tool calling, structured output, skills, and MCP

A model can only produce text. Tool calling turns that text into actions, and structured output makes it dependable. This guide explains how tool calls work, how to design tools, what agent skills and the Model Context Protocol add, and how to keep them safe.

Tools in 60 seconds

  • Tool calling: the model proposes a function call as structured data; your code decides whether to run it and returns the result.
  • Structured output: the model's answer must fit a schema, so other code can rely on it.
  • Agent skills: packaged instructions and resources that load only when a task needs them, which keeps the prompt small.
  • MCP (Model Context Protocol): an open protocol for connecting AI applications to tools and data, so one integration works across many applications.
  • The rule that matters most: the model proposes, your code disposes. Validate and authorise every call.

How a tool call works

The application sends the model the conversation plus a list of tool definitions: for each, a name, a plain-language description, and a schema for its arguments. When the model decides a tool is needed, it does not answer in prose. It returns a structured message that names a tool and fills in the arguments. The application checks that message, runs the real function, and sends the result back as another message. The model then either calls another tool or writes the final answer.

A tool definition: the description is part of the interface (illustrative) (json)
{
  "name": "get_order_status",
  "description": "Look up the status of one order by its ID. Read-only. Use when the customer asks where an order is.",
  "input_schema": {
    "type": "object",
    "properties": {
      "order_id": { "type": "string", "pattern": "^ORD-[0-9]{6}$", "description": "The order ID, for example ORD-123456." }
    },
    "required": ["order_id"],
    "additionalProperties": false
  }
}
The application side of tool calling (illustrative) (python)
# Illustrative: the model proposes; the application validates, authorises, and runs.
# llm.chat(), validate() and the tool functions are placeholders.

TOOLS = {'get_order_status': get_order_status}
READ_ONLY = {'get_order_status'}

def run_turn(messages, user, max_rounds=5):
    for _ in range(max_rounds):
        reply = llm.chat(messages, tools=TOOL_DEFINITIONS)
        if not reply.tool_calls:
            return reply.text                       # a final answer
        messages.append(reply.as_message())
        for call in reply.tool_calls:               # the model may request several at once
            result = execute(call, user)
            messages.append({'role': 'tool', 'tool_call_id': call.id, 'content': result})
    return 'I could not complete this request.'

def execute(call, user):
    tool = TOOLS.get(call.name)
    if tool is None or not validate(call.arguments, call.name):
        return 'Error: invalid tool call.'          # return errors as text so the model can recover
    if call.name not in READ_ONLY and not user.can(call.name):
        return 'Error: not permitted.'
    return str(tool(**call.arguments))

Designing good tools

The quality of an agent depends heavily on its tools, and a tool is an interface for a reader that has only the text you give it. The same discipline you would apply to a public API applies, with extra weight on clarity.

  • Name by intent. 'get_order_status' beats 'query'. A model picks tools mostly from names and descriptions.
  • Describe when to use it, and when not to. One or two plain sentences, including the difference from similar tools.
  • Keep arguments few and typed. Use enums, patterns, and ranges so wrong values are rejected before they run.
  • Return small, useful results. A huge result fills the context window. Return the fields that matter, with a clear error message when something fails.
  • Separate reads from writes. Give writes a distinct name and require confirmation.
  • Make writes idempotent. The model may retry a call. An idempotency key stops a retry from charging twice.
  • Keep the tool set small. Past a handful of tools, selection accuracy tends to fall. Group or load tools by task.

Structured output

When the output feeds other code, free text is a liability. Structured output asks the model to answer in a defined format, usually JSON that matches a schema. Providers and open-source engines offer modes that constrain generation so that the output is valid, and you can add your own validation as a second line of defence. Use structured output whenever the next step is a program, such as classification labels, extracted fields, or routing decisions.

Ask for a schema, validate it, retry once with the error (illustrative) (python)
# Illustrative: never trust the first parse. Validate, retry once, then fail safely.
import json

SCHEMA = {
    'type': 'object',
    'required': ['category', 'urgency'],
    'properties': {
        'category': {'enum': ['billing', 'technical', 'general']},
        'urgency': {'enum': ['low', 'normal', 'high']},
    },
    'additionalProperties': False,
}

def classify_ticket(text):
    prompt = f'Classify the ticket. Return JSON that matches this schema: {json.dumps(SCHEMA)}\n\nTicket: {text}'
    error = None
    for _ in range(2):
        raw = llm.generate(prompt if error is None else prompt + f'\n\nYour last reply was invalid: {error}')
        try:
            data = json.loads(raw)
            validate_schema(data, SCHEMA)  # placeholder for a JSON Schema validator
            return data
        except Exception as exc:
            error = str(exc)
    return {'category': 'general', 'urgency': 'normal'}  # safe default

Agent skills

As an agent gains capabilities, its prompt grows: instructions for each task, formatting rules, examples. Loading all of it into every call is expensive and distracts the model. A skill packages the instructions, example files, and helper scripts for one task, and the agent loads it only when the task matches. Think of a short index of skills, each with a one-line description, always visible, and the full instructions fetched on demand. This keeps the working context small while allowing a large library of capabilities.

A skill is a described, loadable bundle of instructions (illustrative) (markdown)
name: monthly-report
description: Build the monthly sales report from the finance export. Use when asked for the monthly or quarterly sales summary.

# Steps
1. Read the latest export from the finance folder.
2. Compute revenue by region and the change from last month.
3. Fill in the report template and list any region where revenue fell more than 10 percent.
4. Do not send the report. Return it for review.

The Model Context Protocol (MCP)

Without a standard, connecting N applications to M tools needs N times M custom integrations. The Model Context Protocol is an open protocol meant to turn that into N plus M: a tool or data source implements an MCP server once, and any application with an MCP client can use it. The application, called the host, runs one client per server. Messages are exchanged in JSON-RPC, over a local connection for servers on the same machine or over HTTP for remote ones.

One protocol between the application and many tools.

A server can offer three kinds of things. Tools are functions the model can call. Resources are data the application can read and add to the context, such as a file or a record. Prompts are reusable templates a user can choose. At the start the client asks the server what it offers, and the list becomes the tool definitions sent to the model.

What a tool call looks like on the wire (illustrative; check the current specification) (json)
{
  "jsonrpc": "2.0",
  "id": 7,
  "method": "tools/call",
  "params": {
    "name": "get_order_status",
    "arguments": { "order_id": "ORD-123456" }
  }
}

When MCP is worth it

  • Several applications need the same tools, such as a code editor, a chat assistant, and an internal agent that all use the ticket system.
  • You want third parties or other teams to plug in tools without changing your application.
  • You want a clear boundary where one team owns the tool and its permissions, and others consume it.

When MCP is overkill

  • One application with a few internal functions. Plain tool calling in your own code is simpler and faster.
  • Tight latency budgets, where an extra hop is costly.
  • Early prototypes, where the tool set changes daily.

The options compared

MechanismWhat it isBest forWatch for
Tool callingThe model requests a function; your code runs itAny application that needs live data or actionsUnvalidated arguments
Structured outputThe answer must match a schemaClassification, extraction, routingOver-trusting the first parse
Agent skillsOn-demand packaged instructionsLarge libraries of task instructionsVague descriptions that load the wrong skill
MCPA standard protocol between applications and toolsShared tools across applications and teamsUntrusted servers and extra hops

What this means for your role

Common mistakes

Further reading

Tools give a model hands. Define them narrowly, check every call, and give people the final say over anything that cannot be undone.

Search topics

↑↓ to move · Enter to open · Esc to close