Skip to content
Carmel Eve By Carmel Eve Software Engineer II · 10 min read
Power BI Modeling MCP Server in VS Code: Dos and Don'ts

TLDR; The Power BI Modeling MCP server lets an AI assistant in VS Code query and change your semantic models directly. I've found it really useful, but it does get things wrong. So, think about what data it can see before you connect. And before you let it change anything, make sure you can prove what changed!

Hello! For the last few weeks I've been doing something a bit different with my Power BI work. Rather than clicking around Power BI Desktop and DAX Studio, I've been doing most of my semantic model work through an AI assistant in VS Code, connected to my models via the Power BI Modeling MCP server.

This post is aimed at Power BI developers who are curious about AI tooling, rather than AI people who are curious about Power BI, so I'll explain the AI bits as we go.

Overall, the results have been incredibly impressive. Over three weeks, across eight working sessions, the assistant ran around 500 DAX queries against real models for me. It helped me document models and write requirements, and it found and fixed real defects. On one report, it took a slow visual from 13.7 seconds down to 1.8 seconds. But it has also been confidently wrong more than once, and one deployment had to be rolled back. Along the way, 85 tool calls failed.

The best hour you can spend to refine your own data strategy and leverage the latest capabilities on Azure to accelerate your road map.

So, today I'm going to share what I've learnt, and what I found useful along the way. That covers everything from getting set up to working with the assistant day to day.

What is the Power BI Modeling MCP server?

MCP (Model Context Protocol) is a standard way of giving an AI assistant "tools": things it can actually do, rather than just talk about. The Power BI Modeling MCP server gives the assistant tools to:

  • Connect to a model that's open in Power BI Desktop, in a Fabric workspace, or saved as PBIP / TMDL files (we've written more about PBIP and TMDL in our modern development posts)
  • Read tables, columns, measures, relationships and RLS roles
  • Run DAX queries (including with execution metrics, and impersonating RLS roles)
  • Create and update measures, tables, relationships and more

Be careful with that last bullet. An assistant that can change your model in seconds is fantastic, as long as you can tell what it actually changed.

In practice, this means you can say "there's a report open in Desktop, why is this page so much slower than the others?" and the assistant will connect to the model and read the measure definitions. Then it writes and runs its own benchmark queries to find the answer. I started out using it with GitHub Copilot, and then moved to Claude Code in VS Code, but the MCP server is the same either way. (If you're weighing up which assistant to use, Mike's post, AI-assisted coding is four decisions, not one, is a good way to think about it.)

Claude Code in VS Code finding a local Power BI Desktop instance, connecting to it, and running a DAX query that returns sales by region.

Before it changes anything

The biggest lesson isn't really about the MCP server at all: before you let it change anything, make sure you can prove what changed. An assistant that's confidently wrong some of the time is fine, if you have something other than its word to check against. So, before I let the MCP server write anything to a model, I now put three things in place:

  1. Regression tests for every measure, recorded from the unchanged model
  2. A benchmark, with a labelled "before" run
  3. Expected values for the change, derived without using the new DAX

I'll go through how I did each of those in my next post, on testing AI changes to Power BI semantic models. It's the same idea as "track what changes" in James's post on how to trust your AI-assisted data analysis: if you can't say what changed, you can't explain why the results are different.

Getting set up

Install the server. In Claude Code, the server comes as part of the powerbi-authoring plugin, so I just installed the plugin. If you're using GitHub Copilot in VS Code, install the Power BI Authoring MCP extension. For other assistants, the README explains how to register the server.

Accept the EULA up front. When I first tried to connect, every single call failed with:

The Power BI Authoring MCP EULA must be accepted before using this tool.

You can accept it via a tool call, a command line flag, or an environment variable. I'd recommend the environment variable so you only do it once. On Windows:

setx PBI_MODELING_MCP_ACCEPT_EULA true

Then restart VS Code so it picks up the new variable. (I had to ask how to set an environment variable. We all have our blind spots, right?)

We help teams build Power BI reports and semantic models that people trust, understand and actually use. Explore our Power BI consulting services.

