Problem
You want an LLM to decide which functions to call based on user queries—for agents, chatbots, or automated workflows.Solution
What’s in this recipe:- 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
invoke_tools to execute the function calls.
Setup
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘tools_demo’.
<pixeltable.catalog.dir.Dir at 0x30c46a550>
Define tools as UDFs
Create tool-calling pipeline
Created table ‘queries’.
Added 0 column values with 0 errors in 0.00 s
No rows affected.
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Run tool-enabled queries
Inserted 3 rows with 0 errors in 4.16 s (0.72 rows/s)
3 rows inserted.
Using MCP Servers as Tools
The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to LLMs. Pixeltable can connect to MCP servers and use their exposed tools as UDFs.Why MCP?
Create an MCP Server
First, create an MCP server with tools you want to expose. Save this asmcp_server.py:
python mcp_server.py (it will listen on
http://localhost:8000/mcp)
Connect to MCP Server and Use Tools
- SearchPixeltableDocumentation: Search across the Pixeltable Documentation knowledge base to find relevant information, code examples, API references, and guides. Use this tool when you need to answer questions about Pixeltable Documentation, find specific documentation, understand how features work, or locate implementation details. The search returns contextual content with titles and direct links to the documentation pages.
Created table ‘mcp_queries’.
Added 0 column values with 0 errors in 0.00 s
Added 0 column values with 0 errors in 0.01 s
Explanation
Tool calling flow:Query → LLM decides tool → invoke_tools executes → Results
Key components:
MCP integration:
MCP Server → pxt.mcp_udfs() → pxt.tools() → LLM tool calling
MCP servers expose tools via a standardized protocol. Pixeltable’s
mcp_udfs() connects to any MCP server and returns the tools as
callable UDFs that can be bundled with pxt.tools() for LLM use.
Supported providers:
See also
- Build a RAG pipeline - Retrieval-augmented generation
- Run local LLMs - Local model inference
- Multimodal MCP Servers - Pixeltable’s MCP server collection
- Custom Functions - More about UDFs and MCP integration