Function Calling & MCP

Master structured function calling and the Model Context Protocol for reliable tool use.

8 min read
2 quiz questions

Function calling lets you define tools as structured schemas (JSON) that the model can invoke with proper parameters. Instead of the model outputting text like "I'll search for X," it outputs a structured function call: {"name": "search", "arguments": {"query": "X"}}. This is vastly more reliable for building real applications.

Every major API supports function calling: OpenAI, Anthropic, Google, and others. You define your tools as JSON schemas, send them with the request, and the model decides when and how to call them. The key prompt engineering task is writing clear tool descriptions.

The model chooses which tool to call based primarily on tool descriptions. A vague description leads to incorrect tool selection. Each description should state what the tool does, when to use it, what each parameter means, and what it returns.

Bad tool description: name: "get_data" description: "Gets data" Good tool description: name: "search_products" description: "Search the product catalog by keyword. Use this when the user asks about product availability, pricing, or specifications. Returns top 10 matches with name, price, and stock status." parameters: query: "Search keywords (e.g., 'wireless headphones under $50')" category: "Optional product category to filter by (e.g., 'electronics')"

MCP is an open standard (developed by Anthropic) that standardizes how AI applications connect to external tools and data sources. Think of it as "USB-C for AI" — a universal plug that connects any AI model to any tool. Instead of building custom integrations for each tool, MCP provides a single protocol.

  • MCP Servers expose tools, resources, and prompts through a standard interface
  • MCP Clients (like Claude Desktop or IDEs) connect to servers and present tools to the model
  • Tools are auto-discovered — the model sees what's available and chooses what to use
  • Ecosystem: thousands of MCP servers already exist for databases, APIs, file systems, and more
When writing tool descriptions for function calling or MCP, include examples of when NOT to use the tool. This reduces misuse significantly — "Do NOT use this for general questions; only for order-specific lookups."

Prompt Templates

Tool Description Writer

Generates well-structured function calling tool definitions.

I need to create a function calling tool description for:
Tool name: [NAME]
What it does: [DESCRIPTION]
Parameters: [LIST PARAMS]

Write a JSON schema with:
- Clear description (when to use, when NOT to use, what it returns)
- Each parameter with type, description, and example
- Required vs optional parameters marked correctly

MCP Server Prompt

Designs the tool interface for a custom MCP server.

I want to build an MCP server that exposes [FUNCTIONALITY, e.g., "my company's CRM data"].

Design the tool interface: list each tool with its name, description, parameters, and return type. Group related operations logically. Include read-only and write operations separately.

Test Your Knowledge

Knowledge Check

1 / 2

Why is structured function calling more reliable than text-based tool use?

Key Takeaways

  • Structured function calling outputs reliable JSON instead of fragile text, enabling production-grade tool use
  • Tool descriptions are the most important factor in correct tool selection — be specific about what, when, and what parameters mean
  • MCP standardizes AI-tool connections with a universal protocol for tool discovery and execution