Keep the server up to date. The server is moving quickly. I went through eight versions of the server during these three weeks, and a few of the operations I was relying on behaved differently between them. If something odd happens, try updating first.

Set a sensible timeout. At one point a call to connect to a model in a Fabric workspace just... sat there. For 30 minutes. That matches Claude Code's default idle timeout for a local MCP server: how long it waits for any response before abandoning the call. Most MCP hosts let you set something shorter. In Claude Code, you can add a timeout (in milliseconds) to the server's entry in your MCP config. It's also worth knowing that for models in a Fabric workspace, the README recommends the remote (hosted) Power BI Authoring MCP server rather than the local one.

Connecting to models

Think about what data it can see. Every query the assistant runs sends its results back to the assistant, which means they go to the AI provider as part of the conversation. Reading measure definitions is one thing, but a query like "show me the top 20 customers by sales" puts real names and numbers in the chat. That was fine for me, because I was working against dev data. If your model holds anything sensitive (customer details, salaries, health data), check what your organisation allows before connecting, and consider working against a copy with anonymised or sample data instead. Microsoft's README now has a section on data privacy and LLM providers that's worth reading first.

The connection doesn't survive reopening Desktop. I saw "Connection is not open. Please reconnect" a lot. Every time Power BI Desktop opens a file, it starts its local Analysis Services engine on a new port, so the connection name changes too (you'll see names like PBIDesktop-My Model-54146). If you close and reopen Desktop, which I did a lot when switching between report versions, the assistant needs to reconnect. The fix is easy: tell it "I've reopened the report", and it will list the local instances and connect again.

On composite models, expect to sign in again. One of the reports I was working on is a composite model: a handful of local tables and measures, built on top of a shared semantic model through DirectQuery. Whenever the assistant ran a query that touched the remote model, it went through my sign-in in Power BI Desktop. When that expired, which happened quite a few times, queries failed with a fairly unhelpful "a connection could not be made to the data source" error. If you see that, sign in again in Desktop and tell the assistant to try again.

Say which model you mean. I often had two models open at once (for example, the shared model and the composite report built on it). The assistant will happily connect to whichever it finds first.

Querying

Test with the queries your visuals actually send

This is something that tripped me up. On the composite report, I deployed a change that had passed all the assistant's tests and benchmarks. Then a slicer on one of the pages broke, and I had to roll the change back. The error was:

The resultset of a query to external data source has exceeded the maximum allowed size of '1000000' rows.

After the change, a local measure referenced a remote measure that is never blank (it was essentially SELECTEDVALUE ( Selector[Value], 1 )). The slicer grouped by columns from three different dimension tables. Power BI's "auto-exist" only removes impossible combinations of columns from the same table. Across separate tables, it relies on the measures returning blank to know which combinations to drop. So the engine asked the remote model to evaluate that measure for every combination of the three (about 2.3 million of them), which is well over the DirectQuery limit.

The assistant's test queries had missed this because it had helpfully added a SUMMARIZE over the combinations that actually exist in the data. That's a perfectly sensible thing to do in a test query, but it's not what the visual does. So make your test queries ask for exactly what the report asks for, including every combination the visual groups by.

Diagram of a composite model. A slicer groups by columns from three tables, so a local measure calls a remote measure that never returns blank once for every combination: 1,200 × 160 × 12, or 2.3 million rows, which is over the 1,000,000-row DirectQuery limit.

Prototype a new measure in a query, and compare with ==

For performance work, the inner-dev-loop workflow that served me (and Claude!) best was:

  1. Prototype the new version of the measure inside a query using DEFINE MEASURE, so the model isn't touched
  2. Compare it against the existing measure, across every combination the report uses
  3. Benchmark both, with a cleared cache, a couple of times each
  4. Only then write it into the model, and run the regression tests and the benchmark
Microsoft Fabric Weekly is a summary of the week's top news to help you build on the Microsoft Fabric Platform.

The comparison query looks something like this:

DEFINE
    MEASURE 'Measures'[Sales YoY % NEW] =
        -- e.g. a rewritten version of [Sales YoY %]
        VAR PriorSales =
            CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
        RETURN
            DIVIDE ( [Total Sales] - PriorSales, PriorSales )
    MEASURE 'Measures'[YoY Differs] =
        IF ( NOT ( [Sales YoY %] == [Sales YoY % NEW] ), 1 )

