@mapomodule/mcp 0.0.0-stage → 1.0.0-beta.2
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 +509 -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 +274 -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 +124 -0
- package/dist/runtime/core/doctor.d.ts +0 -0
- package/dist/runtime/core/doctor.js +128 -0
- package/dist/runtime/core/endpoint.d.ts +0 -0
- package/dist/runtime/core/endpoint.js +8 -0
- package/dist/runtime/core/indexer.d.ts +0 -0
- package/dist/runtime/core/indexer.js +194 -0
- package/dist/runtime/core/instructions.d.ts +0 -0
- package/dist/runtime/core/instructions.js +10 -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/overview.d.ts +0 -0
- package/dist/runtime/core/overview.js +15 -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 +496 -0
- package/dist/runtime/core/resources.d.ts +0 -0
- package/dist/runtime/core/resources.js +92 -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 +154 -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 +7 -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/resources/overview.js +20 -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 +137 -0
- package/src/__tests__/doctor.test.ts +145 -0
- package/src/__tests__/endpoint.test.ts +31 -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 +225 -0
- package/src/__tests__/openapi.test.ts +256 -0
- package/src/__tests__/overview.test.ts +105 -0
- package/src/__tests__/recipes.test.ts +55 -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 +375 -0
- package/src/index.ts +65 -0
- package/src/module.ts +213 -0
- package/src/runtime/core/doctor.ts +204 -0
- package/src/runtime/core/endpoint.ts +27 -0
- package/src/runtime/core/indexer.ts +285 -0
- package/src/runtime/core/instructions.ts +18 -0
- package/src/runtime/core/knowledge.ts +121 -0
- package/src/runtime/core/openapi.ts +417 -0
- package/src/runtime/core/overview.ts +44 -0
- package/src/runtime/core/prompts.ts +150 -0
- package/src/runtime/core/recipes.ts +574 -0
- package/src/runtime/core/resources.ts +150 -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 +201 -0
- package/src/runtime/core/tools/backend.ts +197 -0
- package/src/runtime/core/tools/docs.ts +218 -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 +16 -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/resources/overview.ts +22 -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,105 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
extractSnippet,
|
|
4
|
+
getDoc,
|
|
5
|
+
listDocs,
|
|
6
|
+
searchDocs,
|
|
7
|
+
} from "../runtime/core/search.js";
|
|
8
|
+
import { CRUD_LIST_DOC, CUSTOM_FIELDS_DOC, makeKnowledge } from "./fixtures.js";
|
|
9
|
+
|
|
10
|
+
const knowledge = makeKnowledge({
|
|
11
|
+
"howto/crud-list.md": CRUD_LIST_DOC,
|
|
12
|
+
"uikit/form/custom-fields.md": CUSTOM_FIELDS_DOC,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("searchDocs", () => {
|
|
16
|
+
it("ranks the section that actually answers the question first", () => {
|
|
17
|
+
const [top] = searchDocs(
|
|
18
|
+
knowledge,
|
|
19
|
+
"how do I run bulk actions on selected rows",
|
|
20
|
+
);
|
|
21
|
+
expect(top?.path).toBe("howto/crud-list.md");
|
|
22
|
+
expect(top?.heading).toBe("Bulk actions");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("finds a page through an identifier mentioned in its body", () => {
|
|
26
|
+
const [top] = searchDocs(knowledge, "defineFormField");
|
|
27
|
+
expect(top?.path).toBe("uikit/form/custom-fields.md");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("honours the section filter", () => {
|
|
31
|
+
const hits = searchDocs(knowledge, "field registry", { section: "howto" });
|
|
32
|
+
expect(hits.length).toBeGreaterThan(0);
|
|
33
|
+
expect(hits.every((hit) => hit.section === "howto")).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("honours the package filter, with or without the scope", () => {
|
|
37
|
+
const scoped = searchDocs(knowledge, "field", { pkg: "@mapomodule/form" });
|
|
38
|
+
const bare = searchDocs(knowledge, "field", { pkg: "form" });
|
|
39
|
+
expect(scoped.map((hit) => hit.path)).toEqual(bare.map((hit) => hit.path));
|
|
40
|
+
expect(bare.every((hit) => hit.path.startsWith("uikit/form/"))).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("respects the limit and returns nothing for gibberish", () => {
|
|
44
|
+
expect(searchDocs(knowledge, "field", { limit: 1 })).toHaveLength(1);
|
|
45
|
+
expect(searchDocs(knowledge, "zzzqqq")).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("extractSnippet", () => {
|
|
50
|
+
it("centres the excerpt on the matched term", () => {
|
|
51
|
+
const text = `${"padding ".repeat(60)}NEEDLE${" trailing".repeat(60)}`;
|
|
52
|
+
const snippet = extractSnippet(text, "needle");
|
|
53
|
+
expect(snippet).toContain("NEEDLE");
|
|
54
|
+
expect(snippet.length).toBeLessThan(text.length);
|
|
55
|
+
expect(snippet.startsWith("…")).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("falls back to the head of the text when nothing matches", () => {
|
|
59
|
+
expect(extractSnippet("short body", "absent")).toBe("short body");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("getDoc", () => {
|
|
64
|
+
it("returns the whole page with its heading list", () => {
|
|
65
|
+
const doc = getDoc(knowledge, "howto/crud-list.md")!;
|
|
66
|
+
expect(doc.title).toBe("CRUD list view");
|
|
67
|
+
expect(doc.headings).toContain("Bulk actions");
|
|
68
|
+
expect(doc.content).toContain("MapoList");
|
|
69
|
+
expect(doc.truncated).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("returns a single section when asked, by heading or anchor", () => {
|
|
73
|
+
const byHeading = getDoc(knowledge, "howto/crud-list.md", {
|
|
74
|
+
heading: "Bulk actions",
|
|
75
|
+
})!;
|
|
76
|
+
const byAnchor = getDoc(knowledge, "howto/crud-list.md", {
|
|
77
|
+
heading: "bulk-actions",
|
|
78
|
+
})!;
|
|
79
|
+
expect(byHeading.content).toBe(byAnchor.content);
|
|
80
|
+
expect(byHeading.content).toContain("## Bulk actions");
|
|
81
|
+
expect(byHeading.content).not.toContain("Minimal example");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("tolerates a leading docs/ prefix and reports unknown pages", () => {
|
|
85
|
+
expect(getDoc(knowledge, "docs/howto/crud-list.md")).not.toBeNull();
|
|
86
|
+
expect(getDoc(knowledge, "nope.md")).toBeNull();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("truncates beyond maxChars", () => {
|
|
90
|
+
const doc = getDoc(knowledge, "howto/crud-list.md", { maxChars: 100 })!;
|
|
91
|
+
expect(doc.truncated).toBe(true);
|
|
92
|
+
expect(doc.content).toContain("[truncated]");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("listDocs", () => {
|
|
97
|
+
it("groups chunks back into pages", () => {
|
|
98
|
+
const docs = listDocs(knowledge);
|
|
99
|
+
expect(docs.map((doc) => doc.path)).toEqual([
|
|
100
|
+
"howto/crud-list.md",
|
|
101
|
+
"uikit/form/custom-fields.md",
|
|
102
|
+
]);
|
|
103
|
+
expect(docs[0]!.headings).toContain("Quick edit");
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
apiTools,
|
|
4
|
+
componentApiTool,
|
|
5
|
+
composableApiTool,
|
|
6
|
+
fieldTypesTool,
|
|
7
|
+
} from "../runtime/core/tools/api.js";
|
|
8
|
+
import {
|
|
9
|
+
appTools,
|
|
10
|
+
doctorTool,
|
|
11
|
+
inspectAppTool,
|
|
12
|
+
} from "../runtime/core/tools/app.js";
|
|
13
|
+
import {
|
|
14
|
+
docsTools,
|
|
15
|
+
getDocTool,
|
|
16
|
+
searchDocsTool,
|
|
17
|
+
} from "../runtime/core/tools/docs.js";
|
|
18
|
+
import { makeContext, makeManifest } from "./fixtures.js";
|
|
19
|
+
|
|
20
|
+
const context = makeContext();
|
|
21
|
+
const allTools = [...docsTools, ...apiTools, ...appTools];
|
|
22
|
+
|
|
23
|
+
describe("tool specs", () => {
|
|
24
|
+
it("namespaces every tool and declares read-only annotations", () => {
|
|
25
|
+
for (const tool of allTools) {
|
|
26
|
+
expect(tool.name.startsWith("mapo_")).toBe(true);
|
|
27
|
+
expect(tool.annotations?.readOnlyHint).toBe(true);
|
|
28
|
+
expect(tool.annotations?.destructiveHint).toBe(false);
|
|
29
|
+
expect(tool.description.length).toBeGreaterThan(40);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("exposes input examples that satisfy the declared schema", () => {
|
|
34
|
+
for (const tool of allTools) {
|
|
35
|
+
for (const example of tool.inputExamples ?? []) {
|
|
36
|
+
for (const key of Object.keys(example)) {
|
|
37
|
+
expect(Object.keys(tool.inputSchema)).toContain(key);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("mapo_search_docs", () => {
|
|
45
|
+
it("returns paths and anchors the agent can feed to mapo_get_doc", async () => {
|
|
46
|
+
const output = await searchDocsTool.run(
|
|
47
|
+
{ query: "bulk actions", limit: 2 },
|
|
48
|
+
context,
|
|
49
|
+
);
|
|
50
|
+
expect(output).toContain("howto/crud-list.md");
|
|
51
|
+
expect(output).toContain("#bulk-actions");
|
|
52
|
+
expect(output).toContain("mapo_get_doc");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("explains the miss instead of returning an empty result", async () => {
|
|
56
|
+
const output = await searchDocsTool.run({ query: "zzzqqq" }, context);
|
|
57
|
+
expect(output).toContain("No documentation section matched");
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("mapo_get_doc", () => {
|
|
62
|
+
it("returns the section plus the page's heading list", async () => {
|
|
63
|
+
const output = await getDocTool.run(
|
|
64
|
+
{ path: "howto/crud-list.md", heading: "Minimal example" },
|
|
65
|
+
context,
|
|
66
|
+
);
|
|
67
|
+
expect(output).toContain("source: `howto/crud-list.md`");
|
|
68
|
+
expect(output).toContain("MapoList");
|
|
69
|
+
expect(output).toContain("Bulk actions");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("points back to search when the path is wrong", async () => {
|
|
73
|
+
const output = await getDocTool.run({ path: "nope.md" }, context);
|
|
74
|
+
expect(output).toContain("mapo_search_docs");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("mapo_component_api", () => {
|
|
79
|
+
it("renders props, events and slots with their real types", async () => {
|
|
80
|
+
const output = await componentApiTool.run({ name: "MapoList" }, context);
|
|
81
|
+
expect(output).toContain("# MapoList");
|
|
82
|
+
expect(output).toContain("`endpoint`: `string` **required**");
|
|
83
|
+
expect(output).toContain("(default `[]`)");
|
|
84
|
+
expect(output).toContain("**Events** (1)");
|
|
85
|
+
expect(output).toContain("uikit/list.md#mapolist");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("resolves partial names, with or without the Mapo prefix", async () => {
|
|
89
|
+
const output = await componentApiTool.run({ name: "detail" }, context);
|
|
90
|
+
expect(output).toContain("# MapoDetail");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("limits the response to the requested sections", async () => {
|
|
94
|
+
const output = await componentApiTool.run(
|
|
95
|
+
{ name: "MapoList", include: ["slots"] },
|
|
96
|
+
context,
|
|
97
|
+
);
|
|
98
|
+
expect(output).toContain("**Slots**");
|
|
99
|
+
expect(output).not.toContain("**Props**");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("lists what exists when the name is unknown", async () => {
|
|
103
|
+
const output = await componentApiTool.run({ name: "MapoNope" }, context);
|
|
104
|
+
expect(output).toContain("No Mapo component matches");
|
|
105
|
+
expect(output).toContain("MapoList");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("mapo_list_field_types", () => {
|
|
110
|
+
it("lists every registered type with its component", async () => {
|
|
111
|
+
const output = await fieldTypesTool.run({}, context);
|
|
112
|
+
expect(output).toContain("`select` → NuiSelectMenu");
|
|
113
|
+
expect(output).toContain("`text` → NuiInput");
|
|
114
|
+
expect(output).toContain("Shared descriptor properties");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("details one type with attrs, defaults and a skeleton descriptor", async () => {
|
|
118
|
+
const output = await fieldTypesTool.run({ type: "select" }, context);
|
|
119
|
+
expect(output).toContain("# Field type `select`");
|
|
120
|
+
expect(output).toContain("descriptor: `SelectDescriptor`");
|
|
121
|
+
expect(output).toContain('registry defaults: `{"labelKey":"text"}`');
|
|
122
|
+
expect(output).toContain('type: "select"');
|
|
123
|
+
expect(output).toContain("attrs: { items: … }");
|
|
124
|
+
expect(output).toContain("`items`: `readonly string[]` **required**");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("points at defineFormField for unknown types", async () => {
|
|
128
|
+
const output = await fieldTypesTool.run({ type: "nope" }, context);
|
|
129
|
+
expect(output).toContain("defineFormField");
|
|
130
|
+
expect(output).toContain("select, text");
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("mapo_composable_api", () => {
|
|
135
|
+
it("groups the auto-imported composables by package", async () => {
|
|
136
|
+
const output = await composableApiTool.run({}, context);
|
|
137
|
+
expect(output).toContain("**@mapomodule/core**: useCrud");
|
|
138
|
+
expect(output).toContain("**@mapomodule/uikit**: useMediaStore");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("returns the real signature for one composable", async () => {
|
|
142
|
+
const output = await composableApiTool.run({ name: "useCrud" }, context);
|
|
143
|
+
expect(output).toContain(
|
|
144
|
+
"useCrud: <T>(endpoint: string) => CrudRepository<T>",
|
|
145
|
+
);
|
|
146
|
+
expect(output).toContain("auto-imported");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("reports unknown names without inventing an API", async () => {
|
|
150
|
+
const output = await composableApiTool.run({ name: "useNope" }, context);
|
|
151
|
+
expect(output).toContain("No auto-imported composable matches");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("mapo_inspect_app", () => {
|
|
156
|
+
it("reports the app's real setup", async () => {
|
|
157
|
+
const output = await inspectAppTool.run({}, context);
|
|
158
|
+
|
|
159
|
+
expect(output).toContain("Installed Mapo modules");
|
|
160
|
+
expect(output).toContain("@nuxt/ui` → `mapomodule");
|
|
161
|
+
expect(output).toContain("Registered field types (2)");
|
|
162
|
+
expect(output).toContain("MapoList");
|
|
163
|
+
expect(output).toContain("/articles");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("limits the report to the requested sections", async () => {
|
|
167
|
+
const output = await inspectAppTool.run({ include: ["fields"] }, context);
|
|
168
|
+
|
|
169
|
+
expect(output).toContain("Registered field types");
|
|
170
|
+
expect(output).not.toContain("## Routes");
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("declares what a build-time snapshot cannot see", async () => {
|
|
174
|
+
const output = await inspectAppTool.run({ include: ["fields"] }, context);
|
|
175
|
+
expect(output).toContain("defineFormField()");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("explains how to get an app when there is none", async () => {
|
|
179
|
+
const output = await inspectAppTool.run({}, makeContext(undefined, null));
|
|
180
|
+
|
|
181
|
+
expect(output).toContain("/mcp/mapo");
|
|
182
|
+
expect(output).toContain("dev server");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe("mapo_doctor", () => {
|
|
187
|
+
it("reports a clean bill of health", async () => {
|
|
188
|
+
const output = await doctorTool.run({}, context);
|
|
189
|
+
|
|
190
|
+
expect(output).toContain("No problem found");
|
|
191
|
+
expect(output).toContain("Not checked");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("renders findings with severity, fix and doc link", async () => {
|
|
195
|
+
const broken = makeContext(
|
|
196
|
+
undefined,
|
|
197
|
+
makeManifest({ moduleOrder: ["mapomodule"] }),
|
|
198
|
+
);
|
|
199
|
+
const output = await doctorTool.run({}, broken);
|
|
200
|
+
|
|
201
|
+
expect(output).toContain("nuxt-ui-missing (error)");
|
|
202
|
+
expect(output).toContain("**Fix**");
|
|
203
|
+
expect(output).toContain("guide/getting-started.md");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("filters by severity", async () => {
|
|
207
|
+
const noisy = makeContext(
|
|
208
|
+
undefined,
|
|
209
|
+
makeManifest({
|
|
210
|
+
config: { mapoCore: { loginUrl: "/login" } },
|
|
211
|
+
locales: ["fr"],
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const all = await doctorTool.run({}, noisy);
|
|
216
|
+
const errorsOnly = await doctorTool.run({ severity: "error" }, noisy);
|
|
217
|
+
|
|
218
|
+
expect(all).toContain("auth-endpoints-default");
|
|
219
|
+
expect(errorsOnly).not.toContain("auth-endpoints-default");
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("explains how to get an app when there is none", async () => {
|
|
223
|
+
const output = await doctorTool.run({}, makeContext(undefined, null));
|
|
224
|
+
expect(output).toContain("/mcp/mapo");
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The write guard is the only code here that can damage a project, so it gets
|
|
3
|
+
* the most adversarial tests: traversal, symlinks, absolute paths, and the
|
|
4
|
+
* refusal to replace existing work.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
existsSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
mkdtempSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
symlinkSync,
|
|
12
|
+
writeFileSync,
|
|
13
|
+
} from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
17
|
+
import { resolveInsideRoot, writeScaffold } from "../runtime/core/write.js";
|
|
18
|
+
|
|
19
|
+
let root: string;
|
|
20
|
+
let outside: string;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
const base = mkdtempSync(join(tmpdir(), "mapo-write-"));
|
|
24
|
+
root = join(base, "project");
|
|
25
|
+
outside = join(base, "elsewhere");
|
|
26
|
+
mkdirSync(root, { recursive: true });
|
|
27
|
+
mkdirSync(outside, { recursive: true });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("resolveInsideRoot", () => {
|
|
31
|
+
it("resolves a normal relative path", () => {
|
|
32
|
+
expect(resolveInsideRoot(root, "app/pages/index.vue")).toContain(
|
|
33
|
+
"app/pages/index.vue",
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("refuses traversal out of the root", () => {
|
|
38
|
+
expect(resolveInsideRoot(root, "../elsewhere/evil.ts")).toBeNull();
|
|
39
|
+
expect(resolveInsideRoot(root, "app/../../elsewhere/evil.ts")).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("refuses absolute paths", () => {
|
|
43
|
+
expect(resolveInsideRoot(root, "/etc/passwd")).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("refuses a path escaping through a symlinked directory", () => {
|
|
47
|
+
// `project/link` points outside: writing "link/evil.ts" would land there.
|
|
48
|
+
symlinkSync(outside, join(root, "link"));
|
|
49
|
+
expect(resolveInsideRoot(root, "link/evil.ts")).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("accepts a symlink that stays inside the root", () => {
|
|
53
|
+
mkdirSync(join(root, "real"));
|
|
54
|
+
symlinkSync(join(root, "real"), join(root, "alias"));
|
|
55
|
+
expect(resolveInsideRoot(root, "alias/page.vue")).toContain("real");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("does not accept a sibling directory sharing the root's prefix", () => {
|
|
59
|
+
// `/tmp/x/project-evil` must not pass a naive `startsWith(root)` check.
|
|
60
|
+
expect(resolveInsideRoot(root, "../project-evil/file.ts")).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("writeScaffold", () => {
|
|
65
|
+
const file = {
|
|
66
|
+
path: "app/pages/articles/index.vue",
|
|
67
|
+
content: "<template>ok</template>\n",
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
it("creates the file and its parent directories", () => {
|
|
71
|
+
const [outcome] = writeScaffold([file], { root });
|
|
72
|
+
|
|
73
|
+
expect(outcome!.status).toBe("written");
|
|
74
|
+
expect(readFileSync(outcome!.absolute!, "utf-8")).toContain("ok");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("refuses to replace an existing file by default", () => {
|
|
78
|
+
writeScaffold([file], { root });
|
|
79
|
+
const [outcome] = writeScaffold(
|
|
80
|
+
[{ ...file, content: "<template>overwritten</template>" }],
|
|
81
|
+
{ root },
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(outcome!.status).toBe("exists");
|
|
85
|
+
expect(outcome!.reason).toContain("overwrite");
|
|
86
|
+
expect(readFileSync(join(root, file.path), "utf-8")).toContain("ok");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("replaces it when overwrite is explicit", () => {
|
|
90
|
+
writeScaffold([file], { root });
|
|
91
|
+
const [outcome] = writeScaffold(
|
|
92
|
+
[{ ...file, content: "<template>overwritten</template>" }],
|
|
93
|
+
{ root, overwrite: true },
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
expect(outcome!.status).toBe("written");
|
|
97
|
+
expect(readFileSync(join(root, file.path), "utf-8")).toContain(
|
|
98
|
+
"overwritten",
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("writes nothing when the adapter forbids it", () => {
|
|
103
|
+
const [outcome] = writeScaffold([file], { root, allowed: false });
|
|
104
|
+
|
|
105
|
+
expect(outcome!.status).toBe("not-allowed");
|
|
106
|
+
expect(existsSync(join(root, file.path))).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("reports each file separately instead of aborting the batch", () => {
|
|
110
|
+
const outcomes = writeScaffold(
|
|
111
|
+
[
|
|
112
|
+
file,
|
|
113
|
+
{ path: "../escape.ts", content: "x" },
|
|
114
|
+
{ path: "/tmp/abs.ts", content: "x" },
|
|
115
|
+
],
|
|
116
|
+
{ root },
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(outcomes.map((outcome) => outcome.status)).toEqual([
|
|
120
|
+
"written",
|
|
121
|
+
"outside-root",
|
|
122
|
+
"absolute-path",
|
|
123
|
+
]);
|
|
124
|
+
expect(existsSync(join(outside, "..", "escape.ts"))).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("leaves a pre-existing file untouched when the write is refused", () => {
|
|
128
|
+
const target = join(root, "keep.ts");
|
|
129
|
+
writeFileSync(target, "original");
|
|
130
|
+
writeScaffold([{ path: "keep.ts", content: "replaced" }], { root });
|
|
131
|
+
|
|
132
|
+
expect(readFileSync(target, "utf-8")).toBe("original");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the public API of every `Mapo*` component from its source.
|
|
3
|
+
*
|
|
4
|
+
* Build-time only: `vue-component-meta` is a devDependency and must never reach
|
|
5
|
+
* the runtime bundle. Source is the ground truth — the curated tables in
|
|
6
|
+
* `docs/uikit/api.md` drift (they listed 11 props for MapoDetail while the
|
|
7
|
+
* component declared 17).
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
10
|
+
import { join, relative } from "node:path";
|
|
11
|
+
import { createChecker } from "vue-component-meta";
|
|
12
|
+
import type { ApiMember, ComponentApi } from "../runtime/core/types.js";
|
|
13
|
+
|
|
14
|
+
/** Packages whose `runtime/components` tree is scanned. */
|
|
15
|
+
const COMPONENT_PACKAGES = [
|
|
16
|
+
{ pkg: "@mapomodule/uikit", dir: "packages/@mapomodule/uikit" },
|
|
17
|
+
{ pkg: "@mapomodule/form", dir: "packages/@mapomodule/form" },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** Union types can be enormous; keep them readable in a tool response. */
|
|
21
|
+
const MAX_TYPE_LENGTH = 160;
|
|
22
|
+
|
|
23
|
+
function shortenType(type: string): string {
|
|
24
|
+
const collapsed = type.replace(/\s+/g, " ").trim();
|
|
25
|
+
return collapsed.length > MAX_TYPE_LENGTH
|
|
26
|
+
? `${collapsed.slice(0, MAX_TYPE_LENGTH)}…`
|
|
27
|
+
: collapsed;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function firstSentence(description: string | undefined): string | undefined {
|
|
31
|
+
if (!description) return undefined;
|
|
32
|
+
const trimmed = description.replace(/\s+/g, " ").trim();
|
|
33
|
+
return trimmed || undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function collectVueFiles(root: string): string[] {
|
|
37
|
+
if (!existsSync(root)) return [];
|
|
38
|
+
const files: string[] = [];
|
|
39
|
+
|
|
40
|
+
const walk = (dir: string) => {
|
|
41
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
42
|
+
const full = join(dir, entry.name);
|
|
43
|
+
if (entry.isDirectory()) walk(full);
|
|
44
|
+
else if (entry.name.endsWith(".vue")) files.push(full);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
walk(root);
|
|
49
|
+
return files.sort();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface MetaMember {
|
|
53
|
+
name: string;
|
|
54
|
+
type?: string;
|
|
55
|
+
required?: boolean;
|
|
56
|
+
default?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
global?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toMembers(
|
|
62
|
+
entries: MetaMember[] | undefined,
|
|
63
|
+
withType = true,
|
|
64
|
+
): ApiMember[] {
|
|
65
|
+
return (entries ?? []).map((entry) => ({
|
|
66
|
+
name: entry.name,
|
|
67
|
+
...(withType && entry.type ? { type: shortenType(entry.type) } : {}),
|
|
68
|
+
...(entry.required !== undefined ? { required: entry.required } : {}),
|
|
69
|
+
...(entry.default !== undefined && entry.default !== "undefined"
|
|
70
|
+
? { default: shortenType(String(entry.default)) }
|
|
71
|
+
: {}),
|
|
72
|
+
...(firstSentence(entry.description)
|
|
73
|
+
? { description: firstSentence(entry.description)! }
|
|
74
|
+
: {}),
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param repoRoot absolute path of the monorepo root
|
|
80
|
+
* @param docsFor resolves the doc sections that mention a symbol
|
|
81
|
+
*/
|
|
82
|
+
export function extractComponents(
|
|
83
|
+
repoRoot: string,
|
|
84
|
+
docsFor: (symbol: string) => string[],
|
|
85
|
+
): ComponentApi[] {
|
|
86
|
+
const components: ComponentApi[] = [];
|
|
87
|
+
|
|
88
|
+
for (const { pkg, dir } of COMPONENT_PACKAGES) {
|
|
89
|
+
const packageRoot = join(repoRoot, dir);
|
|
90
|
+
const tsconfig = join(packageRoot, "tsconfig.json");
|
|
91
|
+
const componentsRoot = join(packageRoot, "src", "runtime", "components");
|
|
92
|
+
const files = collectVueFiles(componentsRoot).filter((file) =>
|
|
93
|
+
/\/Mapo[A-Z][^/]*\.vue$/.test(file),
|
|
94
|
+
);
|
|
95
|
+
if (!files.length || !existsSync(tsconfig)) continue;
|
|
96
|
+
|
|
97
|
+
const checker = createChecker(tsconfig, {
|
|
98
|
+
forceUseTs: true,
|
|
99
|
+
printer: { newLine: 1 },
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
for (const file of files) {
|
|
103
|
+
const name = file
|
|
104
|
+
.split("/")
|
|
105
|
+
.pop()!
|
|
106
|
+
.replace(/\.vue$/, "");
|
|
107
|
+
try {
|
|
108
|
+
const meta = checker.getComponentMeta(file);
|
|
109
|
+
const props = (meta.props as MetaMember[]).filter(
|
|
110
|
+
(prop) => !prop.global,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
components.push({
|
|
114
|
+
name,
|
|
115
|
+
pkg,
|
|
116
|
+
file: relative(repoRoot, file),
|
|
117
|
+
...(firstSentence(meta.description)
|
|
118
|
+
? { description: firstSentence(meta.description)! }
|
|
119
|
+
: {}),
|
|
120
|
+
props: toMembers(props),
|
|
121
|
+
events: toMembers(meta.events as MetaMember[]),
|
|
122
|
+
slots: toMembers(meta.slots as MetaMember[]),
|
|
123
|
+
exposed: toMembers(meta.exposed as MetaMember[]),
|
|
124
|
+
docs: docsFor(name),
|
|
125
|
+
});
|
|
126
|
+
} catch (error) {
|
|
127
|
+
// A single unresolvable component must not break the whole build.
|
|
128
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
129
|
+
console.warn(`[mapo-mcp] skipped ${name}: ${message}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return components.sort((a, b) => a.name.localeCompare(b.name));
|
|
135
|
+
}
|