@mapomodule/mcp 0.0.0-stage → 1.0.0-beta.1
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 +479 -2
- package/bin/mapo-mcp.mjs +3 -0
- package/dist/build.d.mts +18 -0
- package/dist/build.d.ts +18 -0
- package/dist/build.mjs +351 -0
- package/dist/cli.d.mts +7 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.mjs +263 -0
- package/dist/index.d.mts +68 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.mjs +1 -0
- package/dist/knowledge/api.json +1 -0
- package/dist/knowledge/docs.json +1 -0
- package/dist/module.d.mts +16 -0
- package/dist/module.d.ts +16 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +121 -0
- package/dist/runtime/core/doctor.d.ts +0 -0
- package/dist/runtime/core/doctor.js +128 -0
- package/dist/runtime/core/indexer.d.ts +0 -0
- package/dist/runtime/core/indexer.js +193 -0
- package/dist/runtime/core/knowledge.d.ts +0 -0
- package/dist/runtime/core/knowledge.js +76 -0
- package/dist/runtime/core/openapi.d.ts +0 -0
- package/dist/runtime/core/openapi.js +229 -0
- package/dist/runtime/core/prompts.d.ts +0 -0
- package/dist/runtime/core/prompts.js +108 -0
- package/dist/runtime/core/recipes.d.ts +0 -0
- package/dist/runtime/core/recipes.js +297 -0
- package/dist/runtime/core/resources.d.ts +0 -0
- package/dist/runtime/core/resources.js +88 -0
- package/dist/runtime/core/scaffold/fields.d.ts +0 -0
- package/dist/runtime/core/scaffold/fields.js +64 -0
- package/dist/runtime/core/scaffold/index.d.ts +0 -0
- package/dist/runtime/core/scaffold/index.js +74 -0
- package/dist/runtime/core/scaffold/templates.d.ts +0 -0
- package/dist/runtime/core/scaffold/templates.js +349 -0
- package/dist/runtime/core/schema-source.d.ts +0 -0
- package/dist/runtime/core/schema-source.js +70 -0
- package/dist/runtime/core/search.d.ts +0 -0
- package/dist/runtime/core/search.js +173 -0
- package/dist/runtime/core/tokenize.d.ts +0 -0
- package/dist/runtime/core/tokenize.js +96 -0
- package/dist/runtime/core/tool-spec.d.ts +0 -0
- package/dist/runtime/core/tool-spec.js +3 -0
- package/dist/runtime/core/tools/api.d.ts +0 -0
- package/dist/runtime/core/tools/api.js +192 -0
- package/dist/runtime/core/tools/app.d.ts +0 -0
- package/dist/runtime/core/tools/app.js +141 -0
- package/dist/runtime/core/tools/backend.d.ts +0 -0
- package/dist/runtime/core/tools/backend.js +143 -0
- package/dist/runtime/core/tools/docs.d.ts +0 -0
- package/dist/runtime/core/tools/docs.js +150 -0
- package/dist/runtime/core/tools/scaffold.d.ts +0 -0
- package/dist/runtime/core/tools/scaffold.js +127 -0
- package/dist/runtime/core/types.d.ts +0 -0
- package/dist/runtime/core/types.js +0 -0
- package/dist/runtime/core/write.d.ts +0 -0
- package/dist/runtime/core/write.js +53 -0
- package/dist/runtime/mcp/handlers/mapo/index.js +13 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/crud-page.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/custom-field.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/debug-form.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/migrate-v1.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/prompts/theme.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/resources/app-manifest.js +19 -0
- package/dist/runtime/mcp/handlers/mapo/resources/docs.js +34 -0
- package/dist/runtime/mcp/handlers/mapo/resources/fields.js +34 -0
- package/dist/runtime/mcp/handlers/mapo/resources/knowledge-index.js +22 -0
- package/dist/runtime/mcp/handlers/mapo/tools/backend-schema.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/component-api.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/composable-api.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/doctor.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/get-doc.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/inspect-app.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/list-field-types.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/list-recipes.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/scaffold.js +3 -0
- package/dist/runtime/mcp/handlers/mapo/tools/search-docs.js +3 -0
- package/dist/runtime/nitro/context.d.ts +0 -0
- package/dist/runtime/nitro/context.js +21 -0
- package/dist/runtime/nitro/to-mcp-prompt.d.ts +0 -0
- package/dist/runtime/nitro/to-mcp-prompt.js +23 -0
- package/dist/runtime/nitro/to-mcp-tool.d.ts +0 -0
- package/dist/runtime/nitro/to-mcp-tool.js +28 -0
- package/dist/runtime/types/virtual-modules.d.ts +6 -0
- package/dist/types.d.mts +9 -0
- package/package.json +73 -4
- package/src/__tests__/cli.test.ts +121 -0
- package/src/__tests__/doctor.test.ts +145 -0
- package/src/__tests__/fixtures/drf-schema.json +142 -0
- package/src/__tests__/fixtures.ts +198 -0
- package/src/__tests__/indexer.test.ts +114 -0
- package/src/__tests__/knowledge.test.ts +209 -0
- package/src/__tests__/openapi.test.ts +256 -0
- package/src/__tests__/recipes.test.ts +44 -0
- package/src/__tests__/resources.test.ts +69 -0
- package/src/__tests__/scaffold.test.ts +153 -0
- package/src/__tests__/search.test.ts +105 -0
- package/src/__tests__/tools.test.ts +226 -0
- package/src/__tests__/write.test.ts +134 -0
- package/src/build/extract-components.ts +135 -0
- package/src/build/extract-composables.ts +125 -0
- package/src/build/extract-fields.ts +250 -0
- package/src/build/index.ts +103 -0
- package/src/cli.ts +364 -0
- package/src/index.ts +65 -0
- package/src/module.ts +214 -0
- package/src/runtime/core/doctor.ts +204 -0
- package/src/runtime/core/indexer.ts +279 -0
- package/src/runtime/core/knowledge.ts +121 -0
- package/src/runtime/core/openapi.ts +417 -0
- package/src/runtime/core/prompts.ts +150 -0
- package/src/runtime/core/recipes.ts +361 -0
- package/src/runtime/core/resources.ts +144 -0
- package/src/runtime/core/scaffold/fields.ts +127 -0
- package/src/runtime/core/scaffold/index.ts +120 -0
- package/src/runtime/core/scaffold/templates.ts +394 -0
- package/src/runtime/core/schema-source.ts +123 -0
- package/src/runtime/core/search.ts +282 -0
- package/src/runtime/core/tokenize.ts +146 -0
- package/src/runtime/core/tool-spec.ts +74 -0
- package/src/runtime/core/tools/api.ts +300 -0
- package/src/runtime/core/tools/app.ts +200 -0
- package/src/runtime/core/tools/backend.ts +197 -0
- package/src/runtime/core/tools/docs.ts +215 -0
- package/src/runtime/core/tools/scaffold.ts +176 -0
- package/src/runtime/core/types.ts +133 -0
- package/src/runtime/core/write.ts +119 -0
- package/src/runtime/mcp/handlers/mapo/index.ts +22 -0
- package/src/runtime/mcp/handlers/mapo/prompts/crud-page.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/custom-field.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/debug-form.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/migrate-v1.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/prompts/theme.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/resources/app-manifest.ts +28 -0
- package/src/runtime/mcp/handlers/mapo/resources/docs.ts +41 -0
- package/src/runtime/mcp/handlers/mapo/resources/fields.ts +37 -0
- package/src/runtime/mcp/handlers/mapo/resources/knowledge-index.ts +24 -0
- package/src/runtime/mcp/handlers/mapo/tools/backend-schema.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/component-api.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/composable-api.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/doctor.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/get-doc.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/inspect-app.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/list-field-types.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/list-recipes.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/scaffold.ts +4 -0
- package/src/runtime/mcp/handlers/mapo/tools/search-docs.ts +4 -0
- package/src/runtime/nitro/context.ts +41 -0
- package/src/runtime/nitro/to-mcp-prompt.ts +30 -0
- package/src/runtime/nitro/to-mcp-tool.ts +35 -0
- package/src/runtime/types/virtual-modules.d.ts +6 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { tokenize } from "./tokenize.js";
|
|
2
|
+
const K1 = 1.5;
|
|
3
|
+
const B = 0.75;
|
|
4
|
+
const SNIPPET_CHARS = 360;
|
|
5
|
+
const PAGE_CONTEXT_WEIGHT = 0.2;
|
|
6
|
+
const TITLE_BOOST_STEP = 0.15;
|
|
7
|
+
const TITLE_BOOST_CAP = 1.5;
|
|
8
|
+
const MAX_HITS_PER_PAGE = 2;
|
|
9
|
+
const REFERENCE_PENALTY = 0.75;
|
|
10
|
+
const REFERENCE_INTENT = /\b(prop|props|slot|slots|emit|emits|event|events|api|signature|reference|type)\b/i;
|
|
11
|
+
const GENERIC_IDENTITY_TOKENS = /* @__PURE__ */ new Set([
|
|
12
|
+
"api",
|
|
13
|
+
"index",
|
|
14
|
+
"doc",
|
|
15
|
+
"overview",
|
|
16
|
+
"reference",
|
|
17
|
+
"uikit",
|
|
18
|
+
"modul",
|
|
19
|
+
"module",
|
|
20
|
+
"howto",
|
|
21
|
+
"guid",
|
|
22
|
+
"guide",
|
|
23
|
+
"migrat",
|
|
24
|
+
"migration",
|
|
25
|
+
"md"
|
|
26
|
+
]);
|
|
27
|
+
function matchesFilters(chunk, options) {
|
|
28
|
+
if (options.section) {
|
|
29
|
+
const wanted = options.section.toLowerCase();
|
|
30
|
+
if (chunk.section !== wanted && chunk.group !== wanted) return false;
|
|
31
|
+
}
|
|
32
|
+
if (options.pkg) {
|
|
33
|
+
const wanted = options.pkg.toLowerCase().replace(/^@mapomodule\//, "");
|
|
34
|
+
if (!chunk.pkg || !chunk.pkg.toLowerCase().includes(wanted)) return false;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
export function extractSnippet(text, query) {
|
|
39
|
+
const words = query.toLowerCase().split(/[^a-z0-9]+/).filter((word) => word.length > 2);
|
|
40
|
+
const haystack = text.toLowerCase();
|
|
41
|
+
let best = -1;
|
|
42
|
+
for (const word of words) {
|
|
43
|
+
const at = haystack.indexOf(word);
|
|
44
|
+
if (at !== -1 && (best === -1 || at < best)) best = at;
|
|
45
|
+
}
|
|
46
|
+
if (best === -1) {
|
|
47
|
+
return text.length > SNIPPET_CHARS ? `${text.slice(0, SNIPPET_CHARS).trimEnd()}\u2026` : text;
|
|
48
|
+
}
|
|
49
|
+
const start = Math.max(0, best - Math.floor(SNIPPET_CHARS / 3));
|
|
50
|
+
const end = Math.min(text.length, start + SNIPPET_CHARS);
|
|
51
|
+
const slice = text.slice(start, end).trim();
|
|
52
|
+
return `${start > 0 ? "\u2026" : ""}${slice}${end < text.length ? "\u2026" : ""}`;
|
|
53
|
+
}
|
|
54
|
+
export function searchDocs(knowledge, query, options = {}) {
|
|
55
|
+
const { chunks, index } = knowledge;
|
|
56
|
+
const limit = options.limit ?? 5;
|
|
57
|
+
const queryTerms = tokenize(query);
|
|
58
|
+
if (!queryTerms.length || !index.total) return [];
|
|
59
|
+
const scores = /* @__PURE__ */ new Map();
|
|
60
|
+
const seenTerms = /* @__PURE__ */ new Set();
|
|
61
|
+
for (const term of queryTerms) {
|
|
62
|
+
if (seenTerms.has(term)) continue;
|
|
63
|
+
seenTerms.add(term);
|
|
64
|
+
const postings = index.terms[term];
|
|
65
|
+
if (!postings) continue;
|
|
66
|
+
const idf = Math.max(
|
|
67
|
+
0.05,
|
|
68
|
+
Math.log(
|
|
69
|
+
1 + (index.total - postings.length + 0.5) / (postings.length + 0.5)
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
for (const [chunkIndex, frequency] of postings) {
|
|
73
|
+
const chunk = chunks[chunkIndex];
|
|
74
|
+
if (!chunk || !matchesFilters(chunk, options)) continue;
|
|
75
|
+
const length = index.lengths[chunkIndex] ?? 0;
|
|
76
|
+
const norm = 1 - B + B * length / (index.avgLength || 1);
|
|
77
|
+
const score = idf * (frequency * (K1 + 1) / (frequency + K1 * norm));
|
|
78
|
+
scores.set(chunkIndex, (scores.get(chunkIndex) ?? 0) + score);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const pageTotals = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const [chunkIndex, score] of scores) {
|
|
83
|
+
const { path } = chunks[chunkIndex];
|
|
84
|
+
pageTotals.set(path, (pageTotals.get(path) ?? 0) + score);
|
|
85
|
+
}
|
|
86
|
+
const phrase = query.trim().toLowerCase();
|
|
87
|
+
const distinctTerms = [...seenTerms];
|
|
88
|
+
const wantsReference = REFERENCE_INTENT.test(query);
|
|
89
|
+
const ranked = [...scores.entries()].map(([chunkIndex, score]) => {
|
|
90
|
+
const chunk = chunks[chunkIndex];
|
|
91
|
+
let final = score + PAGE_CONTEXT_WEIGHT * ((pageTotals.get(chunk.path) ?? score) - score);
|
|
92
|
+
const identity = new Set(
|
|
93
|
+
tokenize(`${chunk.title} ${chunk.path.replace(/[/.\-_]/g, " ")}`)
|
|
94
|
+
);
|
|
95
|
+
const matched = distinctTerms.filter(
|
|
96
|
+
(term) => identity.has(term) && !GENERIC_IDENTITY_TOKENS.has(term)
|
|
97
|
+
).length;
|
|
98
|
+
if (matched)
|
|
99
|
+
final *= Math.min(TITLE_BOOST_CAP, 1 + TITLE_BOOST_STEP * matched);
|
|
100
|
+
if (chunk.kind === "reference" && !wantsReference)
|
|
101
|
+
final *= REFERENCE_PENALTY;
|
|
102
|
+
if (phrase.length > 6 && chunk.text.toLowerCase().includes(phrase))
|
|
103
|
+
final *= 1.5;
|
|
104
|
+
return [chunkIndex, final];
|
|
105
|
+
});
|
|
106
|
+
const perPage = /* @__PURE__ */ new Map();
|
|
107
|
+
return ranked.sort((a, b) => b[1] - a[1]).filter(([chunkIndex]) => {
|
|
108
|
+
const { path } = chunks[chunkIndex];
|
|
109
|
+
const used = perPage.get(path) ?? 0;
|
|
110
|
+
if (used >= MAX_HITS_PER_PAGE) return false;
|
|
111
|
+
perPage.set(path, used + 1);
|
|
112
|
+
return true;
|
|
113
|
+
}).slice(0, limit).map(([chunkIndex, score]) => {
|
|
114
|
+
const chunk = chunks[chunkIndex];
|
|
115
|
+
return {
|
|
116
|
+
id: chunk.id,
|
|
117
|
+
path: chunk.path,
|
|
118
|
+
section: chunk.section,
|
|
119
|
+
title: chunk.title,
|
|
120
|
+
heading: chunk.heading,
|
|
121
|
+
anchor: chunk.anchor,
|
|
122
|
+
score: Number(score.toFixed(3)),
|
|
123
|
+
snippet: extractSnippet(chunk.text, query),
|
|
124
|
+
tags: chunk.tags.slice(0, 8)
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
export function getDoc(knowledge, path, options = {}) {
|
|
129
|
+
const wantedPath = path.replace(/^\/+/, "").replace(/^docs\//, "");
|
|
130
|
+
const pageChunks = knowledge.chunks.filter(
|
|
131
|
+
(chunk) => chunk.path === wantedPath
|
|
132
|
+
);
|
|
133
|
+
if (!pageChunks.length) return null;
|
|
134
|
+
const maxChars = options.maxChars ?? 8e3;
|
|
135
|
+
const headings = [...new Set(pageChunks.map((chunk) => chunk.heading))];
|
|
136
|
+
let selected = pageChunks;
|
|
137
|
+
if (options.heading) {
|
|
138
|
+
const wanted = options.heading.toLowerCase();
|
|
139
|
+
selected = pageChunks.filter(
|
|
140
|
+
(chunk) => chunk.heading.toLowerCase() === wanted || chunk.anchor === wanted.replace(/^#/, "")
|
|
141
|
+
);
|
|
142
|
+
if (!selected.length) selected = pageChunks;
|
|
143
|
+
}
|
|
144
|
+
const body = selected.map(
|
|
145
|
+
(chunk) => chunk.level > 1 ? `${"#".repeat(chunk.level)} ${chunk.heading}
|
|
146
|
+
|
|
147
|
+
${chunk.text}` : chunk.text
|
|
148
|
+
).join("\n\n");
|
|
149
|
+
return {
|
|
150
|
+
path: wantedPath,
|
|
151
|
+
title: pageChunks[0].title,
|
|
152
|
+
headings,
|
|
153
|
+
content: body.length > maxChars ? `${body.slice(0, maxChars)}
|
|
154
|
+
|
|
155
|
+
\u2026[truncated]` : body,
|
|
156
|
+
truncated: body.length > maxChars
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export function listDocs(knowledge) {
|
|
160
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
161
|
+
for (const chunk of knowledge.chunks) {
|
|
162
|
+
const entry = byPath.get(chunk.path) ?? {
|
|
163
|
+
path: chunk.path,
|
|
164
|
+
title: chunk.title,
|
|
165
|
+
section: chunk.section,
|
|
166
|
+
headings: []
|
|
167
|
+
};
|
|
168
|
+
if (chunk.level > 1 && !entry.headings.includes(chunk.heading))
|
|
169
|
+
entry.headings.push(chunk.heading);
|
|
170
|
+
byPath.set(chunk.path, entry);
|
|
171
|
+
}
|
|
172
|
+
return [...byPath.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
173
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const STOPWORDS = /* @__PURE__ */ new Set([
|
|
2
|
+
"a",
|
|
3
|
+
"an",
|
|
4
|
+
"and",
|
|
5
|
+
"are",
|
|
6
|
+
"as",
|
|
7
|
+
"at",
|
|
8
|
+
"be",
|
|
9
|
+
"but",
|
|
10
|
+
"by",
|
|
11
|
+
"can",
|
|
12
|
+
"do",
|
|
13
|
+
"does",
|
|
14
|
+
"for",
|
|
15
|
+
"from",
|
|
16
|
+
"how",
|
|
17
|
+
"i",
|
|
18
|
+
"if",
|
|
19
|
+
"in",
|
|
20
|
+
"into",
|
|
21
|
+
"is",
|
|
22
|
+
"it",
|
|
23
|
+
"its",
|
|
24
|
+
"me",
|
|
25
|
+
"my",
|
|
26
|
+
"of",
|
|
27
|
+
"on",
|
|
28
|
+
"or",
|
|
29
|
+
"our",
|
|
30
|
+
"so",
|
|
31
|
+
"that",
|
|
32
|
+
"the",
|
|
33
|
+
"their",
|
|
34
|
+
"them",
|
|
35
|
+
"then",
|
|
36
|
+
"there",
|
|
37
|
+
"these",
|
|
38
|
+
"they",
|
|
39
|
+
"this",
|
|
40
|
+
"to",
|
|
41
|
+
"was",
|
|
42
|
+
"we",
|
|
43
|
+
"were",
|
|
44
|
+
"what",
|
|
45
|
+
"when",
|
|
46
|
+
"where",
|
|
47
|
+
"which",
|
|
48
|
+
"who",
|
|
49
|
+
"will",
|
|
50
|
+
"with",
|
|
51
|
+
"you",
|
|
52
|
+
"your"
|
|
53
|
+
]);
|
|
54
|
+
const NO_STEM_SUFFIX = /(?:ss|us|is|os)$/;
|
|
55
|
+
const SUFFIX_RULES = [
|
|
56
|
+
[/ation$/, "at"],
|
|
57
|
+
[/ition$/, "it"],
|
|
58
|
+
[/ing$/, ""],
|
|
59
|
+
[/edly$/, ""],
|
|
60
|
+
[/ed$/, ""],
|
|
61
|
+
[/ly$/, ""],
|
|
62
|
+
[/e$/, ""]
|
|
63
|
+
];
|
|
64
|
+
const MIN_STEM_LENGTH = 4;
|
|
65
|
+
function splitIdentifier(word) {
|
|
66
|
+
const parts = word.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).filter(Boolean);
|
|
67
|
+
return parts.length > 1 ? parts : [];
|
|
68
|
+
}
|
|
69
|
+
export function stem(word) {
|
|
70
|
+
let result = word;
|
|
71
|
+
if (result.length > 3 && result.endsWith("s") && !NO_STEM_SUFFIX.test(result)) {
|
|
72
|
+
result = result.endsWith("ies") ? `${result.slice(0, -3)}y` : result.endsWith("es") && result.length > 4 ? result.slice(0, -2) : result.slice(0, -1);
|
|
73
|
+
}
|
|
74
|
+
for (const [pattern, replacement] of SUFFIX_RULES) {
|
|
75
|
+
if (!pattern.test(result)) continue;
|
|
76
|
+
const candidate = result.replace(pattern, replacement);
|
|
77
|
+
if (candidate.length >= MIN_STEM_LENGTH) return candidate;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
export function tokenize(input) {
|
|
83
|
+
const out = [];
|
|
84
|
+
const words = input.match(/[A-Za-z][A-Za-z0-9]*|[0-9]+/g) ?? [];
|
|
85
|
+
for (const word of words) {
|
|
86
|
+
const lower = word.toLowerCase();
|
|
87
|
+
if (lower.length < 2) continue;
|
|
88
|
+
if (!STOPWORDS.has(lower)) out.push(stem(lower));
|
|
89
|
+
for (const part of splitIdentifier(word)) {
|
|
90
|
+
const lowerPart = part.toLowerCase();
|
|
91
|
+
if (lowerPart.length < 2 || STOPWORDS.has(lowerPart)) continue;
|
|
92
|
+
out.push(stem(lowerPart));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { defineMapoTool } from "../tool-spec.js";
|
|
3
|
+
const READ_ONLY = {
|
|
4
|
+
readOnlyHint: true,
|
|
5
|
+
destructiveHint: false,
|
|
6
|
+
idempotentHint: true,
|
|
7
|
+
openWorldHint: false
|
|
8
|
+
};
|
|
9
|
+
function renderMembers(title, members) {
|
|
10
|
+
if (!members.length) return `**${title}**: none
|
|
11
|
+
`;
|
|
12
|
+
const lines = members.map((member) => {
|
|
13
|
+
const type = member.type ? `: \`${member.type}\`` : "";
|
|
14
|
+
const required = member.required ? " **required**" : "";
|
|
15
|
+
const fallback = member.default !== void 0 ? ` (default \`${member.default}\`)` : "";
|
|
16
|
+
const description = member.description ? ` \u2014 ${member.description}` : "";
|
|
17
|
+
return `- \`${member.name}\`${type}${required}${fallback}${description}`;
|
|
18
|
+
});
|
|
19
|
+
return `**${title}** (${members.length})
|
|
20
|
+
${lines.join("\n")}
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
function renderDocs(docs) {
|
|
24
|
+
return docs.length ? `
|
|
25
|
+
Docs: ${docs.map((doc) => `\`${doc}\``).join(", ")}
|
|
26
|
+
` : "";
|
|
27
|
+
}
|
|
28
|
+
function findByName(entries, name) {
|
|
29
|
+
const needle = name.toLowerCase();
|
|
30
|
+
return entries.find((entry) => entry.name.toLowerCase() === needle) ?? entries.find((entry) => entry.name.toLowerCase() === `mapo${needle}`) ?? entries.find((entry) => entry.name.toLowerCase().includes(needle));
|
|
31
|
+
}
|
|
32
|
+
function suggest(entries, name, limit = 8) {
|
|
33
|
+
const needle = name.toLowerCase();
|
|
34
|
+
const close = entries.filter((entry) => {
|
|
35
|
+
const candidate = entry.name.toLowerCase();
|
|
36
|
+
return [...needle].some((char) => candidate.includes(char)) && candidate.length > 0;
|
|
37
|
+
}).slice(0, limit).map((entry) => entry.name);
|
|
38
|
+
return close.length ? `
|
|
39
|
+
|
|
40
|
+
Available: ${close.join(", ")}` : "";
|
|
41
|
+
}
|
|
42
|
+
function renderComponent(component, include) {
|
|
43
|
+
const wanted = include?.length ? new Set(include) : null;
|
|
44
|
+
const sections = [];
|
|
45
|
+
if (!wanted || wanted.has("props"))
|
|
46
|
+
sections.push(renderMembers("Props", component.props));
|
|
47
|
+
if (!wanted || wanted.has("events"))
|
|
48
|
+
sections.push(renderMembers("Events", component.events));
|
|
49
|
+
if (!wanted || wanted.has("slots"))
|
|
50
|
+
sections.push(renderMembers("Slots", component.slots));
|
|
51
|
+
if ((!wanted || wanted.has("exposed")) && component.exposed.length) {
|
|
52
|
+
sections.push(renderMembers("Exposed", component.exposed));
|
|
53
|
+
}
|
|
54
|
+
return `# ${component.name}
|
|
55
|
+
package: \`${component.pkg}\` \xB7 source: \`${component.file}\`
|
|
56
|
+
` + (component.description ? `
|
|
57
|
+
${component.description}
|
|
58
|
+
` : "") + `
|
|
59
|
+
${sections.join("\n")}` + renderDocs(component.docs);
|
|
60
|
+
}
|
|
61
|
+
export const componentApiTool = defineMapoTool({
|
|
62
|
+
name: "mapo_component_api",
|
|
63
|
+
title: "Mapo component API",
|
|
64
|
+
description: "Props, events, slots and exposed methods of a Mapo component, extracted from its source (not from the docs, which can lag behind). Call this before using any Mapo* component; omit `name` filters to see what exists.",
|
|
65
|
+
inputSchema: {
|
|
66
|
+
name: z.string().describe(
|
|
67
|
+
"Component name, e.g. 'MapoList'. Partial names work ('list', 'detail')."
|
|
68
|
+
),
|
|
69
|
+
include: z.array(z.enum(["props", "events", "slots", "exposed"])).optional().describe("Limit the response to these sections")
|
|
70
|
+
},
|
|
71
|
+
annotations: READ_ONLY,
|
|
72
|
+
inputExamples: [
|
|
73
|
+
{ name: "MapoList" },
|
|
74
|
+
{ name: "MapoDetail", include: ["slots"] }
|
|
75
|
+
],
|
|
76
|
+
run: (args, context) => {
|
|
77
|
+
const { components } = context.api();
|
|
78
|
+
const component = findByName(components, args.name);
|
|
79
|
+
if (!component) {
|
|
80
|
+
return `No Mapo component matches "${args.name}".` + suggest(components, args.name) + `
|
|
81
|
+
|
|
82
|
+
${components.length} components are available; ask for one by name.`;
|
|
83
|
+
}
|
|
84
|
+
return renderComponent(component, args.include);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
function exampleDescriptor(field) {
|
|
88
|
+
const requiredAttrs = field.attrs.filter((attr) => attr.required);
|
|
89
|
+
const attrs = requiredAttrs.length ? `, attrs: { ${requiredAttrs.map((attr) => `${attr.name}: \u2026`).join(", ")} }` : "";
|
|
90
|
+
return `{ key: "\u2026", type: "${field.type}", label: "\u2026"${attrs} }`;
|
|
91
|
+
}
|
|
92
|
+
function renderFieldType(field, common) {
|
|
93
|
+
const defaults = field.defaultAttrs ? `registry defaults: \`${JSON.stringify(field.defaultAttrs)}\`
|
|
94
|
+
` : "";
|
|
95
|
+
return `# Field type \`${field.type}\`
|
|
96
|
+
` + (field.component ? `component: \`${field.component}\`` : "component: (unmapped)") + (field.descriptor ? ` \xB7 descriptor: \`${field.descriptor}\`` : "") + (field.hasAccessor ? " \xB7 has a default get/set accessor" : "") + "\n" + defaults + (field.description ? `
|
|
97
|
+
${field.description}
|
|
98
|
+
` : "") + `
|
|
99
|
+
\`\`\`ts
|
|
100
|
+
${exampleDescriptor(field)}
|
|
101
|
+
\`\`\`
|
|
102
|
+
|
|
103
|
+
` + renderMembers("attrs", field.attrs) + `
|
|
104
|
+
Every descriptor also accepts: ${common.map((member) => `\`${member.name}\``).join(", ")}. Call mapo_list_field_types with no argument for the full list of types.` + renderDocs(field.docs);
|
|
105
|
+
}
|
|
106
|
+
export const fieldTypesTool = defineMapoTool({
|
|
107
|
+
name: "mapo_list_field_types",
|
|
108
|
+
title: "Mapo form field types",
|
|
109
|
+
description: "The form field registry: every `type` a FieldDescriptor accepts, the component behind it, and the exact `attrs` it takes \u2014 read from source. Use this before writing any field descriptor; never invent a field type or an attr.",
|
|
110
|
+
inputSchema: {
|
|
111
|
+
type: z.string().optional().describe(
|
|
112
|
+
"Field type to detail, e.g. 'select'. Omit to list every type."
|
|
113
|
+
)
|
|
114
|
+
},
|
|
115
|
+
annotations: READ_ONLY,
|
|
116
|
+
inputExamples: [{}, { type: "repeater" }],
|
|
117
|
+
run: (args, context) => {
|
|
118
|
+
const { fieldTypes, fieldCommon } = context.api();
|
|
119
|
+
if (args.type) {
|
|
120
|
+
const needle = args.type.toLowerCase();
|
|
121
|
+
const field = fieldTypes.find(
|
|
122
|
+
(entry) => entry.type.toLowerCase() === needle
|
|
123
|
+
);
|
|
124
|
+
if (!field) {
|
|
125
|
+
return `No field type "${args.type}". Available: ${fieldTypes.map((entry) => entry.type).join(", ")}.
|
|
126
|
+
|
|
127
|
+
Custom types are registered with defineFormField() \u2014 see uikit/form/registry.md.`;
|
|
128
|
+
}
|
|
129
|
+
return renderFieldType(field, fieldCommon);
|
|
130
|
+
}
|
|
131
|
+
const lines = fieldTypes.map((field) => {
|
|
132
|
+
const attrs = field.attrs.length ? ` \u2014 attrs: ${field.attrs.map((attr) => attr.name).join(", ")}` : "";
|
|
133
|
+
return `- \`${field.type}\`${field.component ? ` \u2192 ${field.component}` : ""}${attrs}`;
|
|
134
|
+
});
|
|
135
|
+
return `${fieldTypes.length} registered field types:
|
|
136
|
+
|
|
137
|
+
${lines.join("\n")}
|
|
138
|
+
|
|
139
|
+
Shared descriptor properties: ${fieldCommon.map((member) => `\`${member.name}\``).join(", ")}.
|
|
140
|
+
Call mapo_list_field_types({ type }) for the full contract of one type.`;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
function renderComposable(composable) {
|
|
144
|
+
return `# ${composable.name}
|
|
145
|
+
package: \`${composable.pkg}\` \xB7 source: \`${composable.file}\` \xB7 auto-imported
|
|
146
|
+
` + (composable.description ? `
|
|
147
|
+
${composable.description}
|
|
148
|
+
` : "") + (composable.signature ? `
|
|
149
|
+
\`\`\`ts
|
|
150
|
+
${composable.name}: ${composable.signature}
|
|
151
|
+
\`\`\`
|
|
152
|
+
` : "") + renderDocs(composable.docs);
|
|
153
|
+
}
|
|
154
|
+
export const composableApiTool = defineMapoTool({
|
|
155
|
+
name: "mapo_composable_api",
|
|
156
|
+
title: "Mapo composables",
|
|
157
|
+
description: "The composables and stores Mapo auto-imports into an app (useCrud, useMapoAuth, useMapo, useMediaStore\u2026), with their real signatures. Omit `name` to list everything available.",
|
|
158
|
+
inputSchema: {
|
|
159
|
+
name: z.string().optional().describe("Composable name, e.g. 'useCrud'. Partial names work.")
|
|
160
|
+
},
|
|
161
|
+
annotations: READ_ONLY,
|
|
162
|
+
inputExamples: [{}, { name: "useCrud" }],
|
|
163
|
+
run: (args, context) => {
|
|
164
|
+
const { composables } = context.api();
|
|
165
|
+
if (args.name) {
|
|
166
|
+
const composable = findByName(composables, args.name);
|
|
167
|
+
if (!composable) {
|
|
168
|
+
return `No auto-imported composable matches "${args.name}".${suggest(composables, args.name)}`;
|
|
169
|
+
}
|
|
170
|
+
return renderComposable(composable);
|
|
171
|
+
}
|
|
172
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
173
|
+
for (const composable of composables) {
|
|
174
|
+
const list = byPackage.get(composable.pkg) ?? [];
|
|
175
|
+
list.push(composable.name);
|
|
176
|
+
byPackage.set(composable.pkg, list);
|
|
177
|
+
}
|
|
178
|
+
const sections = [...byPackage.entries()].map(
|
|
179
|
+
([pkg, names]) => `**${pkg}**: ${names.join(", ")}`
|
|
180
|
+
);
|
|
181
|
+
return `${composables.length} auto-imported composables:
|
|
182
|
+
|
|
183
|
+
${sections.join("\n")}
|
|
184
|
+
|
|
185
|
+
Call mapo_composable_api({ name }) for a signature.`;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
export const apiTools = [
|
|
189
|
+
componentApiTool,
|
|
190
|
+
fieldTypesTool,
|
|
191
|
+
composableApiTool
|
|
192
|
+
];
|
|
File without changes
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DOCTOR_BLIND_SPOTS, runDoctor } from "../doctor.js";
|
|
3
|
+
import { defineMapoTool } from "../tool-spec.js";
|
|
4
|
+
const READ_ONLY = {
|
|
5
|
+
readOnlyHint: true,
|
|
6
|
+
destructiveHint: false,
|
|
7
|
+
idempotentHint: true,
|
|
8
|
+
openWorldHint: false
|
|
9
|
+
};
|
|
10
|
+
const NO_APP = "This tool needs the running app and is only served over HTTP.\n\nStart the dev server (`pnpm dev`) and point the client at `http://localhost:3000/mcp/mapo`. The stdio server (`mapo-mcp serve`) knows the framework and its documentation, but not the project using it.";
|
|
11
|
+
function renderModules(manifest) {
|
|
12
|
+
const installed = manifest.modules.map(
|
|
13
|
+
(module) => `- \`${module.name}\`${module.version ? ` @ ${module.version}` : ""}`
|
|
14
|
+
).join("\n");
|
|
15
|
+
return `## Installed Mapo modules
|
|
16
|
+
${installed || "- (none)"}
|
|
17
|
+
|
|
18
|
+
Declaration order in nuxt.config: ${manifest.moduleOrder.map((name) => `\`${name}\``).join(" \u2192 ") || "(none)"}
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
function renderConfig(manifest) {
|
|
22
|
+
const entries = Object.entries(manifest.config);
|
|
23
|
+
if (!entries.length) return "## Configuration\n(no public Mapo config)\n";
|
|
24
|
+
const blocks = entries.map(
|
|
25
|
+
([key, value]) => `### ${key}
|
|
26
|
+
\`\`\`json
|
|
27
|
+
${JSON.stringify(value, null, 2)}
|
|
28
|
+
\`\`\``
|
|
29
|
+
);
|
|
30
|
+
return `## Configuration (public runtime config)
|
|
31
|
+
${blocks.join("\n")}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
function renderFields(manifest) {
|
|
35
|
+
const registry = manifest.fieldTypes.filter(
|
|
36
|
+
(field) => field.source === "default"
|
|
37
|
+
);
|
|
38
|
+
const custom = manifest.fieldTypes.filter(
|
|
39
|
+
(field) => field.source === "config"
|
|
40
|
+
);
|
|
41
|
+
return `## Registered field types (${manifest.fieldTypes.length})
|
|
42
|
+
- from the registry: ${registry.map((field) => `\`${field.type}\``).join(", ") || "(none)"}
|
|
43
|
+
` + (custom.length ? `- added in nuxt.config: ${custom.map((field) => `\`${field.type}\``).join(", ")}
|
|
44
|
+
` : "") + "- types registered at runtime with `defineFormField()` are not visible here\n";
|
|
45
|
+
}
|
|
46
|
+
function renderComponents(manifest) {
|
|
47
|
+
return `## Available Mapo components (${manifest.components.length})
|
|
48
|
+
${manifest.components.map((name) => `\`${name}\``).join(", ") || "(none)"}
|
|
49
|
+
|
|
50
|
+
Ask mapo_component_api for the props of any of them.
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
function renderRoutes(manifest) {
|
|
54
|
+
const lines = manifest.routes.map((route) => `- \`${route.path}\``);
|
|
55
|
+
return `## Routes (${manifest.routes.length})
|
|
56
|
+
${lines.join("\n") || "- (none)"}
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
export const inspectAppTool = defineMapoTool({
|
|
60
|
+
name: "mapo_inspect_app",
|
|
61
|
+
title: "Inspect this Mapo app",
|
|
62
|
+
description: "Report how Mapo is actually set up in the project currently running: installed modules and versions, public Mapo configuration, registered form field types, available Mapo components, routes and locales. Call this before writing code for the project, so the code matches its real configuration instead of the defaults.",
|
|
63
|
+
inputSchema: {
|
|
64
|
+
include: z.array(
|
|
65
|
+
z.enum([
|
|
66
|
+
"modules",
|
|
67
|
+
"config",
|
|
68
|
+
"fields",
|
|
69
|
+
"components",
|
|
70
|
+
"routes",
|
|
71
|
+
"locales"
|
|
72
|
+
])
|
|
73
|
+
).optional().describe("Limit the report to these sections")
|
|
74
|
+
},
|
|
75
|
+
annotations: READ_ONLY,
|
|
76
|
+
inputExamples: [{}, { include: ["fields", "config"] }],
|
|
77
|
+
run: (args, context) => {
|
|
78
|
+
const manifest = context.manifest();
|
|
79
|
+
if (!manifest) return NO_APP;
|
|
80
|
+
const wanted = args.include?.length ? new Set(args.include) : null;
|
|
81
|
+
const want = (section) => !wanted || wanted.has(section);
|
|
82
|
+
const parts = [];
|
|
83
|
+
if (want("modules")) parts.push(renderModules(manifest));
|
|
84
|
+
if (want("config")) parts.push(renderConfig(manifest));
|
|
85
|
+
if (want("fields")) parts.push(renderFields(manifest));
|
|
86
|
+
if (want("components")) parts.push(renderComponents(manifest));
|
|
87
|
+
if (want("routes")) parts.push(renderRoutes(manifest));
|
|
88
|
+
if (want("locales")) {
|
|
89
|
+
parts.push(
|
|
90
|
+
`## Locales
|
|
91
|
+
${manifest.locales.join(", ") || "(i18n not configured)"}
|
|
92
|
+
`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return `# Mapo setup of \`${manifest.rootDir}\`
|
|
96
|
+
|
|
97
|
+
${parts.join("\n")}
|
|
98
|
+
Snapshot taken when the dev server started; restart it after changing nuxt.config.`;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
export const doctorTool = defineMapoTool({
|
|
102
|
+
name: "mapo_doctor",
|
|
103
|
+
title: "Diagnose this Mapo app",
|
|
104
|
+
description: "Check the running project for known Mapo misconfigurations \u2014 module ordering, missing login route, untouched auth endpoints, locales without catalogs, media endpoints \u2014 and return each problem with the exact fix. Run it when something behaves unexpectedly, or before shipping.",
|
|
105
|
+
inputSchema: {
|
|
106
|
+
severity: z.enum(["error", "warning", "info"]).optional().describe("Only report findings at this severity or above")
|
|
107
|
+
},
|
|
108
|
+
annotations: READ_ONLY,
|
|
109
|
+
inputExamples: [{}, { severity: "error" }],
|
|
110
|
+
run: (args, context) => {
|
|
111
|
+
const manifest = context.manifest();
|
|
112
|
+
if (!manifest) return NO_APP;
|
|
113
|
+
const threshold = { error: 0, warning: 1, info: 2 };
|
|
114
|
+
const minimum = threshold[args.severity ?? "info"];
|
|
115
|
+
const findings = runDoctor(manifest).filter(
|
|
116
|
+
(finding) => threshold[finding.severity] <= minimum
|
|
117
|
+
);
|
|
118
|
+
const blindSpots = `
|
|
119
|
+
_Not checked: ${DOCTOR_BLIND_SPOTS.join("; ")}._`;
|
|
120
|
+
if (!findings.length) {
|
|
121
|
+
return `No problem found in \`${manifest.rootDir}\`.
|
|
122
|
+
${blindSpots}`;
|
|
123
|
+
}
|
|
124
|
+
const icons = { error: "\u2716", warning: "\u25B2", info: "\u2139" };
|
|
125
|
+
const blocks = findings.map(
|
|
126
|
+
(finding) => `### ${icons[finding.severity]} ${finding.rule} (${finding.severity})
|
|
127
|
+
${finding.message}
|
|
128
|
+
` + (finding.fix ? `
|
|
129
|
+
**Fix**: ${finding.fix}
|
|
130
|
+
` : "") + (finding.doc ? `Docs: \`${finding.doc}\`
|
|
131
|
+
` : "")
|
|
132
|
+
);
|
|
133
|
+
const errors = findings.filter(
|
|
134
|
+
(finding) => finding.severity === "error"
|
|
135
|
+
).length;
|
|
136
|
+
return `${findings.length} finding(s)${errors ? `, ${errors} of which block the app` : ""}:
|
|
137
|
+
|
|
138
|
+
${blocks.join("\n")}${blindSpots}`;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
export const appTools = [inspectAppTool, doctorTool];
|
|
File without changes
|