---
title: "Use tool calling and MCP servers with LLMs"
description: "Enable LLMs to call functions and tools, then execute the results automatically."
url: "https://www.pixeltable.com/notebooks/llm-tool-calling"
updated: "2026-10-16"
---

# Use tool calling and MCP servers with LLMs

Enable LLMs to call functions and tools, then execute the results automatically.

- **Type:** Notebook
- **Group:** Agents

## How it works

You define tools with JSON schemas, pass them to the LLM, and use invoke_tools to execute the function calls.

## What it covers

- Define tools as Python functions
- Let LLMs decide which tool to call
- Automatically execute tool calls with invoke_tools
- Use MCP servers to load external tools

## What it uses

- **Install:** `pip install pixeltable openai mcp`
- **Environment variables it names:** `OPENAI_API_KEY`
- **Pixeltable calls:** `openai.chat_completions()`, `openai.invoke_tools()`, `@pxt.udf`, `pxt.tools()`, `pxt.create_table()`, `pxt.mcp_udfs()`, `add_computed_column()`, `insert()`

## A look at the code

```python
# Add LLM call with tools
queries.add_computed_column(
    response=openai.chat_completions(
        messages=[{'role': 'user', 'content': queries.query}],
        model='gpt-4o-mini',
        tools=tools,  # Pass tools to the LLM
    )
)
```

## Open it

- **Open in Colab:** https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/agents/llm-tool-calling.ipynb
- **Docs page:** https://docs.pixeltable.com/howto/cookbooks/agents/llm-tool-calling
- **Source on GitHub:** https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/agents/llm-tool-calling.ipynb
