From 6740cc56dacb9f31c899b84c20208088a41592c4 Mon Sep 17 00:00:00 2001 From: bobot-agent <258328579+bobot-agent@users.noreply.github.com> Date: Sun, 1 Nov 2026 20:43:14 +0100 Subject: [PATCH] docs(mcp): document get_function_definitions (DAX Lib MCP server 0.2.0) --- _mydocs/user-guide/mcp/index.md | 15 ++++++- _mydocs/user-guide/mcp/install.md | 8 ++-- _mydocs/user-guide/mcp/tools.md | 48 +++++++++++++++++++++-- _mydocs/user-guide/mcp/troubleshooting.md | 18 ++++++++- _mydocs/user-guide/mcp/use.md | 25 ++++++++++-- 5 files changed, 100 insertions(+), 14 deletions(-) diff --git a/_mydocs/user-guide/mcp/index.md b/_mydocs/user-guide/mcp/index.md index 70c11e5..f60ddc4 100644 --- a/_mydocs/user-guide/mcp/index.md +++ b/_mydocs/user-guide/mcp/index.md @@ -4,7 +4,7 @@ title: Use DAX Lib with AI Assistants (MCP) menu_title: AI Assistants (MCP) published: true date: 2026-10-11 -modified: 2026-10-11 +modified: 2026-11-01 order: /user-guide/03 next_reading: true --- @@ -21,6 +21,7 @@ With the DAX Lib MCP server, you can ask your assistant to: - Search the DAX Lib catalog for packages. - Show the details, versions, and README of a package. +- Get the functions of a package as a DAX query `DEFINE` block, to use them in a query without a change to the model. - List the Power BI Desktop models that are open on your computer. - Install the functions of a package into a model open in Power BI Desktop. @@ -39,6 +40,16 @@ The server does not change other model objects. The package code does not go thr > The server does not save your Power BI Desktop file. After the installation, save the file in Power BI Desktop to keep the changes. +## How query definitions work + +When you ask for the functions of a package for a DAX query, the server does these steps: + +1. It downloads the package from DAX Lib. +2. It finds the requested functions and the functions that they call. By default, it also adds the functions that they call in the dependency packages, at the versions that the package declares. +3. It returns the functions as a `DEFINE` block. Put the block before `EVALUATE` in your query. + +The server does not connect to a model and does not change a model. + ## You stay in control - You select the package and the version. The server instructs the assistant to let you choose and not to select a package automatically. @@ -48,7 +59,7 @@ The server does not change other model objects. The package code does not go thr ## Limits - The server runs only on Windows x64. There are no plans for a macOS version at this time. If you want a macOS version, [tell us in a GitHub issue](https://github.com/daxlib/daxlib-mcp/issues/new). -- You can install packages only into models open in Power BI Desktop on the same computer. +- You can install packages only into models open in Power BI Desktop on the same computer. A `DEFINE` block works in a DAX query on the Power BI service, Azure Analysis Services, and recent versions of Power BI Desktop. Refer to [`get_function_definitions`](tools.md#get_function_definitions). - The server does not remove or update installed functions. To update a package, install the new version. The server replaces functions with the same name. ## Pages in this section diff --git a/_mydocs/user-guide/mcp/install.md b/_mydocs/user-guide/mcp/install.md index 1e75125..07c17b0 100644 --- a/_mydocs/user-guide/mcp/install.md +++ b/_mydocs/user-guide/mcp/install.md @@ -4,7 +4,7 @@ title: Install the DAX Lib MCP Server menu_title: Install published: true date: 2026-10-11 -modified: 2026-10-11 +modified: 2026-11-01 order: /user-guide/mcp/01 next_reading: true --- @@ -15,7 +15,7 @@ next_reading: true |---|---| | Operating system | Windows x64. Other platforms (Linux, macOS, Windows ARM64) are not available. | | Node.js | Version 18 or higher. Node.js only starts the server. | -| Power BI Desktop | Necessary to install packages. The target model must have compatibility level 1702 or higher. | +| Power BI Desktop | Necessary to install packages. The target model must have compatibility level 1702 or higher. Not necessary to get a `DEFINE` block for a DAX query. | | MCP client | An AI assistant that supports local (stdio) MCP servers. | The server is a self-contained program. You do not need to install .NET. @@ -123,7 +123,7 @@ Use the `mcpServers` configuration above, or the equivalent format of your clien ## Use the standalone executable -You can use the server without Node.js. Each [release](https://github.com/daxlib/daxlib-mcp/releases) of the server has the executable in a zip file for Windows x64 (for example, `daxlib-mcp-0.1.0-win-x64.zip`). +You can use the server without Node.js. Each [release](https://github.com/daxlib/daxlib-mcp/releases) of the server has the executable in a zip file for Windows x64 (for example, `daxlib-mcp-0.2.0-win-x64.zip`). 1. Download the zip file from the [releases page](https://github.com/daxlib/daxlib-mcp/releases). 2. Extract the zip file to a folder. @@ -147,4 +147,4 @@ If you run the command without options, it shows an overview and a configuration ## Update the server -To use a specific version of the server, add the version to the package name in the configuration, for example `@daxlib/mcp@0.1.0`. Then restart your MCP client. +To use a specific version of the server, add the version to the package name in the configuration, for example `@daxlib/mcp@0.2.0`. Then restart your MCP client. diff --git a/_mydocs/user-guide/mcp/tools.md b/_mydocs/user-guide/mcp/tools.md index e53d0c9..92534da 100644 --- a/_mydocs/user-guide/mcp/tools.md +++ b/_mydocs/user-guide/mcp/tools.md @@ -4,18 +4,19 @@ title: DAX Lib MCP Tools Reference menu_title: Tools Reference published: true date: 2026-10-11 -modified: 2026-10-11 +modified: 2026-11-01 order: /user-guide/mcp/03 next_reading: true --- -The DAX Lib MCP server has five tools. Four tools only read data. The `install_package` tool changes a model. +The DAX Lib MCP server has six tools. Five tools only read data. The `install_package` tool changes a model. | Tool | Read only | Description | |---|---|---| | [`search_packages`](#search_packages) | Yes | Searches the DAX Lib catalog. | | [`get_package`](#get_package) | Yes | Gets the details of a package. | | [`get_package_readme`](#get_package_readme) | Yes | Gets the README of a package version. | +| [`get_function_definitions`](#get_function_definitions) | Yes | Gets the functions of a package as a DAX query `DEFINE` block. | | [`list_local_instances`](#list_local_instances) | Yes | Lists the Power BI Desktop instances on your computer. | | [`install_package`](#install_package) | No | Installs a package into a model open in Power BI Desktop. | @@ -34,7 +35,7 @@ The query is matched as one substring. If there are no results for a query with ## get_package -Gets the details of a package: id, version, description, authors, owners, tags, publication date, download count of the version, README availability, links (gallery, project, and repository), release notes, and all published versions (newest first). This tool does not return DAX code. +Gets the details of a package: id, version, description, authors, owners, tags, publication date, download count of the version, README availability, links (gallery, project, and repository), release notes, and all published versions (newest first). This tool does not return DAX code. To get the DAX code, use [`get_function_definitions`](#get_function_definitions). | Parameter | Type | Required | Default | Description | |---|---|---|---|---| @@ -52,6 +53,45 @@ Gets the README of a package version as a Markdown resource. The README comes fr If the package version has no README, the tool returns a message. +## get_function_definitions + +Gets the functions of a package as a DAX query `DEFINE` block. Put the block before `EVALUATE` to use the functions in that query only. The model does not change. This tool does not connect to Power BI and does not need Power BI Desktop. + +| Parameter | Type | Required | Default | Description | +|---|---|---|---|---| +| `id` | string | Yes | — | The exact package id, for example `DaxLib.SVG`. Not case-sensitive. | +| `version` | string | No | Latest version | The exact package version. If you do not specify it, the tool uses the latest published version, prerelease included. | +| `functions` | array of strings | No | All functions | The functions to return, for example `["DaxLib.SVG.Viz.Pill"]`. If you do not specify it, the tool returns all the functions of the package. An empty list is an error. | +| `includeDependencies` | string | No | `all` | The functions to add to the requested ones. `none`: only the requested functions. `package`: also the functions that they call in the same package. `all`: also the functions that they call in the packages that the manifest declares as dependencies, at the declared versions. | +| `includeDescriptions` | boolean | No | `true` | Writes the description of each function as `//` comments above the function. | + +The result has a short message and the `DEFINE` block as a text resource (`daxlib-define:////define.dax`). The result also has these data: + +| Field | Description | +|---|---| +| `complete` | `false` if a called function is not in the block. | +| `packages` | The packages in the block, with their exact versions, their role (`requested` or `dependency`), and their functions. | +| `functions` | The functions in the block, with their package, version, description, parameters, the functions that they call, and the reason (`requested` or `dependency`). | +| `warnings` | The problems that did not stop the tool. | +| `characters` | The length of the block. | + +These warnings set `complete` to `false`: `missingDependency`, `dependencyNotFound`, `dependencyVersionNotFound`, `versionConflict`, and `functionNotFound`. These warnings are for information only: `undeclaredDependency`, `unresolvedCall`, and `packageCycle`. + +If the tool cannot make a block, it returns an error with one of these codes in `data.code`: + +| Code | Cause | +|---|---| +| `unknownFunction` | A requested function is not in the package. The error shows up to 10 close names. | +| `tmdlParseFailed` | The package content is not valid. Do not try again. | +| `recursiveCall` | The functions call each other in a cycle. DAX does not allow recursion in user-defined functions. | +| `nameCollision` | The same function name is in more than one package. A `DEFINE` block cannot contain the same name two times. | + +Some notes about the block: + +- The block works in a DAX query on the Power BI service (also through the XMLA endpoint), on Azure Analysis Services, and on Power BI Desktop from September 2025 (preview) and June 2026 (general availability). There is no compatibility-level requirement. +- A function in the block replaces a model function with the same name, for that query only. +- Some functions published before a change of the DAX parser cannot run in a query, because a part of their name is now reserved (for example `DaxLib.SVG.Element.Group`). The tool returns these functions unchanged. The query error shows the part of the name. + ## list_local_instances Lists the Power BI Desktop instances that run on your computer. This tool has no parameters. @@ -88,4 +128,6 @@ The tool does these steps in sequence and stops at the first error: If the installation is successful, the result shows the model name and the number of functions that the tool added or replaced. The tool does not save the Power BI Desktop file. +If the package depends on a package that has no function in the model, the result has a `dependencyNotInstalled` warning. The functions that call the other package fail until you install it. The server tells the assistant to ask you if you want to install it. + For error messages, refer to [Troubleshoot the MCP server](troubleshooting.md). diff --git a/_mydocs/user-guide/mcp/troubleshooting.md b/_mydocs/user-guide/mcp/troubleshooting.md index 03eb99c..74b8863 100644 --- a/_mydocs/user-guide/mcp/troubleshooting.md +++ b/_mydocs/user-guide/mcp/troubleshooting.md @@ -4,7 +4,7 @@ title: Troubleshoot the DAX Lib MCP Server menu_title: Troubleshooting published: true date: 2026-10-11 -modified: 2026-10-11 +modified: 2026-11-01 order: /user-guide/mcp/04 next_reading: true --- @@ -60,6 +60,22 @@ To test the server outside the client, run `npx -y @daxlib/mcp --version` in a t | The instance hosts a number of databases different from one. | The model is not loaded. Open the target model in Power BI Desktop, then try again. | | The package could not be read. | The package content is not valid. Do not try again. Report the problem to the package author. | | The engine could not save the change. | Power BI Desktop rejected the change. Read the error message. Do not try again automatically. | +| The package depends on a package that is not installed in the model. | This is a warning. The installation is complete, but the functions that call the other package fail. Install the other package at the version shown in the message. | + +## Query definition errors + +These messages come from `get_function_definitions`. + +| Message | Cause and solution | +|---|---| +| A function is not in the package. | The function name is not correct. The message shows up to 10 close names. Use the exact name, or do not specify functions to get all the functions of the package. | +| `functions` must contain at least one function name. | The list of functions is empty. Specify one or more functions, or do not specify the list. | +| The package contains no functions. | The package version has no functions, so there is no `DEFINE` block. | +| The package could not be read. | The package content is not valid. Do not try again. Report the problem to the package author. | +| The functions call each other in a cycle. | DAX does not allow recursion in user-defined functions. The server does not make a block. | +| A function is in more than one package. | A `DEFINE` block cannot contain the same name two times. The server does not make a block. | +| The block is not complete. | A called function is not in the block. Read the warnings, for example a dependency package or version that is not available. | +| The DAX query fails on a part of a function name. | Some functions published before a change of the DAX parser cannot run in a query, because a part of their name is now reserved. The server returns these functions unchanged. The query error shows the part of the name. | ## Raise the compatibility level diff --git a/_mydocs/user-guide/mcp/use.md b/_mydocs/user-guide/mcp/use.md index 617afa4..c285d56 100644 --- a/_mydocs/user-guide/mcp/use.md +++ b/_mydocs/user-guide/mcp/use.md @@ -4,14 +4,14 @@ title: Use the DAX Lib MCP Server menu_title: Use published: true date: 2026-10-11 -modified: 2026-10-11 +modified: 2026-11-01 order: /user-guide/mcp/02 next_reading: true --- -Write your requests to the assistant in natural language. The assistant selects the applicable [MCP tool](tools.md). This page shows a typical workflow and example prompts. +Write your requests to the assistant in natural language. The assistant selects the applicable [MCP tool](tools.md). This page shows typical workflows and example prompts. -## Typical workflow +## Typical workflow: install a package 1. **Find a package.** If you do not know the exact package id, ask the assistant to search DAX Lib. 2. **Select a package.** The assistant shows the results. You select the package. @@ -21,6 +21,14 @@ Write your requests to the assistant in natural language. The assistant selects 6. **Install the package.** Approve the install request in your MCP client. 7. **Save your file.** Save the file in Power BI Desktop. The server does not save it. +## Typical workflow: use functions in a DAX query + +You can use the functions of a package in a DAX query without installing the package. The model does not change. + +1. **Find a package.** Ask the assistant to search DAX Lib, then select the package. +2. **Get the functions.** Ask for the functions that you need. The server returns a `DEFINE` block with these functions and the functions that they call. +3. **Write the query.** Put the `DEFINE` block before `EVALUATE`, then run the query. + ## Example prompts ### Search @@ -41,6 +49,13 @@ Write your requests to the assistant in natural language. The assistant selects - "Install DaxLib.SVG into the Sales Report model." - "Install version 2.0.0 of DaxLib.SVG into the model on localhost:51542." +### Get functions for a DAX query + +- "Give me the DEFINE block for DaxLib.SVG.Viz.Pill." +- "Get only DaxLib.SVG.Viz.Pill from DaxLib.SVG, without the functions it calls and without descriptions." +- "Get DaxLib.SVG.Viz.Pill and DaxLib.SVG.Viz.ProgressBar from DaxLib.SVG version 2.0.0. Tell me if the block is complete." +- "Write a DAX query that uses DaxLib.FormatString to format the sales amount by year. Do not install the package." + ### Use the functions After the installation, you can ask the assistant to help you use the functions. For example: @@ -50,6 +65,8 @@ After the installation, you can ask the assistant to help you use the functions. ## Things to know - **Versions.** If you do not specify a version, the server uses the latest published version. This version can be a prerelease. The assistant must tell you the version before it installs the package. To install a stable version, specify the version. -- **Replaced functions.** The installation replaces functions that have the same name. Other model objects do not change. +- **Replaced functions.** The installation replaces functions that have the same name. Other model objects do not change. A function in a `DEFINE` block replaces a model function with the same name only for that query. +- **Complete block.** If a called function is not in the `DEFINE` block, the result shows warnings and the block is not complete. Read the warnings before you run the query. +- **Reserved names.** Some functions published before a change of the DAX parser cannot run in a query, because a part of their name is now reserved. The query error shows the part of the name. - **Approval.** The server does not ask for confirmation itself. Your MCP client asks you to approve the install tool call. Read the tool arguments before you approve. - **Author content.** Package descriptions, release notes, and README files come from the package authors, not from DAX Lib. Examine them before you use the functions.