EVALUATE
FILTER (
    SUMMARIZECOLUMNS (
        'Date'[Year],
        'Product'[Category],
        "Old", [Sales YoY %],
        "New", [Sales YoY % NEW],
        "Differs", [YoY Differs]
    ),
    [Differs] = 1
)

An empty result means the two versions agree. Notice the == rather than =. In DAX, BLANK() = 0 is TRUE, so a normal equality check will happily tell you that a measure returning blank matches one returning 0. (This isn't just a theoretical worry: we found a real defect where a filter, [value] <> BLANK(), meant to skip items with no data, was quietly skipping items with a value of 0 too. The fix was NOT ISBLANK ( [value] ).)

== is exact, though, so if a rewrite only differs in the 15th decimal place, round both sides to the same precision as your tests before comparing.

The MCP server's DAX tool can clear the cache and return execution metrics (storage engine vs formula engine time and so on), so the assistant can do the quick benchmarking for you as well. It can also run a query as a given RLS role, which was useful for questions like "can a user in this role see other regions' figures?" One gotcha: I found I couldn't do both in the same call, so I timed things as an admin and checked RLS separately. (If those terms are new, I've written about the formula engine and storage engine, and James has written about comparisons across the full dataset under RLS.)

Done this way, the performance work went really well: a typical visual went from 13.7 s to 1.8 s. I'll go through what fixed it in the next post.

Keep result sets small

Some of the assistant's early queries returned results that were several megabytes each. That's slow, and it fills up the assistant's working memory (its "context") very quickly. Ask it to aggregate, or to limit the rows it returns. It's much better at reasoning over a 20-row summary than a 50,000-row dump.

Making changes to the model

Back up first. Even with tests in place, save a copy of the .pbix or commit your PBIP files before any change session. I needed my backups more than once, including the time we had to undo a whole feature, while keeping the real defect fixes we'd made along the way. (Generally, we back up our PBIX files in SharePoint, which gives us version control and the ability to restore older versions! I've written about how we use SharePoint to manage Power BI report versions if you want to set this up yourself.)

Expect some failed transactions. Batch updates are done in a transaction, so if something fails, nothing is saved. I hit "Transaction commit failed... no changes were saved to the server" several times. Usually this was because calculated tables in the model needed recalculating before the change could be applied. Those recalculations can also take a long time on a big model, long enough that the assistant's background commands timed out. If you have heavy calculated tables, it's worth recalculating them one at a time and timing each one.

Working with the assistant

Bake in understanding of the business. The assistant is very good at reading DAX. It's much worse at knowing why the DAX is like that. On one report, it kept misdescribing a deliberate design choice, because the reason for it lived in people's heads rather than in the DAX, and I had to correct it twice. Most assistants have some way of remembering things between sessions: an instructions file (such as Copilot instructions or CLAUDE.md), or a memory feature. When you correct something important, ask it to write the correction down. It saves you from correcting the same thing every week. (Matthew has written a great post on writing effective Copilot instructions if you want to go further.)

