Skip to main content
Glama
README.md
# powerbi-mcp

Local Power BI MCP server — no tenant, no workspace, no admin.

Two things it does:

- **Read `.pbix` files without opening them** (via
  [pbixray](https://pypi.org/project/pbixray/)): tables, columns, measures,
  relationships, Power Query and decoded rows. Works on `.pbix`, Analysis
  Services `.abf` and PowerPivot `.xlsx`.
- **Generate `.pbip` projects** (the TMDL text format Power BI Desktop saves
  itself): build a semantic model from CSV or Excel files, add DAX measures
  and relationships, lay out report pages, then open the `.pbip` in Power BI
  Desktop and refresh.

Built for course-scale work: an instructor (or an AI agent) can hand out
ready-made models and inspect submitted files, with no Power BI Service
access at all. Everything runs locally; the server never touches the
network beyond its own loopback port.

## Quickstart

```powershell
git clone https://github.com/veenetul/powerbi-mcp.git
cd powerbi-mcp
uv sync
uv run demo_local.py    # end-to-end: CSV star schema -> validated .pbip
```

Open the result (`exports/CourseDemo/CourseDemo.pbip`) in Power BI Desktop
(File > Open report > Browse reports), press **Refresh**, and the data loads.

## Tools (20)

| Tool | What it does |
| --- | --- |
| `pbix_overview` | model size, tables, rough row counts, object counts |
| `pbix_schema` | all columns with data types |
| `pbix_measures` | all DAX measures with expressions |
| `pbix_relationships` | all relationships (from/to, cardinality, active) |
| `pbix_power_query` | all M expressions |
| `pbix_table_data` | decoded rows of one table (max 500/call) |
| `create_pbip_project` | new project skeleton (`<name>.pbip` + report + model) |
| `add_csv_table` | new table loaded from a CSV, types inferred |
| `list_excel_sheets` | sheets of an .xlsx: rows, columns, headers |
| `add_excel_table` | new table loaded from one .xlsx sheet, types from Excel |
| `add_measure` | DAX measure with optional format string |
| `add_relationship` | relate tables (many side → one side) |
| `add_date_table` | calculated calendar table over a date column, marked as date table |
| `add_page` | add a report page, returns page id |
| `add_visual` | add a visual (card, slicer, donutChart, filledMap, stackedBarChart, …) with fields + pixel position |
| `list_report` | pages and visuals of a project |
| `remove_visual` / `remove_page` | delete a visual / page |
| `get_pbip_summary` | tables/columns/measures/relationships of a project |
| `validate_pbip` | structural checks; catches what would stop Desktop opening |

List them all without a client: `uv run list_tools.py`.

## Run the server

```powershell
uv run powerbi-mcp      # stdio (what MCP clients spawn)
uv run powerbi-mcp-http # streamable HTTP on http://127.0.0.1:8003/mcp
```

### Connect from an editor/agent

- **VS Code**: `.vscode/mcp.json` →
  `{"servers": {"powerbi": {"type": "stdio", "command": "uv", "args": ["run", "powerbi-mcp", "--directory", "<repo>"]}}}`,
  then use the tools in Copilot agent mode.
- **Vibe / Claude-style clients**: register with stdio transport, command
  `uv run powerbi-mcp` in the repo folder, or point a streamable-HTTP client
  at `http://127.0.0.1:8003/mcp`.

## Sandbox

All file reads and writes are restricted to allowed roots (semicolon-separated):

- `MCP_POWERBI_ALLOWED_READ_ROOTS` — default: the working directory
- `MCP_POWERBI_ALLOWED_WRITE_ROOTS` — default: the working directory

Set both explicitly when you want the server confined to one data folder.

## Layout produced

```text
<name>/
├── <name>.pbip
├── .gitignore
├── <name>.Report/
│   ├── .platform
│   ├── definition.pbir
│   └── definition/
│       ├── report.json
│       ├── version.json
│       └── pages/pages.json + pages/<id>/page.json
└── <name>.SemanticModel/
    ├── .platform
    ├── .pbi/editorSettings.json
    ├── definition.pbism
    └── definition/
        ├── database.tmdl
        ├── model.tmdl
        ├── relationships.tmdl
        └── tables/<Table>.tmdl
```

## Typical workflow

1. Put source data (CSV or .xlsx) somewhere the sandbox allows.
   `list_excel_sheets` shows what is inside an .xlsx.
2. Ask an MCP client: "create a Power BI project called X, add the orders
   sheet as table Orders, sellers as Sellers, relate them, add a Total
   measure, add a card showing Total".
3. `validate_pbip` passes.
4. Open `<X>/<X>.pbip` in Power BI Desktop, press **Refresh**, build visuals.
5. Save As `.pbix` if that is the deliverable; afterwards `pbix_overview` /
   `pbix_relationships` can read the saved file back to verify it.

### Updating a project

- **Incremental**: call the MCP tools (`add_measure`, `add_visual`, …) or edit
  the TMDL/JSON files in VS Code while Desktop has the project open — Desktop
  shows an "Apply external changes" banner; click Apply. Run `validate_pbip`
  after structural changes.
- **Full rebuild**: close Power BI Desktop first (it locks the folder), then
  rerun the script that generated the project.

## Notes

- The CSV path is baked into each table's M partition. Move the CSV and you
  must fix the partition.
- `pbix_measures` returns whatever the file's metadata database contains;
  some older or odd files store no measures there.
- Visual fields are DAX-style `Table[Field]`; positions are pixels on a
  1280x720 page.

## Requirements

Python 3.13 (`uv sync` downloads it if missing; pbixray ships wheels for
3.13), Power BI Desktop for the last mile (opening the `.pbip`). Works
offline; pbixray decodes the DataModel locally.

## License

MIT — see [LICENSE](LICENSE).

TDQS

B3.1/5.0

Scored across 20 tools

Disambiguation4/5

The set splits cleanly into .pbip authoring tools (add_*, remove_*, create_pbip_project, validate_pbip) and .pbix inspection tools (pbix_*), and descriptions make the file-format distinction explicit. The only mild overlaps are get_pbip_summary vs list_report vs pbix_overview, which are separated by target artifact, and add_date_table vs add_measure, which the description clarifies.

Naming Consistency4/5

Most tools follow a readable verb_noun snake_case pattern (add_measure, remove_page, list_report, validate_pbip). The pbix_* family uses a noun-first namespace prefix instead, and pbix_overview is a noun-style tool where others are verbs, but it functions as a coherent grouping convention rather than chaos.

Tool Count4/5

20 tools is slightly above the comfortable band, but the surface covers two genuinely distinct workflows (authoring .pbip projects and introspecting .pbix binaries), and each tool maps to a concrete operation. Very few tools look redundant or filler-ish, so the count is defensible.

Completeness3/5

Creation is well covered (project, tables, measures, relationships, date table, pages, visuals) plus validation and inspection, but the surface is add-heavy: there is no remove/update for measures, tables, or relationships, and no way to edit an existing visual. An agent that makes a modeling mistake has to fall back to manual file edits, which is a notable lifecycle gap.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues