powerbi-visuals-tools 7.0.2 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +17 -0
- package/MCP.md +234 -0
- package/bin/pbiviz.js +12 -0
- package/eslint.config.mjs +12 -9
- package/lib/CertificateTools.js +1 -1
- package/lib/CommandManager.js +9 -1
- package/lib/ConsoleWriter.js +4 -0
- package/lib/FeatureManager.js +9 -3
- package/lib/Visual.js +6 -0
- package/lib/VisualGenerator.js +2 -2
- package/lib/VisualManager.js +22 -6
- package/lib/WebPackWrap.js +8 -4
- package/lib/features/AuthorInfo.js +14 -0
- package/lib/features/BaseFeature.js +1 -0
- package/lib/features/RenderingEvents.js +1 -0
- package/lib/features/index.js +2 -1
- package/lib/mcp/McpServer.js +122 -0
- package/lib/mcp/tools/availableApis.js +608 -0
- package/lib/mcp/tools/bestPractices.js +391 -0
- package/lib/mcp/tools/certification.js +380 -0
- package/lib/mcp/tools/visualInfo.js +133 -0
- package/lib/mcp/tools/vulnerabilities.js +211 -0
- package/lib/utils.js +27 -0
- package/package.json +22 -18
- package/templates/visuals/_global/.vscode/mcp.json +8 -0
- package/templates/visuals/default/src/visual.ts +17 -4
- package/templates/visuals/rhtml/src/visual.ts +27 -11
- package/templates/visuals/rvisual/src/visual.ts +34 -20
- package/templates/visuals/slicer/src/visual.ts +16 -4
- package/templates/visuals/table/src/visual.ts +14 -1
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Power BI Visual CLI - MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Microsoft Corporation
|
|
5
|
+
* All rights reserved.
|
|
6
|
+
* MIT License
|
|
7
|
+
*/
|
|
8
|
+
"use strict";
|
|
9
|
+
import { McpServer as MCPServerSDK } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import fs from "fs-extra";
|
|
13
|
+
import path from "path";
|
|
14
|
+
import ConsoleWriter from "../ConsoleWriter.js";
|
|
15
|
+
import { getBestPractices } from "./tools/bestPractices.js";
|
|
16
|
+
import { checkVulnerabilities } from "./tools/vulnerabilities.js";
|
|
17
|
+
import { prepareCertification } from "./tools/certification.js";
|
|
18
|
+
import { getVisualInfo } from "./tools/visualInfo.js";
|
|
19
|
+
import { getAvailableApis } from "./tools/availableApis.js";
|
|
20
|
+
export class McpServer {
|
|
21
|
+
server;
|
|
22
|
+
rootPath;
|
|
23
|
+
constructor(rootPath) {
|
|
24
|
+
this.rootPath = rootPath;
|
|
25
|
+
this.server = new MCPServerSDK({
|
|
26
|
+
name: "pbiviz-mcp-server",
|
|
27
|
+
version: "1.0.0",
|
|
28
|
+
});
|
|
29
|
+
this.registerTools();
|
|
30
|
+
}
|
|
31
|
+
registerTools() {
|
|
32
|
+
// Tool 1: Get Best Practices
|
|
33
|
+
this.server.tool("get_best_practices", "Returns best practice guidelines for Power BI custom visual development. Covers: API version management, performance optimization (update loop, lazy loading, data processing), security (eval, innerHTML, XSS, sanitization, external call/calls, network request/requests), accessibility (keyboard navigation, high contrast, screen reader, ARIA label/labels), project structure (module/modules, error handling), formatting pane (format model, formatting model), testing (unit test/tests, E2E test/tests, edge case/cases), and documentation (README, changelog, comment/comments).", {}, async () => {
|
|
34
|
+
const practices = await getBestPractices(this.rootPath);
|
|
35
|
+
return {
|
|
36
|
+
content: [{ type: "text", text: practices }],
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
// Tool 2: Check Vulnerabilities
|
|
40
|
+
this.server.tool("check_vulnerabilities", "Scans the visual project source code for security vulnerability/vulnerabilities and dangerous code pattern/patterns. Detects: eval(), new Function(), innerHTML assignment, document.write, external fetch/HTTP call/calls, XMLHttpRequest. Also checks for commented-out dangerous code and ESLint configuration. Reports issue/issues by severity (critical, high, medium, low, info) with file path and line number.", {}, async () => {
|
|
41
|
+
const result = await checkVulnerabilities(this.rootPath);
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: "text", text: result }],
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
// Tool 3: Prepare Certification
|
|
47
|
+
this.server.tool("prepare_certification", "Audits the visual for Power BI certification readiness. Checks: required file/files (pbiviz.json, capabilities.json, package.json, tsconfig.json), visual configuration (name, GUID, version, API version, author, support URL), capability/capabilities (data role/roles, data view mapping/mappings, keyboard focus, highlight support, web access privilege/privileges), and asset/assets (icon.png). Reports pass/fail/warning status for each check.", {}, async () => {
|
|
48
|
+
const result = await prepareCertification(this.rootPath);
|
|
49
|
+
return {
|
|
50
|
+
content: [{ type: "text", text: result }],
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
// Tool 4: List Visual Info
|
|
54
|
+
this.server.tool("list_visual_info", "Returns detailed information about the current Power BI visual project. Shows: visual name, display name, GUID, version, API version, author, description, support URL, data role/roles, data view mapping/mappings, format object/objects (setting/settings), supported feature/features (highlight, keyboard focus, landing page, multi-visual selection), dependency/dependencies from package.json, and quick command/commands.", {}, async () => {
|
|
55
|
+
const result = await getVisualInfo(this.rootPath);
|
|
56
|
+
return {
|
|
57
|
+
content: [{ type: "text", text: result }],
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
// Tool 5: Get Available APIs
|
|
61
|
+
this.server.tool("get_available_apis", "Lists available Power BI Visual API/APIs and feature/features with code example/examples and documentation link/links. Categories: 'data' (fetchMoreData, data snapshot, persist property/properties), 'formatting' (color palette, format pane, formatting model, custom color/colors, high contrast), 'interaction' (selection manager, tooltip/tooltips, tooltip service, context menu, launch URL, drill down/drilldown, warning icon), 'utility' (localization, local storage, file download, rendering event/events, modal dialog, authentication), or 'all'.", {
|
|
62
|
+
category: z.string().optional().describe("Filter APIs by category: 'data' (fetchMoreData, persist, snapshot), 'formatting' (color palette, format pane, high contrast), 'interaction' (selection, tooltip/tooltips, context menu, drill down, launch URL, warning icon), 'utility' (localization, storage, download, event/events, dialog, auth), or 'all' (default)")
|
|
63
|
+
}, async ({ category }) => {
|
|
64
|
+
const result = await getAvailableApis(category || "all", this.rootPath);
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: "text", text: result }],
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async start() {
|
|
71
|
+
const transport = new StdioServerTransport();
|
|
72
|
+
await this.server.connect(transport);
|
|
73
|
+
// Keep the server running
|
|
74
|
+
process.on("SIGINT", async () => {
|
|
75
|
+
await this.server.close();
|
|
76
|
+
process.exit(0);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export async function startMcpServer(rootPath) {
|
|
81
|
+
const server = new McpServer(rootPath);
|
|
82
|
+
await server.start();
|
|
83
|
+
}
|
|
84
|
+
const MCP_CONFIG = {
|
|
85
|
+
servers: {
|
|
86
|
+
pbiviz: {
|
|
87
|
+
command: "npx",
|
|
88
|
+
args: ["-y", "powerbi-visuals-tools", "mcp"]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export async function initMcpConfig(rootPath) {
|
|
93
|
+
const vscodeDir = path.join(rootPath, ".vscode");
|
|
94
|
+
const mcpConfigPath = path.join(vscodeDir, "mcp.json");
|
|
95
|
+
try {
|
|
96
|
+
// Check if mcp.json already exists
|
|
97
|
+
if (fs.existsSync(mcpConfigPath)) {
|
|
98
|
+
ConsoleWriter.warning("MCP configuration already exists at .vscode/mcp.json");
|
|
99
|
+
ConsoleWriter.info("To reconfigure, delete the file and run this command again.");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// Create .vscode directory if it doesn't exist
|
|
103
|
+
fs.ensureDirSync(vscodeDir);
|
|
104
|
+
// Write mcp.json
|
|
105
|
+
fs.writeJsonSync(mcpConfigPath, MCP_CONFIG, { spaces: 4 });
|
|
106
|
+
ConsoleWriter.done("MCP configuration created successfully!");
|
|
107
|
+
ConsoleWriter.blank();
|
|
108
|
+
ConsoleWriter.info("Created: .vscode/mcp.json");
|
|
109
|
+
ConsoleWriter.blank();
|
|
110
|
+
ConsoleWriter.info("Next steps:");
|
|
111
|
+
ConsoleWriter.info("1. Restart VS Code to activate MCP server");
|
|
112
|
+
ConsoleWriter.info("2. Open Copilot Chat and ask questions like:");
|
|
113
|
+
ConsoleWriter.info(' - "Check my visual for certification readiness"');
|
|
114
|
+
ConsoleWriter.info(' - "What are the best practices for Power BI visuals?"');
|
|
115
|
+
ConsoleWriter.info(' - "Show me available APIs for tooltips"');
|
|
116
|
+
ConsoleWriter.blank();
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
ConsoleWriter.error(`Failed to create MCP configuration: ${(error instanceof Error) ? error.message : String(error)}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
}
|