Ask it to ask questions one at a time. When the assistant needs decisions from you, it tends to dump a list of eight questions at once. "Ask me things one at a time" made for much better decisions (and I ended up asking for this in three separate sessions, so it's a good one to put in your instructions file!).

Say when you want a read-only review. "Don't change anything, but check for similar problems" worked really well. The assistant is keen to fix things (which is lovely!) but sometimes you just want the analysis, especially when a model is shared with other people. (In Claude Code, plan mode is built for this: the assistant investigates and proposes what to do, but doesn't make changes until you approve them.)

Use templates for documentation, then check them. It did some of its most useful work filling in documentation templates from the live model: a "model document" describing every table, measure, filter and RLS role, and requirements documents for upcoming changes. It's fast and thorough. But it also wrote a hand-calculated (and wrong) value into one of those documents, so do read what it writes before anyone builds on it. It's also great at turning technical findings into plain language. "Summarise the question so I can ask a business stakeholder, as simply as possible" became one of my most-used prompts.

Keep state in documents, not just in the chat. Long sessions eventually run out of context, and the assistant continues from a summary of what happened. Summaries lose detail. Sessions went most smoothly when the important stuff (decisions, requirements, the model document) already lived in files that the assistant could re-read.

Summary

Do:

  • Think about what data the assistant can see, and use dev or anonymised data if the model holds anything sensitive
  • Put regression tests, a benchmark and independently derived expected values in place before the MCP server changes anything (more on that in the next post)
  • Accept the EULA via an environment variable
  • Keep the server updated, and set a timeout
  • Make your test queries ask for exactly what the report asks for
  • Prototype with DEFINE MEASURE, and compare with ==
  • Back up before any change session
  • Get the business context written down, and keep state in documents
  • Ask for one question at a time, and say when you want a read-only review

Don't:

  • Trust test queries that the report would never send
  • Expect the connection to survive reopening Desktop, or your sign-in to last forever on composite models
  • Pull back huge result sets
  • Be surprised when a transaction fails because a calculated table needs recalculating

Looking back, very little of this is new. Regression tests, benchmarks, version control, backups and written-down requirements are all things we'd use on any software project. It worked well because we applied the same practices to the assistant's changes as we would to anyone else's.

Overall, I'm a convert. Pairing with an assistant that can actually run queries against the model changed how I approach semantic model work: I spent less time writing boilerplate DAX and more time thinking about what the numbers should be. Just treat it like a very fast, very keen colleague who hasn't met your stakeholders yet, and make sure you've got the tests to check its working!

In my next post, I go through that dev loop in detail, including what fixed that 13.7 s visual. If you want to go further on the performance side, my Optimising DAX series covers how the engine works and what makes DAX fast or slow, with practical examples at the end.

We help teams build Power BI reports and semantic models that people trust, understand and actually use. Explore our Power BI consulting services.

FAQs

What is the Power BI Modeling MCP server? It's an MCP (Model Context Protocol) server from Microsoft that lets an AI assistant, such as GitHub Copilot or Claude Code in VS Code, connect to a semantic model open in Power BI Desktop, in a Fabric workspace, or saved as PBIP/TMDL files. The assistant can then read the model, run DAX queries and make changes to tables, measures and relationships.
How do I accept the Power BI Modeling MCP server EULA? Until the EULA is accepted, every call fails with 'The Power BI Authoring MCP EULA must be accepted before using this tool'. You can accept it through a tool call, the --accepteula command line flag, or by setting the PBI_MODELING_MCP_ACCEPT_EULA environment variable to true. The environment variable means you only have to do it once.
Why do Power BI MCP queries fail with 'Connection is not open. Please reconnect'? Each time Power BI Desktop opens a file, it starts its local engine on a new port. If you close and reopen Desktop, the connection the assistant had is gone. Ask the assistant to list local instances and connect again.
Why compare DAX values with == rather than =? In DAX, BLANK() = 0 is TRUE, so a normal equality check treats a blank and a zero as the same value. Strict equality (==) doesn't, which matters when you're checking that a rewritten measure returns exactly what the original did.

Carmel Eve

Software Engineer II

Carmel Eve

Carmel is a software engineer and LinkedIn Learning instructor. She worked at endjin from 2016 to 2021, focused on delivering cloud-first solutions to a variety of problems. These included highly performant serverless architectures, web applications, reporting and insight pipelines, and data analytics engines. After a three-year career break spent travelling around the world, she rejoined endjin in 2024.

Carmel has written many blog posts covering a huge range of topics, including deconstructing Rx operators, agile estimation and planning and mental well-being and managing remote working.

Carmel has released two courses on LinkedIn Learning - one on the Az-204 exam (developing solutions for Microsoft Azure) and one on Azure Data Lake. She has also spoken at NDC, APISpecs, and SQLBits, covering a range of topics from reactive big-data processing to secure Azure architectures.

She is passionate about diversity and inclusivity in tech. She spent two years as a STEM ambassador in her local community and taking part in a local mentorship scheme. Through this work she hopes to be a part of positive change in the industry.

Carmel won "Apprentice Engineer of the Year" at the Computing Rising Star Awards 2019.