# Power BI Desktop MCP Server A Model Context Protocol (MCP) server that enables Claude to interact with Power BI Desktop through the XMLA endpoint using Analysis Services. ## Overview This MCP server allows Claude to: - Query Power BI data models and metadata - Execute DAX queries - Retrieve table schemas, columns, and relationships - Access measures and model information - All without leaving the Claude interface ## Features - **Model Discovery**: Get information about active Power BI models - **Schema Exploration**: Browse tables, columns, and their properties - **DAX Execution**: Run DAX queries directly against your Power BI model - **Measures**: Retrieve all measures with their expressions - **Relationships**: View model relationships and their properties - **Auto-Detection**: Automatically finds the Power BI Desktop XMLA port ## Prerequisites - **Windows OS** (Power BI Desktop is Windows-only) - **Power BI Desktop** installed and running with a report open - **Python 3.8+** - **pythonnet** package for .NET interoperability ## Installation ### 1. Clone or Download the Repository ```bash git clone cd Claude-Power-BI-Integration ``` ### 2. Create a Virtual Environment ```bash python -m venv venv ``` ### 3. Activate the Virtual Environment **Windows:** ```bash venv\Scripts\activate ``` **Linux/Mac:** ```bash source venv/bin/activate ``` ### 4. Install Dependencies ```bash pip install mcp pythonnet ``` ## Configuration ### Claude Desktop Configuration Add the following configuration to your Claude Desktop config file: **Location:** `%APPDATA%\Claude\claude_desktop_config.json` ```json { "mcpServers": { "powerbi": { "command": "C:\\Path\\To\\Your\\venv\\Scripts\\python.exe", "args": [ "C:\\Path\\To\\Your\\powerbi_mcp_server.py" ] } } } ``` **Example Configuration:** ```json { "mcpServers": { "powerbi": { "command": "D:\\Job Preparation\\Personnel Work\\Python - Technology\\VS Code Python Code\\Claude-Power BI-Intergration\\venv\\Scripts\\python.exe", "args": [ "D:\\Job Preparation\\Personnel Work\\Python - Technology\\VS Code Python Code\\Claude-Power BI-Intergration\\powerbi_mcp_server.py" ] } } } ``` **Important:** Replace the paths with your actual project paths. Use double backslashes (`\\`) or forward slashes (`/`) in JSON. ### Finding Your Paths 1. **Python executable path:** ```bash where python # Or if in virtual environment venv\Scripts\python.exe ``` 2. **Script path:** - Navigate to your project folder - Copy the full path to `powerbi_mcp_server.py` ## Usage ### 1. Start Power BI Desktop Ensure Power BI Desktop is running with a report/model open. ### 2. Restart Claude Desktop After updating the configuration, restart Claude Desktop to load the MCP server. ### 3. Verify Connection In Claude, you can ask: ``` "Can you connect to my Power BI model?" ``` Claude will use the MCP server to connect and retrieve model information. ## Available Tools The MCP server provides the following tools to Claude: | Tool | Description | |------|-------------| | `get_powerbi_models` | Get all Power BI models in the active report | | `get_model_tables` | List all tables in the model | | `get_table_columns` | Get columns from a specific table | | `execute_dax_query` | Execute DAX queries against the model | | `get_measures` | Retrieve all measures (optionally filtered by table) | | `get_relationships` | Get all relationships in the model | | `get_report_pages` | Get report pages (limited - requires COM) | | `get_page_visuals` | Get visuals from a page (limited - requires COM) | ## Example Queries Once configured, you can ask Claude: - "Show me all tables in my Power BI model" - "What columns are in the Sales table?" - "Execute this DAX query: EVALUATE TOPN(10, Sales)" - "What measures are defined in the model?" - "Show me the relationships between tables" - "Calculate total sales by year using DAX" ## How It Works 1. **Port Detection**: The server automatically finds the local Analysis Services port used by Power BI Desktop 2. **XMLA Connection**: Connects using the MSOLAP provider through OleDB 3. **DMV Queries**: Uses Dynamic Management Views (DMVs) to retrieve metadata 4. **DAX Execution**: Executes DAX queries and returns results to Claude ## Troubleshooting ### "Could not find Power BI Desktop Analysis Services port" **Solution:** - Ensure Power BI Desktop is running - Open a report/model in Power BI Desktop - The XMLA endpoint is only active when a model is loaded ### "pythonnet not installed" **Solution:** ```bash pip install pythonnet ``` ### MCP Server Not Showing in Claude **Solution:** - Verify the JSON configuration is valid (use a JSON validator) - Check that paths use double backslashes or forward slashes - Restart Claude Desktop completely - Check Claude Desktop logs: `%APPDATA%\Claude\logs` ### Connection Errors **Solution:** - Ensure you have the Microsoft OLE DB Provider for Analysis Services installed - This comes with Power BI Desktop but may need repair/reinstall - Try running Claude Desktop as Administrator ## Limitations - **Windows Only**: Power BI Desktop and XMLA endpoints are Windows-specific - **Local Only**: Connects only to local Power BI Desktop instances - **Report Pages/Visuals**: Limited access to report-level objects (requires Power BI COM interface) - **No Data Modification**: Read-only access to the model ## Technical Details ### Architecture ``` Claude Desktop ↓ MCP Server (Python) ↓ pythonnet → .NET OleDb ↓ MSOLAP Provider ↓ Power BI Desktop (XMLA Endpoint) ``` ### Security - All connections are local (localhost) - Uses Windows Integrated Security (SSPI) - No external network access required - No API keys or credentials needed ## Contributing Contributions are welcome! Please feel free to submit issues or pull requests. ## License [Add your license here] ## Resources - [Power BI XMLA Endpoint Documentation](https://learn.microsoft.com/en-us/power-bi/enterprise/service-premium-connect-tools) - [DAX Query Language](https://learn.microsoft.com/en-us/dax/) - [Model Context Protocol](https://modelcontextprotocol.io/) - [Analysis Services DMVs](https://learn.microsoft.com/en-us/analysis-services/instances/use-dynamic-management-views-dmvs) ## Support For issues or questions: 1. Check the Troubleshooting section 2. Review Power BI Desktop logs 3. Check Claude Desktop logs in `%APPDATA%\Claude\logs` 4. Open an issue on GitHub --- **Note:** This is a community project and is not officially supported by Microsoft or Anthropic.