Power BI Desktop Local MCP Server

Power BI Desktop Local MCP Server

Enables AI assistants to discover and interact with local Power BI Desktop instances, including inspecting table/column schema and executing DAX queries.

Category
访问服务器

README

Power BI Desktop Local MCP Server

A Model Context Protocol (MCP) server that enables AI assistants (such as Claude Desktop, Cursor, Cline, Hermes, and others) to securely and dynamically connect to locally running Power BI Desktop instances in Windows.

Through this server, an LLM can discover open reports, inspect table and column schema (metadata), and execute custom DAX queries to interact with your data or generate visualizations dynamically.


INSTALL THE MCP FOR YOUR AI AGENT WITH THIS PROMPT

Copy and paste this prompt when starting a new session with Cursor, Cline, Claude Desktop, or Hermes to have the agent configure the environment and understand the workflow automatically:

1. **Dependency Installation:** If the `.venv/` directory does not exist, initialize a Python virtual environment (`python -m venv .venv`), activate it, and install all dependencies declared in `requirements.txt`.
2. **Skill Registration:** Copy the `.agents/skills/powerbi-pbir-editor` customizations directory to your local global skills directory (e.g., in Hermes: `C:\Users\{User}\AppData\Local\hermes\skills\`).
3. **MCP Server Registration:** Register the `powerbi-local` MCP server in your global configuration file (e.g., in Hermes: `config.yaml`, in Cursor/Cline: `mcpjson.json`).
   - **CRITICAL:** Configure the command pointing to the Python executable of the local virtual environment (`.venv/Scripts/python.exe`) and the arguments pointing to the `launch.py` script of this repository. This prevents sys.path conflicts (PYTHONPATH pollution) when importing the `mcp` library.
4. **Understanding Your Capabilities (CRITICAL):** Do not assume you cannot create report pages or visuals programmatically just because the MCP tools don't have visual creation functions. You have full filesystem write access. You can and should create new pages and visuals by creating directories in the `.Report/definition/pages/` folder and writing `visual.json` files in their `visuals/` subfolders according to the `powerbi-pbir-editor` skill rules. Never tell the user you cannot create visuals; you can always write files.
5. **Next Steps (Request from Human):** Once the installation is complete, present the following next steps to the human to proceed:
   - "I have successfully installed and configured the Power BI MCP server and skills."
   - "Please open Power BI Desktop with your project."
   - "Provide me with the absolute path to your `.pbip` file and the name of the table you want to work with so I can start modeling and generating charts."

Key Features

  • Dynamic Port Discovery: Power BI Desktop spins up a local instance of SQL Server Analysis Services (SSAS) and assigns it a random port every session. This server automatically scans Windows AppData directories to identify active workspace sessions and resolve their local ports.
  • Robust Connection via ADOMD.NET: Instead of relying on local system OLE DB providers (MSOLAP) which often suffer from architecture mismatches (32-bit vs. 64-bit) or missing drivers, this server leverages pythonnet to directly load the native Microsoft.PowerBI.AdomdClient.dll shipped with Power BI Desktop.
  • Schema Inspection: Exposes database schema, detailing tables, columns, data types, and visibility states.
  • JSON-Safe DAX Execution: Executes complex DAX expressions (e.g., EVALUATE SUMMARIZECOLUMNS(...)) and parses raw .NET data types (decimals, dates, nulls) into clean, JSON-serializable structures.
  • Self-Sanitizing Environment: Automatically isolates its environment from host platforms (such as AI agent runners or global shells) by clearing contaminated PYTHONPATH/PYTHONHOME environment variables and prioritizing the local .venv directory to prevent runtime dependency import issues (e.g., pywintypes or pythonnet collision).

Project Structure

  • pbi_connector.py: Core database connector utilizing ADOMD.NET client libraries and local active port scanning.
  • server.py: Entry point for the MCP server built with the high-level FastMCP framework.
  • requirements.txt: Python package dependencies.
  • launch.py: Sanitizing wrapper to run the server without PYTHONPATH collision.

Prerequisites

  1. Operating System: Windows (required to run Power BI Desktop and load the native Windows .NET Assemblies).
  2. Python: Version 3.10 or higher.
  3. Power BI Desktop: Installed standard edition (C:\Program Files\Microsoft Power BI Desktop) or Microsoft Store edition.

Installation & Setup Step-by-Step

1. Clone & Set Up Workspace

Navigate to the directory and run:

# Create virtual environment
python -m venv .venv

# Activate virtual environment
.\.venv\Scripts\Activate.ps1

# Install requirements
pip install -r requirements.txt

2. Standalone Test

With Power BI Desktop open containing a loaded dataset:

fastmcp run server.py

3. Register MCP Server in client (Cursor, Cline, Claude Desktop, Hermes)

Add the following block to your MCP config file (e.g. C:\Users\{User}\AppData\Local\hermes\config.yaml or C:\Users\{User}\AppData\Roaming\Cursor\User\globalStorage\moe.etherelf.container\mcpjson.json):

# yaml format (Hermes config.yaml)
mcp_servers:
  powerbi-local:
    command: C:/Users/{User}/powerbi-mcp/.venv/Scripts/python.exe
    args:
      - C:/Users/{User}/powerbi-mcp/launch.py
    connect_timeout: 30
    timeout: 120
// json format (Cursor / Cline config)
{
  "mcpServers": {
    "powerbi-local": {
      "command": "C:\\Users\\{User}\\powerbi-mcp\\.venv\\Scripts\\python.exe",
      "args": [
        "C:\\Users\\{User}\\powerbi-mcp\\launch.py"
      ]
    }
  }
}

⚠️ GOLDEN RULES FOR HUMAN AND AI AGENTS (PBIR 2.0.0+ / TMDL)

When creating or modifying Power BI report pages or semantic models programmatically, you must follow these rules strictly. Failure to do so will result in empty visual placeholders, evaluation loops, or report loading crashes.

1. Folder Structure for Visuals (PBIR 2.0.0+)

In modern Power BI projects, visual files must not be placed directly in the page folder. They must be organized inside a visuals/ subfolder, where each visual is its own directory containing a visual.json file:

{project}.Report/
  definition/
    pages/
      {page-guid}/
        page.json
        visuals/
          {visual-name}/
            visual.json

2. Visual JSON Structure (visualContainer Schema)

Projections and fields must be structured directly under visual.query.queryState (never on the root of visual.json or directly under visual).

Example visual configuration (visual.json):

{
  "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/report/definition/visualContainer/2.5.0/schema.json",
  "name": "treemap-service",
  "position": { "x": 20, "y": 20, "z": 0, "width": 610, "height": 310, "tabOrder": 0 },
  "visual": {
    "visualType": "treemap",
    "query": {
      "queryState": {
        "Group": {
          "projections": [
            {
              "field": {
                "Column": {
                  "Expression": { "SourceRef": { "Entity": "comidasrapidas" } },
                  "Property": "nse"
                }
              },
              "queryRef": "comidasrapidas.nse",
              "nativeQueryRef": "nse"
            }
          ]
        },
        "Values": {
          "projections": [
            {
              "field": {
                "Measure": {
                  "Expression": { "SourceRef": { "Entity": "comidasrapidas" } },
                  "Property": "Promedio Servicio"
                }
              },
              "queryRef": "comidasrapidas.Promedio Servicio",
              "nativeQueryRef": "Promedio Servicio"
            }
          ]
        }
      }
    },
    "drillFilterOtherVisuals": true,
    "objects": {},
    "visualContainerObjects": {
      "title": [
        {
          "properties": {
            "show": { "expr": { "Literal": { "Value": "true" } } },
            "text": { "expr": { "Literal": { "Value": "'Service by NSE'" } } }
          }
        }
      ]
    }
  }
}

3. Column vs Measure Rule (CRITICAL)

  • Bar/Column/Line/Combo/Funnel/Pie/Donut Charts and Treemaps DO NOT accept direct columns ("Column") on their Y-axis/Values axis. Doing so will result in an empty visual showing the "Select or drag fields" warning.
  • Fix: You must first define a DAX measure in the table's .tmdl file (using the MCP tool add_measure_to_tmdl), and reference it as a "Measure" projection in the visual JSON.
  • Table Visuals (tableEx): Direct column references are allowed in table visual projections ("Values" channel).

4. Projection Keys by Chart Type

  • Bar, Column, Line, Combo, Funnel, Pie, Donut: Use "Category" (grouping) and "Y" (values/measure).
  • Treemaps: Use "Group" (grouping) and "Values" (measure/size).
  • Tables (tableEx): Use "Values" (array of column projections).

5. TMDL Model Rules (CRITICAL FOR CALCULATION GROUPS)

  • discourageImplicitMeasures Setting: If you create any Calculation Group (calculationGroup) in your model, you MUST add discourageImplicitMeasures: true under the model Model block in model.tmdl. If you omit this, Power BI Desktop will fail to load with a Frown crash indicating that implicit measures must be discouraged.
  • Avoid isKey Property on Dimensions: Never add isKey: true to primary key columns in standard import dimensions (like date or category dimensions). Setting isKey: true in TMDL can trigger a "cyclic reference was found during evaluation" error in Power Query. Keep the column definition simple and let the model-level relationships handle cardinality.
  • Double-Quoting Format Strings: If formatString contains spaces, currencies, or symbols, always enclose it in double quotes: formatString: "$#,##0" (Correct). Unquoted strings with symbols will crash Power BI.
  • Prevent duplicates: Scan the .tmdl file before inserting any measure to avoid compiling duplicate names.

6. Workflow & Cache Rules (CRITICAL)

  • Close Power BI Before Edits: You MUST run taskkill /IM PBIDesktop.exe /F BEFORE making any changes to .Report or .SemanticModel files (TMDL/PBIR). If Power BI Desktop is open, it holds the files in memory and will overwrite any local disk changes upon close or save.
  • Clear Schema Cache: If you perform a major schema refactoring (e.g. splitting a flat table into a Star Schema), you MUST delete the local database cache file .SemanticModel/.pbi/cache.abf. If you leave it, Power BI Desktop will load conflicting cached metadata and trigger cyclic evaluation or dependency loop errors.
  • Root Git Repositories: Ensure no .git folder exists in C:\ or D:\ roots. This causes Power BI's automatic Git integration to try to write a .gitignore to the root drive, triggering an access permission crash.
  • Valid JSON Keys: In visual.json, never write "size", "config", or "filters" on the root object. All dimensions must reside strictly inside "position".
  • Mandatory Keys: Every field projection must contain "queryRef" and "nativeQueryRef".
  • Page Folder Names: Page folders under pages/ must be named using 20-character lowercase hexadecimal strings or GUIDs. Do not use descriptive folder names.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选