execute_malloy_query
Execute Malloy queries against models by providing a query string or specifying a source and named query, returning results including data styles and model definitions.
Instructions
Execute a Malloy query.
This tool connects to the Malloy Publisher API (default: http://localhost:4000/api/v0)
and executes a Malloy query against a model.
Args:
project_name: The name of the project, defaults to "home"
package_name: The name of the package containing the model
model_path: The path to the model within the package
query: The Malloy query string to execute (mutually exclusive with query_name)
source_name: Name of the source in the model (required when using query_name)
query_name: Name of a query to execute on a source
(mutually exclusive with query)
version_id: Version ID of the package
Returns:
Any: Query execution result with structure:
{
"data_styles": Object containing style information
"model_def": Object containing model definition
"query_result": Array of result objects
}
Raises:
MalloyError: If query execution fails or parameters are invalid
Error codes:
- QUERY_EXECUTION_ERROR: Error during query execution
- CONNECTION_ERROR: Error connecting to Malloy Publisher API
Example:
```python
# Example 1: Direct query
result = await execute_malloy_query(
project_name="home",
package_name="sales",
model_path="sales.malloy",
query="query: orders -> { aggregate: count() }"
)
# Example 2: Named query
result = await execute_malloy_query(
project_name="home",
package_name="sales",
model_path="sales.malloy",
source_name="orders",
query_name="top_customers"
)
```
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_name | No | home | |
| package_name | No | ||
| model_path | No | ||
| query | No | ||
| source_name | No | ||
| query_name | No | ||
| version_id | No |