@qwik.dev/mcp 2.0.0-rc.2 → 2.0.0-rc.3
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 +3 -0
- package/dist/browser.js +46 -6
- package/dist/cli.js +19 -2
- package/dist/docs.json +1 -1
- package/dist/index.js +28 -71
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -137,41 +137,11 @@ function isCustomHook(hookName) {
|
|
|
137
137
|
const isBuiltIn = USE_HOOK_LIST.some((item) => item.startsWith(hookName));
|
|
138
138
|
return !isBuiltIn && /^use[A-Z_]/.test(hookName);
|
|
139
139
|
}
|
|
140
|
-
function findLineStart(code, index) {
|
|
141
|
-
for (let i = index - 1; i >= 0; i--) {
|
|
142
|
-
const ch = code[i];
|
|
143
|
-
if (ch === "\n" || ch === "\r") {
|
|
144
|
-
return i + 1;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return 0;
|
|
148
|
-
}
|
|
149
|
-
function readIndent(code, indexFrom) {
|
|
150
|
-
let indent = "";
|
|
151
|
-
let i = indexFrom;
|
|
152
|
-
while (i < code.length) {
|
|
153
|
-
const ch = code[i];
|
|
154
|
-
if (ch === " " || ch === " ") {
|
|
155
|
-
indent += ch;
|
|
156
|
-
i++;
|
|
157
|
-
} else {
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return indent;
|
|
162
|
-
}
|
|
163
140
|
function trimStatementSemicolon(segment) {
|
|
164
141
|
return segment.trim().replace(/;?\s*$/, "");
|
|
165
142
|
}
|
|
166
|
-
function buildCollecthookPayload(
|
|
167
|
-
|
|
168
|
-
return `${indent}collecthook({
|
|
169
|
-
${indent} variableName: '${variableName}',
|
|
170
|
-
${indent} hookType: '${hookType}',
|
|
171
|
-
${indent} category: '${category}',
|
|
172
|
-
${indent} data: ${dataValue}
|
|
173
|
-
${indent}});
|
|
174
|
-
`;
|
|
143
|
+
function buildCollecthookPayload(variableName, hookType, category, hookExpression) {
|
|
144
|
+
return `collecthook({ variableName: '${variableName}', hookType: '${hookType}', category: '${category}', data: ${hookExpression} });`;
|
|
175
145
|
}
|
|
176
146
|
function hasCollecthookAfterByVariableId(code, fromIndex, variableId, maxLookahead = 600) {
|
|
177
147
|
const lookahead = code.slice(fromIndex, fromIndex + maxLookahead);
|
|
@@ -363,26 +333,14 @@ function createInitTask(code, body, options) {
|
|
|
363
333
|
if (hasExistingCollecthook(code, insertPos)) {
|
|
364
334
|
return null;
|
|
365
335
|
}
|
|
366
|
-
const { insertIndex, prefixNewline } = calculateInsertPosition(code, insertPos);
|
|
367
|
-
const indent = readIndent(code, insertIndex);
|
|
368
336
|
const componentArg = buildComponentArg(options?.path, exportName);
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
return { kind: "insert", pos: insertIndex, text: initLine };
|
|
337
|
+
const initStatement = ` const collecthook = ${INNER_USE_HOOK}(${componentArg});`;
|
|
338
|
+
return { kind: "insert", pos: insertPos, text: initStatement };
|
|
372
339
|
}
|
|
373
340
|
function hasExistingCollecthook(code, insertPos) {
|
|
374
341
|
const lookahead = code.slice(insertPos, insertPos + 200);
|
|
375
342
|
return /const\s+collecthook\s*=\s*useCollectHooks\s*\(/.test(lookahead);
|
|
376
343
|
}
|
|
377
|
-
function calculateInsertPosition(code, insertPos) {
|
|
378
|
-
if (code[insertPos] === "\r" && code[insertPos + 1] === "\n") {
|
|
379
|
-
return { insertIndex: insertPos + 2, prefixNewline: "" };
|
|
380
|
-
}
|
|
381
|
-
if (code[insertPos] === "\n") {
|
|
382
|
-
return { insertIndex: insertPos + 1, prefixNewline: "" };
|
|
383
|
-
}
|
|
384
|
-
return { insertIndex: insertPos, prefixNewline: "\n" };
|
|
385
|
-
}
|
|
386
344
|
function buildComponentArg(path, exportName) {
|
|
387
345
|
const rawArg = String(path ?? "");
|
|
388
346
|
const baseArg = rawArg.split("?")[0].split("#")[0];
|
|
@@ -447,19 +405,18 @@ function processVariableDeclarator(code, node, path) {
|
|
|
447
405
|
if (!range) {
|
|
448
406
|
return null;
|
|
449
407
|
}
|
|
450
|
-
const
|
|
408
|
+
const [, declEnd] = range;
|
|
451
409
|
if (isCustomHook(normalizedName)) {
|
|
452
410
|
if (hasCollecthookAfterByVariableId(code, declEnd, variableId)) {
|
|
453
411
|
return null;
|
|
454
412
|
}
|
|
455
413
|
const payload2 = buildCollecthookPayload(
|
|
456
|
-
indent,
|
|
457
414
|
variableId,
|
|
458
415
|
"customhook",
|
|
459
416
|
"VariableDeclarator",
|
|
460
417
|
variableId
|
|
461
418
|
);
|
|
462
|
-
return
|
|
419
|
+
return insertAfterStatement(code, declEnd, payload2);
|
|
463
420
|
}
|
|
464
421
|
if (!isKnownHook(normalizedName)) {
|
|
465
422
|
return null;
|
|
@@ -468,13 +425,12 @@ function processVariableDeclarator(code, node, path) {
|
|
|
468
425
|
return null;
|
|
469
426
|
}
|
|
470
427
|
const payload = buildCollecthookPayload(
|
|
471
|
-
indent,
|
|
472
428
|
variableId,
|
|
473
429
|
normalizedName,
|
|
474
430
|
"VariableDeclarator",
|
|
475
431
|
variableId
|
|
476
432
|
);
|
|
477
|
-
return
|
|
433
|
+
return insertAfterStatement(code, declEnd, payload);
|
|
478
434
|
}
|
|
479
435
|
function processExpressionStatement(code, node, currentIndex) {
|
|
480
436
|
const hookInfo = extractExpressionHookInfo(node);
|
|
@@ -490,36 +446,30 @@ function processExpressionStatement(code, node, currentIndex) {
|
|
|
490
446
|
return null;
|
|
491
447
|
}
|
|
492
448
|
const [stmtStart, stmtEnd] = stmtRange;
|
|
493
|
-
const lineStart = findLineStart(code, stmtStart);
|
|
494
|
-
const indent = readIndent(code, lineStart);
|
|
495
449
|
if (isKnownHook(normalizedName)) {
|
|
496
450
|
if (hasCollecthookAfterByVariableName(code, stmtEnd, normalizedName)) {
|
|
497
451
|
return null;
|
|
498
452
|
}
|
|
499
453
|
const payload = buildCollecthookPayload(
|
|
500
|
-
indent,
|
|
501
454
|
normalizedName,
|
|
502
455
|
normalizedName,
|
|
503
456
|
"expressionStatement",
|
|
504
457
|
"undefined"
|
|
505
458
|
);
|
|
506
459
|
return {
|
|
507
|
-
task:
|
|
460
|
+
task: insertAfterStatement(code, stmtEnd, payload),
|
|
508
461
|
newIndex: currentIndex
|
|
509
462
|
};
|
|
510
463
|
}
|
|
511
464
|
if (isCustomHook(normalizedName)) {
|
|
512
|
-
return convertToVariableDeclaration(code, stmtStart, stmtEnd,
|
|
465
|
+
return convertToVariableDeclaration(code, stmtStart, stmtEnd, currentIndex);
|
|
513
466
|
}
|
|
514
467
|
return null;
|
|
515
468
|
}
|
|
516
|
-
function convertToVariableDeclaration(code, stmtStart, stmtEnd,
|
|
469
|
+
function convertToVariableDeclaration(code, stmtStart, stmtEnd, currentIndex) {
|
|
517
470
|
const callSource = code.slice(stmtStart, stmtEnd);
|
|
518
471
|
const variableName = `_customhook_${currentIndex}`;
|
|
519
|
-
const declLine = `${indent}let ${variableName} = ${trimStatementSemicolon(callSource)};
|
|
520
|
-
`;
|
|
521
472
|
const payload = buildCollecthookPayload(
|
|
522
|
-
indent,
|
|
523
473
|
variableName,
|
|
524
474
|
"customhook",
|
|
525
475
|
"VariableDeclarator",
|
|
@@ -530,7 +480,7 @@ function convertToVariableDeclaration(code, stmtStart, stmtEnd, indent, currentI
|
|
|
530
480
|
kind: "replace",
|
|
531
481
|
start: stmtStart,
|
|
532
482
|
end: stmtEnd,
|
|
533
|
-
text:
|
|
483
|
+
text: `let ${variableName} = ${trimStatementSemicolon(callSource)}; ${payload}`
|
|
534
484
|
},
|
|
535
485
|
newIndex: currentIndex + 1
|
|
536
486
|
};
|
|
@@ -563,6 +513,10 @@ function extractHookCall(node) {
|
|
|
563
513
|
normalizedName: normalizeQrlHookName(hookName)
|
|
564
514
|
};
|
|
565
515
|
}
|
|
516
|
+
function insertAfterStatement(code, statementEnd, statement) {
|
|
517
|
+
const separator = code[statementEnd - 1] === ";" ? " " : "; ";
|
|
518
|
+
return { kind: "insert", pos: statementEnd, text: separator + statement };
|
|
519
|
+
}
|
|
566
520
|
function getParentRange(parent) {
|
|
567
521
|
const range = parent?.range;
|
|
568
522
|
if (!range) {
|
|
@@ -570,12 +524,6 @@ function getParentRange(parent) {
|
|
|
570
524
|
}
|
|
571
525
|
return [range[0], range[1]];
|
|
572
526
|
}
|
|
573
|
-
function getPositionInfo(code, range) {
|
|
574
|
-
const [declStart, declEnd] = range;
|
|
575
|
-
const lineStart = findLineStart(code, declStart);
|
|
576
|
-
const indent = readIndent(code, lineStart);
|
|
577
|
-
return { declStart, declEnd, indent };
|
|
578
|
-
}
|
|
579
527
|
|
|
580
528
|
// ../devtools/plugin/src/parse/parse.ts
|
|
581
529
|
function parseQwikCode(code, options) {
|
|
@@ -590,12 +538,14 @@ function parseQwikCode(code, options) {
|
|
|
590
538
|
}
|
|
591
539
|
|
|
592
540
|
// ../devtools/plugin/src/transforms/source-utils.ts
|
|
541
|
+
function prependImportIfMissing(code, importStatement) {
|
|
542
|
+
return code.includes(importStatement) ? code : `${importStatement}${code}`;
|
|
543
|
+
}
|
|
593
544
|
function injectNamedImportIfMissing(code, key, name) {
|
|
594
545
|
if (code.includes(key)) {
|
|
595
546
|
return code;
|
|
596
547
|
}
|
|
597
|
-
return `import { ${name} } from '${key}';
|
|
598
|
-
${code}`;
|
|
548
|
+
return prependImportIfMissing(code, `import { ${name} } from '${key}';`);
|
|
599
549
|
}
|
|
600
550
|
|
|
601
551
|
// ../devtools/plugin/src/transforms/component-transform.ts
|
|
@@ -1445,6 +1395,7 @@ var inspectInput = pageInput.extend({
|
|
|
1445
1395
|
includeSerializedVNodeTree: z.boolean().default(false),
|
|
1446
1396
|
offset: z.number().int().nonnegative().safe().default(0)
|
|
1447
1397
|
});
|
|
1398
|
+
var locateInput = pageInput.extend({ selector: z.string().min(1) });
|
|
1448
1399
|
|
|
1449
1400
|
// src/access.ts
|
|
1450
1401
|
function isLoopback(address) {
|
|
@@ -1473,6 +1424,11 @@ function qwikMcp() {
|
|
|
1473
1424
|
}
|
|
1474
1425
|
};
|
|
1475
1426
|
const router = () => server.config.plugins.find((plugin) => plugin.name === "vite-plugin-qwik-router")?.api;
|
|
1427
|
+
const pageToolInputs = {
|
|
1428
|
+
get_dev_errors: inspectInput,
|
|
1429
|
+
inspect_page: inspectInput,
|
|
1430
|
+
locate_element: locateInput
|
|
1431
|
+
};
|
|
1476
1432
|
const call = async (name, args) => {
|
|
1477
1433
|
if (name === "get_project_info") {
|
|
1478
1434
|
return {
|
|
@@ -1493,10 +1449,10 @@ function qwikMcp() {
|
|
|
1493
1449
|
})) ?? []
|
|
1494
1450
|
};
|
|
1495
1451
|
}
|
|
1496
|
-
if (
|
|
1452
|
+
if (!Object.hasOwn(pageToolInputs, name)) {
|
|
1497
1453
|
throw new Error("Unknown MCP tool.");
|
|
1498
1454
|
}
|
|
1499
|
-
args =
|
|
1455
|
+
args = pageToolInputs[name].parse(args);
|
|
1500
1456
|
const matches = [...pages.values()].filter((page) => !args.url || page.url === args.url);
|
|
1501
1457
|
if (!matches.length) {
|
|
1502
1458
|
throw new Error("No connected page. Open the requested Qwik URL in a local browser.");
|
|
@@ -1545,6 +1501,7 @@ function qwikMcp() {
|
|
|
1545
1501
|
return createHookRuntime() + createVNodeRuntime() + await readFile(new URL("../dist/browser.js", import.meta.url), "utf8");
|
|
1546
1502
|
}
|
|
1547
1503
|
},
|
|
1504
|
+
// Runs before the optimizer, which has no input sourcemap: never add or remove source lines.
|
|
1548
1505
|
transform(code, id) {
|
|
1549
1506
|
if (/\.[jt]sx(?:\?|$)/.test(id) && !id.includes("/node_modules/") && code.includes("component$")) {
|
|
1550
1507
|
return { code: transformComponentFile(code, id), map: null };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qwik.dev/mcp",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.3",
|
|
4
4
|
"description": "Local MCP tools for Qwik development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"typescript": "5.9.3",
|
|
31
31
|
"vite": "8.2.1",
|
|
32
32
|
"vitest": "5.0.0",
|
|
33
|
-
"@qwik.dev/core": "2.0.0-rc.
|
|
34
|
-
"@qwik.dev/router": "2.0.0-rc.
|
|
33
|
+
"@qwik.dev/core": "2.0.0-rc.3",
|
|
34
|
+
"@qwik.dev/router": "2.0.0-rc.3"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"vite": ">=8 <9",
|
|
38
|
-
"@qwik.dev/core": "2.0.0-rc.
|
|
38
|
+
"@qwik.dev/core": "2.0.0-rc.3"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=22.18.0"
|