Usage
The#[mcp]
macro enables you to expose any HelixQL query as an MCP (Model Context Protocol) endpoint, making it directly accessible to AI agents and LLM applications.
You MUST only return a single object/value from the query otherwise you will get a compile error. (See E401)
Make sure to set
mcp = true
under the instance you are using in the helix.toml
file.How it works
When you add the#[mcp]
attribute to a query:
- HelixDB automatically registers the query as an MCP tool
- The query parameters become the tool’s input schema
- The query’s return type becomes the tool’s output schema
- AI agents can call this tool directly through the MCP server
The MCP macro automatically converts your HelixQL query into a callable MCP tool that can be used by LLM providers like OpenAI, Anthropic, and Gemini.
Using MCP Queries with LLM Providers
Once you’ve defined your MCP queries, you can use them with any LLM provider that supports MCP:Best Practices
Use descriptive query names
Use descriptive query names
Choose query names that clearly describe what the tool does. AI agents rely on function names to understand capabilities.
Keep query signatures simple
Keep query signatures simple
Use clear parameter types and avoid overly complex signatures. AI agents work best with straightforward interfaces.