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.
README
Power BI Desktop Local MCP Server
A Model Context Protocol (MCP) server that enables AI assistants (such as Claude Desktop, Cursor, Cline, 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.
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
AppDatadirectories 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 leveragespythonnetto directly load the nativeMicrosoft.PowerBI.AdomdClient.dllshipped 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/PYTHONHOMEenvironment variables and prioritizing the local.venvdirectory to prevent runtime dependency import issues (e.g.,pywintypesorpythonnetcollision).
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-levelFastMCPframework.requirements.txt: Python package dependencies.create_dashboard.py: A companion script demonstrating how to run DAX queries, aggregate data inpandas, and generate a premium web-based dashboard withPlotly.
Prerequisites
- Operating System: Windows (required to run Power BI Desktop and load the native Windows .NET Assemblies).
- Python: Version 3.10 or higher.
- Power BI Desktop: Installed standard edition (
C:\Program Files\Microsoft Power BI Desktop) or Microsoft Store edition.
Installation & Setup
1. Environment Setup
Navigate to the project directory, initialize a virtual environment, and install dependencies:
# Create virtual environment
python -m venv .venv
# Activate virtual environment
.\.venv\Scripts\Activate.ps1
# Install requirements
pip install -r requirements.txt
2. Standalone Execution
With an active Power BI Desktop file open, you can test the MCP server locally in your terminal:
fastmcp run server.py
MCP Client Registration
To use this server inside your AI editor or chat client (e.g., Cursor, Cline, or Claude Desktop), register the server in your MCP configuration file.
Configuration Configuration (mcp_config.json or claude_desktop_config.json)
Append the following block to your mcpServers object (ensure you replace paths with the absolute path of your workspace):
{
"mcpServers": {
"powerbi-local": {
"command": "C:\\Path\\To\\Your\\powerbi-mcp\\.venv\\Scripts\\python.exe",
"args": [
"C:\\Path\\To\\Your\\powerbi-mcp\\server.py"
]
}
}
}
MCP Tools Reference
The server exposes the following tools:
-
list_instances- Description: Detects and returns active local Power BI Desktop instances on the current machine.
- Returns: List of objects containing the active local port and temporary directory path.
-
get_schema- Parameters:
port(string) - Description: Connects to the local port and returns the semantic model table/column structure.
- Parameters:
-
execute_dax- Parameters:
port(string),query(string) - Description: Executes a custom DAX query (e.g.,
EVALUATE 'Table') and returns rows formatted as JSON.
- Parameters:
-
add_measure_to_tmdl- Parameters:
tmdl_path(string),name(string),expression(string),format_string(string, optional) - Description: Appends a DAX measure directly to a local table's
.tmdlfile on disk. This guarantees the measure is permanently saved in the Power BI Project (PBIP) metadata instead of only living in the temporary active memory session. It automatically handles double-quoting the format string to prevent syntax errors.
- Parameters:
Best Practices & Troubleshooting (PBIP / TMDL / PBIR)
During manual or agent-based programmatic editing of Power BI Projects, follow these strict development rules to avoid report corruption and application load crashes:
1. TMDL formatString Quoting Rules
In Tabular Model Definition Language (TMDL) files, any formatString property containing special characters, symbols, operators, or spacing (such as $, %, ;, +, or spaces) must be enclosed in double quotes.
- Incorrect:
formatString: $#,##0(causes Power BI Desktop crash on load) - Correct:
formatString: "$#,##0"orformatString: "+0.0%;-0.0%" - Note: The
add_measure_to_tmdltool handles this automatically.
2. Guarding Against Duplicate Measures
Before appending DAX measures to a .tmdl file, verify if the measure is already defined (e.g. at the beginning of the file from a prior .pbix export). Defining a measure twice will trigger a fatal TMDL compilation error: "No se pueden combinar objetos TMDL porque ambos declaran la misma propiedad: expression".
3. Git Integration and Root Path Permission Error
Power BI Desktop automatically detects Git repositories up the directory tree to configure its project settings. If a .git folder accidentally exists in the root drive (e.g., C:\.git), Power BI will attempt to write a .gitignore file at C:\.gitignore. Because non-admin users cannot write to the root of C:\, saving the project will crash with: Acceso denegado a la ruta de acceso 'C:\.gitignore'.
- Fix: Delete the accidental root-level
C:\.gitfolder.
4. Valid PBIR visualType Identifiers
When injecting custom visual layouts inside .Report\definition\pages\[page]\visuals\[visual]\visual.json, only use official Power BI built-in visualType names. Using invalid names causes the entire report to fail to load on startup:
- Invalid:
columnClusteredChart,columnStackedChart - Valid standard chart types:
"columnChart"(handles both clustered column and stacked column layouts)"barChart"(handles both clustered bar and stacked bar layouts)"lineChart","pieChart","donutChart","treemap","card","matrix","table","waterfallChart","areaChart","scatterChart"
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。