@mcpc-tech/unplugin-dev-inspector-mcp 0.1.8 → 0.1.9
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/README.md +8 -16
- package/dist/index.cjs +26 -4
- package/dist/index.d.cts +17 -4
- package/dist/index.d.ts +13 -0
- package/dist/index.js +25 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,19 +150,17 @@ If you prefer to configure it manually:
|
|
|
150
150
|
|
|
151
151
|
If your project doesn't use HTML files (e.g., miniapp platforms that only bundle JS):
|
|
152
152
|
|
|
153
|
+
```typescript
|
|
154
|
+
// vite.config.ts
|
|
153
155
|
```typescript
|
|
154
156
|
// vite.config.ts
|
|
155
157
|
DevInspector.vite({
|
|
156
158
|
enabled: true,
|
|
157
|
-
autoInject: false // Disable HTML injection
|
|
159
|
+
autoInject: false, // Disable HTML injection
|
|
160
|
+
entry: 'src/main.ts' // Inject inspector into entry file
|
|
158
161
|
})
|
|
159
162
|
```
|
|
160
163
|
|
|
161
|
-
```typescript
|
|
162
|
-
// main.ts or app entry point
|
|
163
|
-
import 'virtual:dev-inspector-mcp'; // ← Add this import
|
|
164
|
-
```
|
|
165
|
-
|
|
166
164
|
##### TypeScript Types (Required for `virtual:dev-inspector-mcp`)
|
|
167
165
|
|
|
168
166
|
If you use TypeScript and import `virtual:dev-inspector-mcp`, make sure your TS config includes the plugin client types:
|
|
@@ -270,15 +268,6 @@ export default function RootLayout({ children }) {
|
|
|
270
268
|
|
|
271
269
|
### React Router v7+
|
|
272
270
|
|
|
273
|
-
Since React Router handles HTML generation via its own SSR/SPA mechanism, it bypasses the standard Vite HTML transformation hooks. You need to manually import the virtual module in your entry file.
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
// app/root.tsx or app/entry.client.tsx
|
|
277
|
-
import 'virtual:dev-inspector-mcp';
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
And ensure your `vite.config.ts` has the plugin:
|
|
281
|
-
|
|
282
271
|
```typescript
|
|
283
272
|
// vite.config.ts
|
|
284
273
|
import { reactRouter } from "@react-router/dev/vite";
|
|
@@ -286,7 +275,10 @@ import DevInspector from '@mcpc-tech/unplugin-dev-inspector-mcp';
|
|
|
286
275
|
|
|
287
276
|
export default defineConfig({
|
|
288
277
|
plugins: [
|
|
289
|
-
DevInspector.vite({
|
|
278
|
+
DevInspector.vite({
|
|
279
|
+
enabled: true,
|
|
280
|
+
entry: "app/root.tsx" // Inject inspector into root layout
|
|
281
|
+
}),
|
|
290
282
|
reactRouter(),
|
|
291
283
|
],
|
|
292
284
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,8 @@ let node_path = require("node:path");
|
|
|
6
6
|
node_path = require_chunk.__toESM(node_path);
|
|
7
7
|
let _modelcontextprotocol_sdk_client_index_js = require("@modelcontextprotocol/sdk/client/index.js");
|
|
8
8
|
let _modelcontextprotocol_sdk_client_sse_js = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
9
|
+
let path = require("path");
|
|
10
|
+
path = require_chunk.__toESM(path);
|
|
9
11
|
let _babel_parser = require("@babel/parser");
|
|
10
12
|
let magic_string = require("magic-string");
|
|
11
13
|
magic_string = require_chunk.__toESM(magic_string);
|
|
@@ -144,9 +146,21 @@ const createDevInspectorPlugin = (name, transformFactory) => {
|
|
|
144
146
|
let resolvedPort = options.port || 5173;
|
|
145
147
|
const transformImpl = transformFactory(options);
|
|
146
148
|
const chromeDisabled = require_config_updater.isChromeDisabled(options.disableChrome);
|
|
149
|
+
const entryOption = process.env.DEV_INSPECTOR_ENTRY || options.entry;
|
|
150
|
+
const resolvedEntry = entryOption ? path.default.resolve(process.cwd(), entryOption) : null;
|
|
147
151
|
const transform = (code, id) => {
|
|
148
152
|
if (!enabled) return null;
|
|
149
153
|
if (viteCommand && viteCommand !== "serve") return null;
|
|
154
|
+
if (resolvedEntry && id === resolvedEntry) {
|
|
155
|
+
const injection = `import '${virtualModuleName}';\n`;
|
|
156
|
+
const result = transformImpl(code, id);
|
|
157
|
+
if (typeof result === "string") return injection + result;
|
|
158
|
+
else if (result && typeof result === "object" && "code" in result) return {
|
|
159
|
+
...result,
|
|
160
|
+
code: injection + result.code
|
|
161
|
+
};
|
|
162
|
+
else return injection + code;
|
|
163
|
+
}
|
|
150
164
|
return transformImpl(code, id);
|
|
151
165
|
};
|
|
152
166
|
const createNoopVirtualModule = () => {
|
|
@@ -169,7 +183,11 @@ export function registerInspectorTool(_tool) {
|
|
|
169
183
|
const host = resolvedHost;
|
|
170
184
|
const port = resolvedPort;
|
|
171
185
|
const showInspectorBar = options.showInspectorBar ?? true;
|
|
172
|
-
const publicBaseUrl =
|
|
186
|
+
const publicBaseUrl = require_config_updater.getPublicBaseUrl({
|
|
187
|
+
publicBaseUrl: options.publicBaseUrl,
|
|
188
|
+
host,
|
|
189
|
+
port
|
|
190
|
+
});
|
|
173
191
|
const injectedBaseUrl = publicBaseUrl ? require_config_updater.stripTrailingSlash(publicBaseUrl) : void 0;
|
|
174
192
|
return `
|
|
175
193
|
// Development-only code - removed in production builds
|
|
@@ -254,7 +272,11 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
|
254
272
|
const port = options.port ?? server?.config.server.port ?? 5173;
|
|
255
273
|
const base = server?.config.base ?? "/";
|
|
256
274
|
const showInspectorBar = options.showInspectorBar ?? true;
|
|
257
|
-
const publicBaseUrl =
|
|
275
|
+
const publicBaseUrl = require_config_updater.getPublicBaseUrl({
|
|
276
|
+
publicBaseUrl: options.publicBaseUrl,
|
|
277
|
+
host,
|
|
278
|
+
port
|
|
279
|
+
});
|
|
258
280
|
const displayHost = host === "0.0.0.0" ? "localhost" : host;
|
|
259
281
|
return html.replace("</body>", `<dev-inspector-mcp></dev-inspector-mcp><script>
|
|
260
282
|
(function() {
|
|
@@ -488,9 +510,9 @@ function transformJSX({ code, id }) {
|
|
|
488
510
|
const s = new magic_string.default(code);
|
|
489
511
|
let hasModifications = false;
|
|
490
512
|
try {
|
|
491
|
-
traverse(ast, { JSXOpeningElement(path$
|
|
513
|
+
traverse(ast, { JSXOpeningElement(path$6) {
|
|
492
514
|
try {
|
|
493
|
-
const node = path$
|
|
515
|
+
const node = path$6.node;
|
|
494
516
|
if (!node.name || isFragment(node.name)) return;
|
|
495
517
|
if (!node.loc?.start || !node.name.end) return;
|
|
496
518
|
if (node.attributes?.some((attr$1) => attr$1.type === "JSXAttribute" && attr$1.name?.type === "JSXIdentifier" && attr$1.name.name === DATA_SOURCE_ATTR$2)) return;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as unplugin0 from "unplugin";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/config-updater.d.ts
|
|
4
4
|
type EditorId = "cursor" | "vscode" | "windsurf" | "claude-code" | "antigravity";
|
|
@@ -174,19 +174,32 @@ interface DevInspectorOptions extends McpConfigOptions, AcpOptions {
|
|
|
174
174
|
* @example "http://localhost:5173/dashboard"
|
|
175
175
|
*/
|
|
176
176
|
browserUrl?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Whether to show the inspector bar UI
|
|
179
|
+
* Set to false if you only want to use the editor integration
|
|
180
|
+
* @default true
|
|
181
|
+
*/
|
|
177
182
|
/**
|
|
178
183
|
* Whether to show the inspector bar UI
|
|
179
184
|
* Set to false if you only want to use the editor integration
|
|
180
185
|
* @default true
|
|
181
186
|
*/
|
|
182
187
|
showInspectorBar?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Entry file to safely inject the inspector import.
|
|
190
|
+
* Useful when `autoInject: false` or when using a framework where HTML injection is insufficient.
|
|
191
|
+
* Can also be set via `DEV_INSPECTOR_ENTRY` environment variable.
|
|
192
|
+
*
|
|
193
|
+
* @example "src/main.tsx"
|
|
194
|
+
*/
|
|
195
|
+
entry?: string;
|
|
183
196
|
}
|
|
184
197
|
//#endregion
|
|
185
198
|
//#region src/core.d.ts
|
|
186
|
-
declare const unplugin:
|
|
199
|
+
declare const unplugin: unplugin0.UnpluginInstance<DevInspectorOptions | undefined, boolean>;
|
|
187
200
|
//#endregion
|
|
188
201
|
//#region src/core-external.d.ts
|
|
189
|
-
declare const unpluginExternal:
|
|
202
|
+
declare const unpluginExternal: unplugin0.UnpluginInstance<DevInspectorOptions | undefined, boolean>;
|
|
190
203
|
//#endregion
|
|
191
204
|
//#region src/turbopack.d.ts
|
|
192
205
|
interface TurbopackDevInspectorOptions extends DevInspectorOptions {
|
|
@@ -211,7 +224,7 @@ interface TurbopackDevInspectorOptions extends DevInspectorOptions {
|
|
|
211
224
|
declare function turbopackDevInspector(options?: TurbopackDevInspectorOptions): any;
|
|
212
225
|
//#endregion
|
|
213
226
|
//#region src/index.d.ts
|
|
214
|
-
declare const external:
|
|
227
|
+
declare const external: unplugin0.UnpluginInstance<DevInspectorOptions | undefined, boolean>;
|
|
215
228
|
declare module "virtual:dev-inspector-mcp" {}
|
|
216
229
|
//#endregion
|
|
217
230
|
export { type CustomEditorConfig, type DevInspectorOptions, type EditorId, type McpConfigOptions, type TurbopackDevInspectorOptions, unplugin as default, unplugin, external, turbopackDevInspector, unpluginExternal };
|
package/dist/index.d.ts
CHANGED
|
@@ -174,12 +174,25 @@ interface DevInspectorOptions extends McpConfigOptions, AcpOptions {
|
|
|
174
174
|
* @example "http://localhost:5173/dashboard"
|
|
175
175
|
*/
|
|
176
176
|
browserUrl?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Whether to show the inspector bar UI
|
|
179
|
+
* Set to false if you only want to use the editor integration
|
|
180
|
+
* @default true
|
|
181
|
+
*/
|
|
177
182
|
/**
|
|
178
183
|
* Whether to show the inspector bar UI
|
|
179
184
|
* Set to false if you only want to use the editor integration
|
|
180
185
|
* @default true
|
|
181
186
|
*/
|
|
182
187
|
showInspectorBar?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Entry file to safely inject the inspector import.
|
|
190
|
+
* Useful when `autoInject: false` or when using a framework where HTML injection is insufficient.
|
|
191
|
+
* Can also be set via `DEV_INSPECTOR_ENTRY` environment variable.
|
|
192
|
+
*
|
|
193
|
+
* @example "src/main.tsx"
|
|
194
|
+
*/
|
|
195
|
+
entry?: string;
|
|
183
196
|
}
|
|
184
197
|
//#endregion
|
|
185
198
|
//#region src/core.d.ts
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
5
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
6
|
+
import path$1 from "path";
|
|
6
7
|
import { parse } from "@babel/parser";
|
|
7
8
|
import MagicString from "magic-string";
|
|
8
9
|
import { createUnplugin } from "unplugin";
|
|
@@ -140,9 +141,21 @@ const createDevInspectorPlugin = (name, transformFactory) => {
|
|
|
140
141
|
let resolvedPort = options.port || 5173;
|
|
141
142
|
const transformImpl = transformFactory(options);
|
|
142
143
|
const chromeDisabled = isChromeDisabled(options.disableChrome);
|
|
144
|
+
const entryOption = process.env.DEV_INSPECTOR_ENTRY || options.entry;
|
|
145
|
+
const resolvedEntry = entryOption ? path$1.resolve(process.cwd(), entryOption) : null;
|
|
143
146
|
const transform = (code, id) => {
|
|
144
147
|
if (!enabled) return null;
|
|
145
148
|
if (viteCommand && viteCommand !== "serve") return null;
|
|
149
|
+
if (resolvedEntry && id === resolvedEntry) {
|
|
150
|
+
const injection = `import '${virtualModuleName}';\n`;
|
|
151
|
+
const result = transformImpl(code, id);
|
|
152
|
+
if (typeof result === "string") return injection + result;
|
|
153
|
+
else if (result && typeof result === "object" && "code" in result) return {
|
|
154
|
+
...result,
|
|
155
|
+
code: injection + result.code
|
|
156
|
+
};
|
|
157
|
+
else return injection + code;
|
|
158
|
+
}
|
|
146
159
|
return transformImpl(code, id);
|
|
147
160
|
};
|
|
148
161
|
const createNoopVirtualModule = () => {
|
|
@@ -165,7 +178,11 @@ export function registerInspectorTool(_tool) {
|
|
|
165
178
|
const host = resolvedHost;
|
|
166
179
|
const port = resolvedPort;
|
|
167
180
|
const showInspectorBar = options.showInspectorBar ?? true;
|
|
168
|
-
const publicBaseUrl =
|
|
181
|
+
const publicBaseUrl = getPublicBaseUrl({
|
|
182
|
+
publicBaseUrl: options.publicBaseUrl,
|
|
183
|
+
host,
|
|
184
|
+
port
|
|
185
|
+
});
|
|
169
186
|
const injectedBaseUrl = publicBaseUrl ? stripTrailingSlash(publicBaseUrl) : void 0;
|
|
170
187
|
return `
|
|
171
188
|
// Development-only code - removed in production builds
|
|
@@ -250,7 +267,11 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
|
250
267
|
const port = options.port ?? server?.config.server.port ?? 5173;
|
|
251
268
|
const base = server?.config.base ?? "/";
|
|
252
269
|
const showInspectorBar = options.showInspectorBar ?? true;
|
|
253
|
-
const publicBaseUrl =
|
|
270
|
+
const publicBaseUrl = getPublicBaseUrl({
|
|
271
|
+
publicBaseUrl: options.publicBaseUrl,
|
|
272
|
+
host,
|
|
273
|
+
port
|
|
274
|
+
});
|
|
254
275
|
const displayHost = host === "0.0.0.0" ? "localhost" : host;
|
|
255
276
|
return html.replace("</body>", `<dev-inspector-mcp></dev-inspector-mcp><script>
|
|
256
277
|
(function() {
|
|
@@ -484,9 +505,9 @@ function transformJSX({ code, id }) {
|
|
|
484
505
|
const s = new MagicString(code);
|
|
485
506
|
let hasModifications = false;
|
|
486
507
|
try {
|
|
487
|
-
traverse(ast, { JSXOpeningElement(path$
|
|
508
|
+
traverse(ast, { JSXOpeningElement(path$2) {
|
|
488
509
|
try {
|
|
489
|
-
const node = path$
|
|
510
|
+
const node = path$2.node;
|
|
490
511
|
if (!node.name || isFragment(node.name)) return;
|
|
491
512
|
if (!node.loc?.start || !node.name.end) return;
|
|
492
513
|
if (node.attributes?.some((attr$1) => attr$1.type === "JSXAttribute" && attr$1.name?.type === "JSXIdentifier" && attr$1.name.name === DATA_SOURCE_ATTR$2)) return;
|
package/package.json
CHANGED