@mcpc-tech/unplugin-dev-inspector-mcp 0.0.7 → 0.0.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 +78 -19
- package/client/dist/inspector.iife.js +5 -5
- package/dist/chunk.cjs +74 -0
- package/dist/index.cjs +814 -802
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +92 -38
- package/dist/next.cjs +31 -0
- package/dist/next.d.cts +11 -0
- package/dist/next.d.ts +11 -0
- package/dist/next.js +28 -0
- package/dist/standalone-server.cjs +104 -0
- package/dist/standalone-server.js +102 -0
- package/package.json +12 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as unplugin0 from "unplugin";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/config-updater.d.ts
|
|
4
|
-
type EditorId = 'cursor' | 'vscode' | 'windsurf' | 'claude-code';
|
|
4
|
+
type EditorId = 'cursor' | 'vscode' | 'windsurf' | 'claude-code' | 'antigravity';
|
|
5
5
|
interface CustomEditorConfig {
|
|
6
6
|
id: string;
|
|
7
7
|
name: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as unplugin0 from "unplugin";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/config-updater.d.ts
|
|
4
|
-
type EditorId = 'cursor' | 'vscode' | 'windsurf' | 'claude-code';
|
|
4
|
+
type EditorId = 'cursor' | 'vscode' | 'windsurf' | 'claude-code' | 'antigravity';
|
|
5
5
|
interface CustomEditorConfig {
|
|
6
6
|
id: string;
|
|
7
7
|
name: string;
|
package/dist/index.js
CHANGED
|
@@ -76,7 +76,7 @@ var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["modu
|
|
|
76
76
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
77
77
|
|
|
78
78
|
//#endregion
|
|
79
|
-
//#region ../../node_modules/.pnpm/@mcpc-tech+cmcp@0.0.
|
|
79
|
+
//#region ../../node_modules/.pnpm/@mcpc-tech+cmcp@0.0.14/node_modules/@mcpc-tech/cmcp/index.mjs
|
|
80
80
|
var ClientToolResponseRequestSchema = z.object({
|
|
81
81
|
method: z.literal("proxy/tool_response"),
|
|
82
82
|
params: z.object({
|
|
@@ -170,14 +170,14 @@ var ClientExecServer = class {
|
|
|
170
170
|
const existingOwner = this.toolToClient.get(toolName);
|
|
171
171
|
const isPredefined = this.predefinedTools.has(toolName);
|
|
172
172
|
if (this.useNamespacing) {
|
|
173
|
-
console.error(`Unexpected tool name conflict with namespacing: ${toolName}`);
|
|
173
|
+
console.error(`[cmcp] Unexpected tool name conflict with namespacing: ${toolName}`);
|
|
174
174
|
conflicts.push(tool$1.name);
|
|
175
175
|
continue;
|
|
176
176
|
} else if (isPredefined && existingOwner === this.clientId) {
|
|
177
|
-
console.log(`Client ${clientId} providing implementation for predefined tool: ${tool$1.name}`);
|
|
177
|
+
console.log(`[cmcp] Client ${clientId} providing implementation for predefined tool: ${tool$1.name}`);
|
|
178
178
|
this.predefinedTools.delete(toolName);
|
|
179
179
|
} else {
|
|
180
|
-
console.warn(`Tool ${tool$1.name} already exists, owned by client ${existingOwner}. Skipping registration for client ${clientId}`);
|
|
180
|
+
console.warn(`[cmcp] Tool ${tool$1.name} already exists, owned by client ${existingOwner}. Skipping registration for client ${clientId}`);
|
|
181
181
|
conflicts.push(tool$1.name);
|
|
182
182
|
continue;
|
|
183
183
|
}
|
|
@@ -192,7 +192,7 @@ var ClientExecServer = class {
|
|
|
192
192
|
this.toolToClient.set(toolName, clientId);
|
|
193
193
|
}
|
|
194
194
|
this.clientTools.set(clientId, clientToolNames);
|
|
195
|
-
if (conflicts.length > 0) console.warn(`Client ${clientId} had ${conflicts.length} tool conflicts:`, conflicts);
|
|
195
|
+
if (conflicts.length > 0) console.warn(`[cmcp] Client ${clientId} had ${conflicts.length} tool conflicts:`, conflicts);
|
|
196
196
|
return {
|
|
197
197
|
status: "success",
|
|
198
198
|
registeredTools,
|
|
@@ -379,7 +379,7 @@ function bindPuppet(transport, puppet, methods = [...DEFAULT_FORWARDED]) {
|
|
|
379
379
|
originalPuppetSend = puppet2.send?.bind(puppet2);
|
|
380
380
|
originalTransportHandler = transport.onmessage?.bind(transport);
|
|
381
381
|
transport.onmessage = (msg) => {
|
|
382
|
-
console.error(`[puppet] intercepted transport onmessage: ${JSON.stringify(msg)}`);
|
|
382
|
+
console.error(`[cmcp] [puppet] intercepted transport onmessage: ${JSON.stringify(msg)}`);
|
|
383
383
|
const parsed = JSONRPCMessageSchema.safeParse(msg);
|
|
384
384
|
if (!parsed.success) {
|
|
385
385
|
originalTransportHandler?.(msg);
|
|
@@ -391,22 +391,22 @@ function bindPuppet(transport, puppet, methods = [...DEFAULT_FORWARDED]) {
|
|
|
391
391
|
return;
|
|
392
392
|
}
|
|
393
393
|
const shouldForward = method && methods2.includes(method);
|
|
394
|
-
console.error(`[puppet] should forward to puppet=${shouldForward}, method=${method}`);
|
|
394
|
+
console.error(`[cmcp] [puppet] should forward to puppet=${shouldForward}, method=${method}`);
|
|
395
395
|
if (shouldForward) return puppet2?.onmessage?.(msg);
|
|
396
396
|
originalTransportHandler?.(msg);
|
|
397
397
|
};
|
|
398
398
|
puppet2.send = async (message) => {
|
|
399
|
-
console.error(`[puppet] intercepted puppet send: ${JSON.stringify(message)}`);
|
|
399
|
+
console.error(`[cmcp] [puppet] intercepted puppet send: ${JSON.stringify(message)}`);
|
|
400
400
|
await transport.send?.(message);
|
|
401
401
|
await originalPuppetSend?.(message);
|
|
402
402
|
};
|
|
403
403
|
}
|
|
404
404
|
function unbindPuppet() {
|
|
405
405
|
if (!boundPuppet) {
|
|
406
|
-
console.error("[puppet] no puppet bound, nothing to unbind");
|
|
406
|
+
console.error("[cmcp] [puppet] no puppet bound, nothing to unbind");
|
|
407
407
|
return;
|
|
408
408
|
}
|
|
409
|
-
console.error("[puppet] unbinding puppet and restoring original handlers");
|
|
409
|
+
console.error("[cmcp] [puppet] unbinding puppet and restoring original handlers");
|
|
410
410
|
if (originalTransportHandler) transport.onmessage = originalTransportHandler;
|
|
411
411
|
if (boundPuppet && originalPuppetSend) boundPuppet.send = originalPuppetSend;
|
|
412
412
|
boundPuppet = null;
|
|
@@ -422,7 +422,7 @@ function bindPuppet(transport, puppet, methods = [...DEFAULT_FORWARDED]) {
|
|
|
422
422
|
transport.start = async function() {
|
|
423
423
|
await originalStart?.();
|
|
424
424
|
if (puppet) {
|
|
425
|
-
console.error(`[puppet] applying puppet binding after connection established, controler: ${transport.sessionId}, puppet: ${puppet.sessionId}`);
|
|
425
|
+
console.error(`[cmcp] [puppet] applying puppet binding after connection established, controler: ${transport.sessionId}, puppet: ${puppet.sessionId}`);
|
|
426
426
|
applyPuppetBinding(puppet, methods);
|
|
427
427
|
}
|
|
428
428
|
};
|
|
@@ -88147,6 +88147,13 @@ const EDITORS = {
|
|
|
88147
88147
|
file: ".mcp.json",
|
|
88148
88148
|
urlKey: "url",
|
|
88149
88149
|
format: "mcpServers"
|
|
88150
|
+
},
|
|
88151
|
+
antigravity: {
|
|
88152
|
+
name: "Antigravity",
|
|
88153
|
+
path: join(HOME_DIR, ".gemini", "antigravity"),
|
|
88154
|
+
file: "mcp.json",
|
|
88155
|
+
urlKey: "url",
|
|
88156
|
+
format: "servers"
|
|
88150
88157
|
}
|
|
88151
88158
|
};
|
|
88152
88159
|
function resolvePath(path$2, root$2) {
|
|
@@ -88171,6 +88178,7 @@ function detectEditors(root$2) {
|
|
|
88171
88178
|
const found = findUpDir(editor.path, root$2);
|
|
88172
88179
|
if (!found) {
|
|
88173
88180
|
if (id === "cursor" || id === "vscode") return true;
|
|
88181
|
+
if (id === "antigravity") return existsSync(editor.path);
|
|
88174
88182
|
return false;
|
|
88175
88183
|
}
|
|
88176
88184
|
return id === "claude-code" ? existsSync(join(found, editor.file)) : true;
|
|
@@ -88255,6 +88263,7 @@ const unplugin = createUnplugin((options = {}) => {
|
|
|
88255
88263
|
const enabled = options.enabled ?? process.env.NODE_ENV !== "production";
|
|
88256
88264
|
const enableMcp = options.enableMcp ?? true;
|
|
88257
88265
|
const virtualModuleName = options.virtualModuleName ?? "virtual:dev-inspector-mcp";
|
|
88266
|
+
const webpackModuleName = virtualModuleName.replace("virtual:", "");
|
|
88258
88267
|
let resolvedHost = options.host || "localhost";
|
|
88259
88268
|
let resolvedPort = options.port || 5173;
|
|
88260
88269
|
if (!enabled) return { name: "unplugin-dev-inspector" };
|
|
@@ -88262,40 +88271,38 @@ const unplugin = createUnplugin((options = {}) => {
|
|
|
88262
88271
|
name: "unplugin-dev-inspector",
|
|
88263
88272
|
enforce: "pre",
|
|
88264
88273
|
resolveId(id) {
|
|
88265
|
-
if (id === virtualModuleName) return "\0" + virtualModuleName;
|
|
88274
|
+
if (id === virtualModuleName || id === webpackModuleName) return "\0" + virtualModuleName;
|
|
88266
88275
|
},
|
|
88267
88276
|
load(id) {
|
|
88268
88277
|
if (id === "\0" + virtualModuleName) return `
|
|
88269
|
-
// Development-only code -
|
|
88270
|
-
if (
|
|
88271
|
-
|
|
88272
|
-
|
|
88273
|
-
|
|
88274
|
-
|
|
88275
|
-
|
|
88276
|
-
|
|
88277
|
-
|
|
88278
|
-
|
|
88279
|
-
|
|
88280
|
-
|
|
88281
|
-
|
|
88282
|
-
|
|
88283
|
-
|
|
88284
|
-
|
|
88285
|
-
|
|
88286
|
-
|
|
88287
|
-
|
|
88288
|
-
baseUrl = baseUrl.slice(0, -1);
|
|
88289
|
-
}
|
|
88290
|
-
script.src = baseUrl + '/__inspector__/inspector.iife.js';
|
|
88291
|
-
script.type = 'module';
|
|
88292
|
-
document.head.appendChild(script);
|
|
88278
|
+
// Development-only code - removed in production builds
|
|
88279
|
+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
88280
|
+
// Create inspector element
|
|
88281
|
+
const inspector = document.createElement('dev-inspector-mcp');
|
|
88282
|
+
document.body.appendChild(inspector);
|
|
88283
|
+
|
|
88284
|
+
// Store dev server config globally
|
|
88285
|
+
window.__DEV_INSPECTOR_CONFIG__ = {
|
|
88286
|
+
host: '${resolvedHost}',
|
|
88287
|
+
port: '${resolvedPort}',
|
|
88288
|
+
base: '/'
|
|
88289
|
+
};
|
|
88290
|
+
|
|
88291
|
+
// Dynamically load inspector script
|
|
88292
|
+
const script = document.createElement('script');
|
|
88293
|
+
const config = window.__DEV_INSPECTOR_CONFIG__;
|
|
88294
|
+
let baseUrl = 'http://' + config.host + ':' + config.port + config.base;
|
|
88295
|
+
if (baseUrl.endsWith('/')) {
|
|
88296
|
+
baseUrl = baseUrl.slice(0, -1);
|
|
88293
88297
|
}
|
|
88298
|
+
script.src = baseUrl + '/__inspector__/inspector.iife.js';
|
|
88299
|
+
script.type = 'module';
|
|
88300
|
+
document.head.appendChild(script);
|
|
88294
88301
|
}
|
|
88295
88302
|
`;
|
|
88296
88303
|
},
|
|
88297
88304
|
async transform(code, id) {
|
|
88298
|
-
if (id.includes("node_modules")) return null;
|
|
88305
|
+
if (!id || id.includes("node_modules")) return null;
|
|
88299
88306
|
if (id.match(/\.(jsx|tsx)$/)) try {
|
|
88300
88307
|
return await transformJSX({
|
|
88301
88308
|
code,
|
|
@@ -88389,7 +88396,54 @@ if (import.meta.env.DEV) {
|
|
|
88389
88396
|
handleHotUpdate() {}
|
|
88390
88397
|
},
|
|
88391
88398
|
webpack(compiler) {
|
|
88392
|
-
|
|
88399
|
+
if (!enabled) return;
|
|
88400
|
+
if (compiler.options.mode !== "development") return;
|
|
88401
|
+
let serverStarted = false;
|
|
88402
|
+
compiler.hooks.beforeCompile.tapAsync("UnpluginDevInspector", async (params, callback) => {
|
|
88403
|
+
if (serverStarted) {
|
|
88404
|
+
callback();
|
|
88405
|
+
return;
|
|
88406
|
+
}
|
|
88407
|
+
serverStarted = true;
|
|
88408
|
+
try {
|
|
88409
|
+
const { startStandaloneServer } = await import("./standalone-server.js");
|
|
88410
|
+
const { server, host, port } = await startStandaloneServer({
|
|
88411
|
+
port: options.port,
|
|
88412
|
+
host: options.host
|
|
88413
|
+
});
|
|
88414
|
+
resolvedHost = host;
|
|
88415
|
+
resolvedPort = port;
|
|
88416
|
+
const serverContext = {
|
|
88417
|
+
host,
|
|
88418
|
+
port
|
|
88419
|
+
};
|
|
88420
|
+
if (enableMcp) {
|
|
88421
|
+
const baseUrl = `http://${host === "0.0.0.0" ? "localhost" : host}:${port}/__mcp__/sse`;
|
|
88422
|
+
console.log(`[dev-inspector] 📡 MCP (Standalone): ${baseUrl}\n`);
|
|
88423
|
+
setupMcpMiddleware(server, serverContext);
|
|
88424
|
+
setupAcpMiddleware(server, serverContext, {
|
|
88425
|
+
acpMode: options.acpMode,
|
|
88426
|
+
acpModel: options.acpModel,
|
|
88427
|
+
acpDelay: options.acpDelay
|
|
88428
|
+
});
|
|
88429
|
+
const root$2 = compiler.context;
|
|
88430
|
+
await updateMcpConfigs(root$2, baseUrl, {
|
|
88431
|
+
updateConfig: options.updateConfig,
|
|
88432
|
+
updateConfigServerName: options.updateConfigServerName,
|
|
88433
|
+
updateConfigAdditionalServers: options.updateConfigAdditionalServers,
|
|
88434
|
+
customEditors: options.customEditors
|
|
88435
|
+
});
|
|
88436
|
+
}
|
|
88437
|
+
setupInspectorMiddleware(server, {
|
|
88438
|
+
agents: options.agents,
|
|
88439
|
+
defaultAgent: options.defaultAgent
|
|
88440
|
+
});
|
|
88441
|
+
callback();
|
|
88442
|
+
} catch (e) {
|
|
88443
|
+
console.error("[dev-inspector] Failed to start standalone server:", e);
|
|
88444
|
+
callback();
|
|
88445
|
+
}
|
|
88446
|
+
});
|
|
88393
88447
|
},
|
|
88394
88448
|
rollup: {},
|
|
88395
88449
|
esbuild: { setup(build) {} }
|
package/dist/next.cjs
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
const require_chunk = require('./chunk.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/next.tsx
|
|
8
|
+
function DevInspector({ host = "localhost", port = "8888" }) {
|
|
9
|
+
(0, react.useEffect)(() => {
|
|
10
|
+
if (typeof window === "undefined") return;
|
|
11
|
+
if (window.__DEV_INSPECTOR_LOADED__) return;
|
|
12
|
+
window.__DEV_INSPECTOR_LOADED__ = true;
|
|
13
|
+
const inspector = document.createElement("dev-inspector-mcp");
|
|
14
|
+
document.body.appendChild(inspector);
|
|
15
|
+
window.__DEV_INSPECTOR_CONFIG__ = {
|
|
16
|
+
host,
|
|
17
|
+
port: String(port),
|
|
18
|
+
base: "/"
|
|
19
|
+
};
|
|
20
|
+
const script = document.createElement("script");
|
|
21
|
+
script.src = `http://${host}:${port}/__inspector__/inspector.iife.js`;
|
|
22
|
+
script.type = "module";
|
|
23
|
+
document.head.appendChild(script);
|
|
24
|
+
}, [host, port]);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
var next_default = DevInspector;
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.DevInspector = DevInspector;
|
|
31
|
+
exports.default = next_default;
|
package/dist/next.d.cts
ADDED
package/dist/next.d.ts
ADDED
package/dist/next.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/next.tsx
|
|
6
|
+
function DevInspector({ host = "localhost", port = "8888" }) {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (typeof window === "undefined") return;
|
|
9
|
+
if (window.__DEV_INSPECTOR_LOADED__) return;
|
|
10
|
+
window.__DEV_INSPECTOR_LOADED__ = true;
|
|
11
|
+
const inspector = document.createElement("dev-inspector-mcp");
|
|
12
|
+
document.body.appendChild(inspector);
|
|
13
|
+
window.__DEV_INSPECTOR_CONFIG__ = {
|
|
14
|
+
host,
|
|
15
|
+
port: String(port),
|
|
16
|
+
base: "/"
|
|
17
|
+
};
|
|
18
|
+
const script = document.createElement("script");
|
|
19
|
+
script.src = `http://${host}:${port}/__inspector__/inspector.iife.js`;
|
|
20
|
+
script.type = "module";
|
|
21
|
+
document.head.appendChild(script);
|
|
22
|
+
}, [host, port]);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
var next_default = DevInspector;
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { DevInspector, next_default as default };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const require_chunk = require('./chunk.cjs');
|
|
2
|
+
let node_http = require("node:http");
|
|
3
|
+
node_http = require_chunk.__toESM(node_http);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/standalone-server.ts
|
|
6
|
+
var StandaloneServer = class {
|
|
7
|
+
server;
|
|
8
|
+
middlewares = [];
|
|
9
|
+
port = 0;
|
|
10
|
+
host = "localhost";
|
|
11
|
+
stack = [];
|
|
12
|
+
constructor() {
|
|
13
|
+
this.server = node_http.default.createServer(async (req, res) => {
|
|
14
|
+
let index = 0;
|
|
15
|
+
const next = async () => {
|
|
16
|
+
if (index >= this.middlewares.length) {
|
|
17
|
+
if (!res.writableEnded) {
|
|
18
|
+
res.statusCode = 404;
|
|
19
|
+
res.end("Not Found");
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const layer = this.middlewares[index++];
|
|
24
|
+
if ((req.url || "/").startsWith(layer.route)) try {
|
|
25
|
+
const originalUrl = req.url;
|
|
26
|
+
if (layer.route !== "/" && req.url) {}
|
|
27
|
+
await layer.handle(req, res, next);
|
|
28
|
+
if (layer.route !== "/") req.url = originalUrl;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error("Middleware error:", error);
|
|
31
|
+
if (!res.writableEnded) {
|
|
32
|
+
res.statusCode = 500;
|
|
33
|
+
res.end("Internal Server Error");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else next();
|
|
37
|
+
};
|
|
38
|
+
await next();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
use(routeOrHandle, handle) {
|
|
42
|
+
let route = "/";
|
|
43
|
+
let handler;
|
|
44
|
+
if (typeof routeOrHandle === "string") {
|
|
45
|
+
route = routeOrHandle;
|
|
46
|
+
if (!handle) throw new Error("Handler is required when route is provided");
|
|
47
|
+
handler = handle;
|
|
48
|
+
} else handler = routeOrHandle;
|
|
49
|
+
this.middlewares.push({
|
|
50
|
+
route,
|
|
51
|
+
handle: handler
|
|
52
|
+
});
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
listen(...args) {
|
|
56
|
+
return this.server.listen(...args);
|
|
57
|
+
}
|
|
58
|
+
async start(options = {}) {
|
|
59
|
+
const startPort = options.port || 8888;
|
|
60
|
+
this.host = options.host || "localhost";
|
|
61
|
+
for (let port = startPort; port < startPort + 100; port++) try {
|
|
62
|
+
await new Promise((resolve, reject) => {
|
|
63
|
+
this.server.listen(port, this.host, () => {
|
|
64
|
+
this.port = port;
|
|
65
|
+
resolve();
|
|
66
|
+
});
|
|
67
|
+
this.server.on("error", (err) => {
|
|
68
|
+
if (err.code === "EADDRINUSE") {
|
|
69
|
+
this.server.close();
|
|
70
|
+
reject(err);
|
|
71
|
+
} else reject(err);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
host: this.host,
|
|
76
|
+
port: this.port
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.code !== "EADDRINUSE") throw error;
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`Could not find a free port starting from ${startPort}`);
|
|
82
|
+
}
|
|
83
|
+
close() {
|
|
84
|
+
this.server.close();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
let globalServer = null;
|
|
88
|
+
async function startStandaloneServer(options = {}) {
|
|
89
|
+
if (globalServer) return {
|
|
90
|
+
server: globalServer,
|
|
91
|
+
host: globalServer.host,
|
|
92
|
+
port: globalServer.port
|
|
93
|
+
};
|
|
94
|
+
globalServer = new StandaloneServer();
|
|
95
|
+
const { host, port } = await globalServer.start(options);
|
|
96
|
+
return {
|
|
97
|
+
server: globalServer,
|
|
98
|
+
host,
|
|
99
|
+
port
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
exports.startStandaloneServer = startStandaloneServer;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/standalone-server.ts
|
|
4
|
+
var StandaloneServer = class {
|
|
5
|
+
server;
|
|
6
|
+
middlewares = [];
|
|
7
|
+
port = 0;
|
|
8
|
+
host = "localhost";
|
|
9
|
+
stack = [];
|
|
10
|
+
constructor() {
|
|
11
|
+
this.server = http.createServer(async (req, res) => {
|
|
12
|
+
let index = 0;
|
|
13
|
+
const next = async () => {
|
|
14
|
+
if (index >= this.middlewares.length) {
|
|
15
|
+
if (!res.writableEnded) {
|
|
16
|
+
res.statusCode = 404;
|
|
17
|
+
res.end("Not Found");
|
|
18
|
+
}
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const layer = this.middlewares[index++];
|
|
22
|
+
if ((req.url || "/").startsWith(layer.route)) try {
|
|
23
|
+
const originalUrl = req.url;
|
|
24
|
+
if (layer.route !== "/" && req.url) {}
|
|
25
|
+
await layer.handle(req, res, next);
|
|
26
|
+
if (layer.route !== "/") req.url = originalUrl;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error("Middleware error:", error);
|
|
29
|
+
if (!res.writableEnded) {
|
|
30
|
+
res.statusCode = 500;
|
|
31
|
+
res.end("Internal Server Error");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else next();
|
|
35
|
+
};
|
|
36
|
+
await next();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
use(routeOrHandle, handle) {
|
|
40
|
+
let route = "/";
|
|
41
|
+
let handler;
|
|
42
|
+
if (typeof routeOrHandle === "string") {
|
|
43
|
+
route = routeOrHandle;
|
|
44
|
+
if (!handle) throw new Error("Handler is required when route is provided");
|
|
45
|
+
handler = handle;
|
|
46
|
+
} else handler = routeOrHandle;
|
|
47
|
+
this.middlewares.push({
|
|
48
|
+
route,
|
|
49
|
+
handle: handler
|
|
50
|
+
});
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
listen(...args) {
|
|
54
|
+
return this.server.listen(...args);
|
|
55
|
+
}
|
|
56
|
+
async start(options = {}) {
|
|
57
|
+
const startPort = options.port || 8888;
|
|
58
|
+
this.host = options.host || "localhost";
|
|
59
|
+
for (let port = startPort; port < startPort + 100; port++) try {
|
|
60
|
+
await new Promise((resolve, reject) => {
|
|
61
|
+
this.server.listen(port, this.host, () => {
|
|
62
|
+
this.port = port;
|
|
63
|
+
resolve();
|
|
64
|
+
});
|
|
65
|
+
this.server.on("error", (err) => {
|
|
66
|
+
if (err.code === "EADDRINUSE") {
|
|
67
|
+
this.server.close();
|
|
68
|
+
reject(err);
|
|
69
|
+
} else reject(err);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
host: this.host,
|
|
74
|
+
port: this.port
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (error.code !== "EADDRINUSE") throw error;
|
|
78
|
+
}
|
|
79
|
+
throw new Error(`Could not find a free port starting from ${startPort}`);
|
|
80
|
+
}
|
|
81
|
+
close() {
|
|
82
|
+
this.server.close();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
let globalServer = null;
|
|
86
|
+
async function startStandaloneServer(options = {}) {
|
|
87
|
+
if (globalServer) return {
|
|
88
|
+
server: globalServer,
|
|
89
|
+
host: globalServer.host,
|
|
90
|
+
port: globalServer.port
|
|
91
|
+
};
|
|
92
|
+
globalServer = new StandaloneServer();
|
|
93
|
+
const { host, port } = await globalServer.start(options);
|
|
94
|
+
return {
|
|
95
|
+
server: globalServer,
|
|
96
|
+
host,
|
|
97
|
+
port
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
102
|
+
export { startStandaloneServer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcpc-tech/unplugin-dev-inspector-mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Universal dev inspector plugin for React/Vue - inspect component sources and API calls in any bundler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,6 +23,16 @@
|
|
|
23
23
|
"default": "./dist/index.cjs"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
+
"./next": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/next.d.ts",
|
|
29
|
+
"default": "./dist/next.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/next.d.cts",
|
|
33
|
+
"default": "./dist/next.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
26
36
|
"./client": {
|
|
27
37
|
"types": "./client.d.ts"
|
|
28
38
|
},
|
|
@@ -62,7 +72,7 @@
|
|
|
62
72
|
"@babel/parser": "^7.28.5",
|
|
63
73
|
"@babel/traverse": "^7.28.5",
|
|
64
74
|
"@mcpc-tech/acp-ai-provider": "^0.1.25",
|
|
65
|
-
"@mcpc-tech/cmcp": "^0.0.
|
|
75
|
+
"@mcpc-tech/cmcp": "^0.0.14",
|
|
66
76
|
"@mcpc-tech/core": "^0.3.8",
|
|
67
77
|
"@modelcontextprotocol/sdk": "^1.20.1",
|
|
68
78
|
"@radix-ui/primitive": "^1.1.3",
|