CLI for Power BI semantic models - wraps the Power BI MCP server for token-efficient AI agent usage
Project description
pbi-cli
Token-efficient CLI for Power BI semantic models.
pbi-cli wraps Microsoft's Power BI MCP server so you can manage semantic models from the terminal. MCP tool schemas consume ~4,000+ tokens in an AI agent's context window; a pbi command uses ~30. One install, no separate MCP server configuration required.
pip install pbi-cli-tool
pbi setup
pbi connect --data-source localhost:54321
pbi measure list
Why pbi-cli?
| Approach | Context cost | Setup |
|---|---|---|
| Raw MCP server | ~4,000 tokens per tool schema | Manual config per project |
| pbi-cli | ~30 tokens per command | pip install pbi-cli-tool |
Designed for Claude Code and other AI agents, but works great for humans too. Use --json for machine-readable output or enjoy Rich-formatted tables by default.
Installation
pip install pbi-cli-tool
Prerequisites
- Python 3.10+
- Power BI Desktop (for local development) or a Fabric workspace
First-time setup
Download the Power BI MCP binary:
pbi setup
This downloads the official Microsoft binary from the VS Code Marketplace to ~/.pbi-cli/bin/. You can also point to an existing binary:
export PBI_MCP_BINARY=/path/to/powerbi-modeling-mcp
Quick Start
Connect to Power BI Desktop
# Connect to a local Power BI Desktop instance
pbi connect --data-source localhost:54321
# Connect to a Fabric workspace model
pbi connect-fabric --workspace "My Workspace" --model "Sales Model"
Run DAX queries
pbi dax execute "EVALUATE TOPN(10, Sales)"
pbi dax execute --file query.dax
cat query.dax | pbi dax execute -
Manage measures
pbi measure list
pbi measure create "Total Revenue" --expression "SUM(Sales[Revenue])" --table Sales
pbi measure get "Total Revenue" --table Sales
Export and import models
pbi database export-tmdl ./my-model/
pbi database import-tmdl ./my-model/
Command Reference
| Group | Description | Examples |
|---|---|---|
setup |
Download and manage the MCP binary | pbi setup, pbi setup --check |
connect |
Connect to Power BI via data source | pbi connect -d localhost:54321 |
connect-fabric |
Connect to Fabric workspace | pbi connect-fabric -w "WS" -m "Model" |
disconnect |
Disconnect from active connection | pbi disconnect |
connections |
Manage saved connections | pbi connections list |
dax |
Execute and validate DAX queries | pbi dax execute "EVALUATE Sales" |
measure |
CRUD for measures | pbi measure list, pbi measure create |
table |
CRUD for tables | pbi table list, pbi table get Sales |
column |
CRUD for columns | pbi column list --table Sales |
relationship |
Manage relationships | pbi relationship list |
model |
Model metadata and refresh | pbi model get, pbi model refresh |
database |
Import/export TMDL and TMSL | pbi database export-tmdl ./out/ |
security-role |
Row-level security roles | pbi security-role list |
calc-group |
Calculation groups and items | pbi calc-group list |
partition |
Table partitions | pbi partition list --table Sales |
perspective |
Model perspectives | pbi perspective list |
hierarchy |
User hierarchies | pbi hierarchy list --table Date |
expression |
Named expressions | pbi expression list |
calendar |
Calendar table management | pbi calendar list |
trace |
Diagnostic traces | pbi trace start |
transaction |
Explicit transactions | pbi transaction begin |
advanced |
Cultures, translations, functions | pbi advanced culture list |
repl |
Interactive REPL session | pbi repl |
Run pbi <command> --help for full option details.
REPL Mode
The interactive REPL keeps the MCP server process alive across commands, avoiding the 2-3 second startup cost on each invocation:
$ pbi repl
pbi-cli interactive mode. Type 'exit' or Ctrl+D to quit.
pbi> connect --data-source localhost:54321
Connected: localhost-54321 (localhost:54321)
pbi(localhost-54321)> measure list
...
pbi(localhost-54321)> dax execute "EVALUATE Sales"
...
pbi(localhost-54321)> exit
Goodbye.
Features:
- Persistent MCP server connection (no restart between commands)
- Command history (stored at
~/.pbi-cli/repl_history) - Tab completion for commands and subcommands
- Dynamic prompt showing active connection name
For AI Agents
Use --json before the subcommand for machine-readable JSON output:
pbi --json measure list
pbi --json dax execute "EVALUATE Sales"
pbi --json model get
JSON output goes to stdout. Status messages go to stderr. This makes piping and parsing straightforward.
Named connections
Use -c to target a specific named connection:
pbi -c my-conn measure list
pbi -c prod-model dax execute "EVALUATE Sales"
Configuration
pbi-cli stores its configuration in ~/.pbi-cli/:
~/.pbi-cli/
config.json # Binary version, path, args
connections.json # Named connections
repl_history # REPL command history
bin/
{version}/
powerbi-modeling-mcp[.exe]
Binary resolution order
PBI_MCP_BINARYenvironment variable (explicit override)~/.pbi-cli/bin/{version}/(managed bypbi setup)- VS Code extension fallback (
~/.vscode/extensions/analysis-services.powerbi-modeling-mcp-*/server/)
Development
git clone https://github.com/pbi-cli/pbi-cli.git
cd pbi-cli
pip install -e ".[dev]"
# Lint
ruff check src/ tests/
# Type check
mypy src/
# Test
pytest -m "not e2e"
Contributing
Contributions are welcome! Please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-change) - Make your changes with tests
- Run
ruff checkandmypybefore submitting - Open a pull request
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pbi_cli_tool-0.1.0.tar.gz.
File metadata
- Download URL: pbi_cli_tool-0.1.0.tar.gz
- Upload date:
- Size: 40.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
664b10f24456d7910d3ab29f46765239e5cc349afa50824cd8830855bac3fa49
|
|
| MD5 |
2fb8cbfa2830ceb7c7b17ae11abeadcc
|
|
| BLAKE2b-256 |
d3e3a1c6a1806f9c5afd3239e4eda95ce598ae8df869e5a2f05a3da5a543d440
|
File details
Details for the file pbi_cli_tool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pbi_cli_tool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 47.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acdaa19dc3a39cbadeb82272aa9b6c086681d239fe6e0685b2e271243f884644
|
|
| MD5 |
82e38bd42f6bef19af3923b5bf97e36f
|
|
| BLAKE2b-256 |
1a1144d5055f0a6b39d34de578bbcdcf65f19f6320adbf780f970d70594b65e7
|