fix: use server-assigned connection name instead of local name

The MCP server assigns connection names like "PBIDesktop-demo-57947"
but we were saving and reusing "localhost-57947", causing "connection
not found" errors on subsequent commands. Now _auto_reconnect extracts
the server-returned connectionName from the Connect response.
This commit is contained in:
MinaSaad1 2026-03-26 23:03:23 +02:00
parent 5f0361a682
commit d9951aeecc
5 changed files with 18 additions and 6 deletions

View file

@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.6] - 2026-03-26
### Fixed
- Use server-assigned connection name for subsequent commands (fixes "connection not found" mismatch)
## [1.0.5] - 2026-03-26
### Fixed

View file

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "pbi-cli-tool"
version = "1.0.5"
version = "1.0.6"
description = "CLI for Power BI semantic models - wraps the Power BI MCP server for token-efficient AI agent usage"
readme = "README.pypi.md"
license = {text = "MIT"}

View file

@ -1,3 +1,3 @@
"""pbi-cli: CLI for Power BI semantic models via MCP server."""
__version__ = "1.0.5"
__version__ = "1.0.6"

View file

@ -55,8 +55,14 @@ def _auto_reconnect(client: PbiMcpClient, ctx: PbiContext) -> str | None:
if conn.connection_string:
request["connectionString"] = conn.connection_string
client.call_tool("connection_operations", request)
return conn.name
result = client.call_tool("connection_operations", request)
# Use server-assigned connection name (e.g. "PBIDesktop-demo-57947")
# instead of our locally saved name (e.g. "localhost-57947")
server_name = None
if isinstance(result, dict):
server_name = result.get("connectionName") or result.get("ConnectionName")
return server_name or conn.name
def run_tool(

View file

@ -56,8 +56,9 @@ def test_run_tool_adds_connection(monkeypatch: pytest.MonkeyPatch) -> None:
ctx = PbiContext(json_output=True, connection="my-conn")
run_tool(ctx, "measure_operations", {"operation": "List"})
# First call is auto-reconnect (Connect), second is the actual tool call
assert mock.calls[1][1]["connectionName"] == "my-conn"
# First call is auto-reconnect (Connect), second is the actual tool call.
# The connectionName comes from the server response ("test-conn"), not our saved name.
assert mock.calls[1][1]["connectionName"] == "test-conn"
def test_run_tool_no_connection(monkeypatch: pytest.MonkeyPatch) -> None: