@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,16 @@
|
|
|
1
|
+
import { NuxtModule } from '@nuxt/schema';
|
|
2
|
+
import { MapoMcpOptions } from './index.mjs';
|
|
3
|
+
export { MapoAppManifest, MapoMcpContext } from './index.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Mapo MCP server — development-only.
|
|
7
|
+
*
|
|
8
|
+
* Registers a dedicated `@nuxtjs/mcp-toolkit` handler (default route `/mcp/mapo`)
|
|
9
|
+
* carrying Mapo's docs, API surface, app introspection and scaffolding tools.
|
|
10
|
+
* The definitions live inside this package and are injected through the
|
|
11
|
+
* toolkit's `mcp:definitions:paths` hook, so consuming apps write no MCP files
|
|
12
|
+
* and their own MCP definitions stay untouched.
|
|
13
|
+
*/
|
|
14
|
+
declare const _default: NuxtModule<MapoMcpOptions, MapoMcpOptions, false>;
|
|
15
|
+
|
|
16
|
+
export { MapoMcpOptions, _default as default };
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NuxtModule } from '@nuxt/schema';
|
|
2
|
+
import { MapoMcpOptions } from './index.js';
|
|
3
|
+
export { MapoAppManifest, MapoMcpContext } from './index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Mapo MCP server — development-only.
|
|
7
|
+
*
|
|
8
|
+
* Registers a dedicated `@nuxtjs/mcp-toolkit` handler (default route `/mcp/mapo`)
|
|
9
|
+
* carrying Mapo's docs, API surface, app introspection and scaffolding tools.
|
|
10
|
+
* The definitions live inside this package and are injected through the
|
|
11
|
+
* toolkit's `mcp:definitions:paths` hook, so consuming apps write no MCP files
|
|
12
|
+
* and their own MCP definitions stay untouched.
|
|
13
|
+
*/
|
|
14
|
+
declare const _default: NuxtModule<MapoMcpOptions, MapoMcpOptions, false>;
|
|
15
|
+
|
|
16
|
+
export { MapoMcpOptions, _default as default };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { defineNuxtModule, logger, createResolver, hasNuxtModule, installModule, addServerTemplate } from '@nuxt/kit';
|
|
4
|
+
|
|
5
|
+
const HANDLER_NAME = "mapo";
|
|
6
|
+
function readDefaultFieldTypes(knowledgeDir) {
|
|
7
|
+
if (!knowledgeDir) return [];
|
|
8
|
+
const file = join(knowledgeDir, "api.json");
|
|
9
|
+
if (!existsSync(file)) return [];
|
|
10
|
+
try {
|
|
11
|
+
const parsed = JSON.parse(readFileSync(file, "utf-8"));
|
|
12
|
+
return (parsed.fieldTypes ?? []).map((entry) => entry.type);
|
|
13
|
+
} catch {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const module$1 = defineNuxtModule({
|
|
18
|
+
meta: {
|
|
19
|
+
name: "@mapomodule/mcp",
|
|
20
|
+
configKey: "mapoMcp"
|
|
21
|
+
},
|
|
22
|
+
defaults: {},
|
|
23
|
+
async setup(options, nuxt) {
|
|
24
|
+
const log = logger.withTag("mapo:mcp");
|
|
25
|
+
const enabled = options.enabled ?? nuxt.options.dev;
|
|
26
|
+
if (!enabled) return;
|
|
27
|
+
const resolver = createResolver(import.meta.url);
|
|
28
|
+
const knowledgeDir = ["./knowledge", "../knowledge", "../dist/knowledge"].map((candidate) => resolver.resolve(candidate)).find((candidate) => existsSync(join(candidate, "docs.json")));
|
|
29
|
+
if (!knowledgeDir) {
|
|
30
|
+
log.warn(
|
|
31
|
+
"Knowledge base missing \u2014 docs tools will fail. Build it with `pnpm --filter @mapomodule/mcp build`."
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (!hasNuxtModule("@nuxtjs/mcp-toolkit")) {
|
|
35
|
+
await installModule(await resolver.resolvePath("@nuxtjs/mcp-toolkit"), {
|
|
36
|
+
name: "Mapo",
|
|
37
|
+
description: "Mapo admin framework: docs, APIs, app introspection and scaffolding."
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const hook = nuxt.hook;
|
|
41
|
+
hook("mcp:definitions:paths", (paths) => {
|
|
42
|
+
paths.handlers.push(resolver.resolve("./runtime/mcp"));
|
|
43
|
+
});
|
|
44
|
+
const components = [];
|
|
45
|
+
const routes = [];
|
|
46
|
+
nuxt.hook("components:extend", (registered) => {
|
|
47
|
+
components.length = 0;
|
|
48
|
+
for (const component of registered) {
|
|
49
|
+
if (component.pascalName?.startsWith("Mapo"))
|
|
50
|
+
components.push(component.pascalName);
|
|
51
|
+
}
|
|
52
|
+
components.sort();
|
|
53
|
+
});
|
|
54
|
+
nuxt.hook("pages:extend", (pages) => {
|
|
55
|
+
routes.length = 0;
|
|
56
|
+
const walk = (list) => {
|
|
57
|
+
for (const page of list) {
|
|
58
|
+
routes.push({
|
|
59
|
+
path: page.path,
|
|
60
|
+
...page.file ? { file: page.file } : {}
|
|
61
|
+
});
|
|
62
|
+
if (page.children?.length) walk(page.children);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
walk(pages);
|
|
66
|
+
});
|
|
67
|
+
const buildContext = () => {
|
|
68
|
+
const publicConfig = nuxt.options.runtimeConfig.public;
|
|
69
|
+
const mapoConfig = Object.fromEntries(
|
|
70
|
+
Object.entries(publicConfig).filter(
|
|
71
|
+
([key]) => key.toLowerCase().startsWith("mapo")
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
const options_ = nuxt.options;
|
|
75
|
+
const configuredTypes = Object.keys(
|
|
76
|
+
options_.mapoForm?.fields?.mapping ?? {}
|
|
77
|
+
);
|
|
78
|
+
const defaultTypes = readDefaultFieldTypes(knowledgeDir ?? null);
|
|
79
|
+
const manifest = {
|
|
80
|
+
rootDir: nuxt.options.rootDir,
|
|
81
|
+
dev: nuxt.options.dev,
|
|
82
|
+
modules: (nuxt.options._installedModules ?? []).map((installed) => ({
|
|
83
|
+
name: installed.meta?.name ?? "",
|
|
84
|
+
...installed.meta?.version ? { version: installed.meta.version } : {}
|
|
85
|
+
})).filter((entry) => entry.name.includes("mapo")),
|
|
86
|
+
// Declaration order, not resolution order: `mapo_doctor` checks that
|
|
87
|
+
// `@nuxt/ui` is registered before `mapomodule`.
|
|
88
|
+
moduleOrder: (nuxt.options.modules ?? []).filter(
|
|
89
|
+
(entry) => typeof entry === "string"
|
|
90
|
+
),
|
|
91
|
+
config: mapoConfig,
|
|
92
|
+
fieldTypes: [
|
|
93
|
+
...defaultTypes.map((type) => ({ type, source: "default" })),
|
|
94
|
+
...configuredTypes.filter((type) => !defaultTypes.includes(type)).map((type) => ({ type, source: "config" }))
|
|
95
|
+
],
|
|
96
|
+
components: [...components],
|
|
97
|
+
routes: [...routes],
|
|
98
|
+
locales: (options_.i18n?.locales ?? []).map(
|
|
99
|
+
(locale) => typeof locale === "string" ? locale : locale.code
|
|
100
|
+
)
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
knowledgeDir: knowledgeDir ?? null,
|
|
104
|
+
backend: {
|
|
105
|
+
schemaUrl: options.backend?.schemaUrl ?? process.env.MAPO_BACKEND_SCHEMA_URL ?? null,
|
|
106
|
+
tokenEnv: options.backend?.tokenEnv ?? "MAPO_BACKEND_TOKEN"
|
|
107
|
+
},
|
|
108
|
+
manifest
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
addServerTemplate({
|
|
112
|
+
filename: "#mapo-mcp/context.mjs",
|
|
113
|
+
getContents: () => `export default ${JSON.stringify(buildContext())}`
|
|
114
|
+
});
|
|
115
|
+
log.info(
|
|
116
|
+
`MCP server available at ${nuxt.options.devServer?.url ?? "http://localhost:3000"}/mcp/${HANDLER_NAME}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
export { module$1 as default };
|
|
File without changes
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const AUTH_DEFAULTS = {
|
|
2
|
+
authLoginUrl: "/api/auth/login",
|
|
3
|
+
userInfoApi: "/api/profiles/me/",
|
|
4
|
+
logoutUrl: "/api/auth/logout",
|
|
5
|
+
loginUrl: "/login"
|
|
6
|
+
};
|
|
7
|
+
const MEDIA_ENDPOINT_DEFAULTS = {
|
|
8
|
+
media: "/api/media",
|
|
9
|
+
folders: "/api/media-folders"
|
|
10
|
+
};
|
|
11
|
+
const BUNDLED_LOCALES = /* @__PURE__ */ new Set(["en", "it"]);
|
|
12
|
+
const MEDIA_FIELD_TYPES = /* @__PURE__ */ new Set(["media", "media-m2m", "enhanced-media"]);
|
|
13
|
+
function section(manifest, key) {
|
|
14
|
+
const value = manifest.config[key];
|
|
15
|
+
return value && typeof value === "object" ? value : {};
|
|
16
|
+
}
|
|
17
|
+
export function runDoctor(manifest) {
|
|
18
|
+
const findings = [];
|
|
19
|
+
const core = section(manifest, "mapoCore");
|
|
20
|
+
const media = section(manifest, "mapoMedia");
|
|
21
|
+
const moduleNames = new Set(manifest.modules.map((module) => module.name));
|
|
22
|
+
const order = manifest.moduleOrder;
|
|
23
|
+
const uiIndex = order.indexOf("@nuxt/ui");
|
|
24
|
+
const mapoIndex = order.findIndex(
|
|
25
|
+
(name) => name === "mapomodule" || name.startsWith("@mapomodule/")
|
|
26
|
+
);
|
|
27
|
+
if (mapoIndex !== -1 && uiIndex === -1) {
|
|
28
|
+
findings.push({
|
|
29
|
+
rule: "nuxt-ui-missing",
|
|
30
|
+
severity: "error",
|
|
31
|
+
message: "`@nuxt/ui` is not declared in `modules[]`, but Mapo's UI layer requires it.",
|
|
32
|
+
fix: 'Add "@nuxt/ui" as the first entry of `modules[]`.',
|
|
33
|
+
doc: "guide/getting-started.md"
|
|
34
|
+
});
|
|
35
|
+
} else if (mapoIndex !== -1 && uiIndex > mapoIndex) {
|
|
36
|
+
findings.push({
|
|
37
|
+
rule: "nuxt-ui-order",
|
|
38
|
+
severity: "error",
|
|
39
|
+
message: `\`@nuxt/ui\` is declared after \`${order[mapoIndex]}\` in modules[]. Icons break during SSR when Nuxt UI is initialised after Mapo.`,
|
|
40
|
+
fix: 'Move "@nuxt/ui" before the Mapo entry in `modules[]`.',
|
|
41
|
+
doc: "guide/compatibility.md"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (!moduleNames.has("@mapomodule/core")) {
|
|
45
|
+
findings.push({
|
|
46
|
+
rule: "core-missing",
|
|
47
|
+
severity: "error",
|
|
48
|
+
message: "`@mapomodule/core` is not installed \u2014 auth, `useCrud` and route middleware are unavailable.",
|
|
49
|
+
fix: 'Add "mapomodule" to `modules[]`.',
|
|
50
|
+
doc: "guide/getting-started.md"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const loginUrl = typeof core.loginUrl === "string" ? core.loginUrl : AUTH_DEFAULTS.loginUrl;
|
|
54
|
+
const hasLoginRoute = manifest.routes.some(
|
|
55
|
+
(route) => route.path === loginUrl
|
|
56
|
+
);
|
|
57
|
+
if (!hasLoginRoute && manifest.routes.length > 0) {
|
|
58
|
+
findings.push({
|
|
59
|
+
rule: "login-route-missing",
|
|
60
|
+
severity: "error",
|
|
61
|
+
message: `No page matches \`loginUrl\` (\`${loginUrl}\`); the auth middleware would redirect to a missing route.`,
|
|
62
|
+
fix: `Create \`pages${loginUrl}.vue\` rendering <MapoLogin /> with \`definePageMeta({ layout: false })\`, or change \`mapo.loginUrl\`.`,
|
|
63
|
+
doc: "howto/auth-permissions.md"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const authKeys = ["authLoginUrl", "userInfoApi", "logoutUrl"];
|
|
67
|
+
const allDefault = authKeys.every(
|
|
68
|
+
(key) => (core[key] ?? AUTH_DEFAULTS[key]) === AUTH_DEFAULTS[key]
|
|
69
|
+
);
|
|
70
|
+
if (allDefault) {
|
|
71
|
+
findings.push({
|
|
72
|
+
rule: "auth-endpoints-default",
|
|
73
|
+
severity: "info",
|
|
74
|
+
message: "Auth endpoints are still the Mapo defaults \u2014 fine for a mock backend, not for a real one.",
|
|
75
|
+
fix: "Set `mapo.authLoginUrl`, `mapo.userInfoApi` and `mapo.logoutUrl` to your backend routes.",
|
|
76
|
+
doc: "howto/backend-integration.md"
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const adminRoutes = manifest.routes.filter(
|
|
80
|
+
(route) => route.path !== loginUrl
|
|
81
|
+
);
|
|
82
|
+
if (adminRoutes.length === 0) {
|
|
83
|
+
findings.push({
|
|
84
|
+
rule: "no-admin-pages",
|
|
85
|
+
severity: "warning",
|
|
86
|
+
message: "The app has no admin page yet (only the login route was found).",
|
|
87
|
+
fix: 'Create a page with `definePageMeta({ layout: "mapo-default", middleware: ["auth"] })`.',
|
|
88
|
+
doc: "howto/first-admin-page.md"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const uncovered = manifest.locales.filter(
|
|
92
|
+
(locale) => !BUNDLED_LOCALES.has(locale)
|
|
93
|
+
);
|
|
94
|
+
if (uncovered.length) {
|
|
95
|
+
findings.push({
|
|
96
|
+
rule: "locale-without-catalog",
|
|
97
|
+
severity: "warning",
|
|
98
|
+
message: `Mapo ships UI catalogs for en and it only; ${uncovered.join(", ")} will fall back for framework strings.`,
|
|
99
|
+
fix: "Add the missing `mapo.*` keys to your own `i18n/locales/<code>.json`.",
|
|
100
|
+
doc: "howto/i18n.md"
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const usesMedia = manifest.fieldTypes.some(
|
|
104
|
+
(field) => MEDIA_FIELD_TYPES.has(field.type)
|
|
105
|
+
);
|
|
106
|
+
const endpoints = media.endpoints ?? {};
|
|
107
|
+
const mediaDefaults = (endpoints.media ?? MEDIA_ENDPOINT_DEFAULTS.media) === MEDIA_ENDPOINT_DEFAULTS.media && (endpoints.folders ?? MEDIA_ENDPOINT_DEFAULTS.folders) === MEDIA_ENDPOINT_DEFAULTS.folders;
|
|
108
|
+
if (usesMedia && mediaDefaults && !moduleNames.has("mapo-integrations-camomilla")) {
|
|
109
|
+
findings.push({
|
|
110
|
+
rule: "media-endpoints-default",
|
|
111
|
+
severity: "info",
|
|
112
|
+
message: `Media field types are registered but the media endpoints are still the defaults (\`${MEDIA_ENDPOINT_DEFAULTS.media}\`, \`${MEDIA_ENDPOINT_DEFAULTS.folders}\`) and no integration provides them.`,
|
|
113
|
+
fix: "Set `mapo.uikit.media.endpoints`, or install an integration that serves them.",
|
|
114
|
+
doc: "howto/media-manager.md"
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const rank = {
|
|
118
|
+
error: 0,
|
|
119
|
+
warning: 1,
|
|
120
|
+
info: 2
|
|
121
|
+
};
|
|
122
|
+
return findings.sort((a, b) => rank[a.severity] - rank[b.severity]);
|
|
123
|
+
}
|
|
124
|
+
export const DOCTOR_BLIND_SPOTS = [
|
|
125
|
+
"field types registered at runtime by `defineFormField()` inside a plugin",
|
|
126
|
+
"`definePageMeta` values (layout, middleware, permissions) of your pages",
|
|
127
|
+
"anything that depends on a request, such as the logged-in user's permissions"
|
|
128
|
+
];
|
|
File without changes
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative, sep } from "node:path";
|
|
3
|
+
import { tokenize } from "./tokenize.js";
|
|
4
|
+
export const KNOWLEDGE_VERSION = 1;
|
|
5
|
+
const MAX_CHUNK_CHARS = 3500;
|
|
6
|
+
const EXCLUDED_DIRS = /* @__PURE__ */ new Set([
|
|
7
|
+
"node_modules",
|
|
8
|
+
"roadmap",
|
|
9
|
+
".vitepress",
|
|
10
|
+
"dist"
|
|
11
|
+
]);
|
|
12
|
+
const EXCLUDED_FILES = /* @__PURE__ */ new Set(["DECISIONS.md"]);
|
|
13
|
+
const BOOST = { heading: 3, title: 2, tags: 3, text: 1 };
|
|
14
|
+
const PKG_BY_PREFIX = [
|
|
15
|
+
["uikit/form", "@mapomodule/form"],
|
|
16
|
+
["uikit", "@mapomodule/uikit"],
|
|
17
|
+
["modules/core", "@mapomodule/core"],
|
|
18
|
+
["modules/store", "@mapomodule/store"],
|
|
19
|
+
["modules/utils", "@mapomodule/utils"],
|
|
20
|
+
["modules/i18n", "@mapomodule/i18n"],
|
|
21
|
+
["modules/api", "@mapomodule/core"],
|
|
22
|
+
["modules/camomilla", "mapo-integrations-camomilla"]
|
|
23
|
+
];
|
|
24
|
+
const REFERENCE_PATH = /(?:^|\/)api\.md$/;
|
|
25
|
+
const REFERENCE_HEADING = /^(props|slots|emits|events|exposed|api)\b/i;
|
|
26
|
+
export function slugify(heading) {
|
|
27
|
+
return heading.toLowerCase().replace(/`/g, "").replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-");
|
|
28
|
+
}
|
|
29
|
+
function toPosix(path) {
|
|
30
|
+
return sep === "/" ? path : path.split(sep).join("/");
|
|
31
|
+
}
|
|
32
|
+
export function collectMarkdownFiles(root) {
|
|
33
|
+
const files = [];
|
|
34
|
+
const walk = (dir) => {
|
|
35
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
36
|
+
if (entry.name.startsWith(".") && entry.name !== ".vitepress") continue;
|
|
37
|
+
const full = join(dir, entry.name);
|
|
38
|
+
if (entry.isDirectory()) {
|
|
39
|
+
if (EXCLUDED_DIRS.has(entry.name)) continue;
|
|
40
|
+
walk(full);
|
|
41
|
+
} else if (entry.isFile() && entry.name.endsWith(".md") && !EXCLUDED_FILES.has(entry.name)) {
|
|
42
|
+
files.push(full);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
walk(root);
|
|
47
|
+
return files.sort();
|
|
48
|
+
}
|
|
49
|
+
export function extractTags(text) {
|
|
50
|
+
const tags = /* @__PURE__ */ new Set();
|
|
51
|
+
for (const match of text.matchAll(/\bMapo[A-Z][A-Za-z0-9]*/g))
|
|
52
|
+
tags.add(match[0]);
|
|
53
|
+
for (const match of text.matchAll(/\buse[A-Z][A-Za-z0-9]*/g))
|
|
54
|
+
tags.add(match[0]);
|
|
55
|
+
for (const match of text.matchAll(/\btype:\s*["']([a-z0-9-]+)["']/g)) {
|
|
56
|
+
if (match[1]) tags.add(match[1]);
|
|
57
|
+
}
|
|
58
|
+
return [...tags];
|
|
59
|
+
}
|
|
60
|
+
export function splitSections(markdown) {
|
|
61
|
+
const lines = markdown.replace(/\r\n/g, "\n").split("\n");
|
|
62
|
+
const sections = [];
|
|
63
|
+
let title = "";
|
|
64
|
+
let current = { heading: "", level: 1, lines: [] };
|
|
65
|
+
let fence = null;
|
|
66
|
+
for (const line of lines) {
|
|
67
|
+
const fenceMatch = /^\s*(```|~~~)/.exec(line);
|
|
68
|
+
if (fenceMatch) {
|
|
69
|
+
if (fence && line.trimStart().startsWith(fence)) fence = null;
|
|
70
|
+
else if (!fence) fence = fenceMatch[1];
|
|
71
|
+
current.lines.push(line);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (!fence) {
|
|
75
|
+
const heading = /^(#{1,3})\s+(.*)$/.exec(line);
|
|
76
|
+
if (heading) {
|
|
77
|
+
const level = heading[1].length;
|
|
78
|
+
const text = heading[2].trim();
|
|
79
|
+
if (level === 1 && !title) {
|
|
80
|
+
title = text;
|
|
81
|
+
current.heading ||= text;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (level >= 2) {
|
|
85
|
+
if (current.lines.some((l) => l.trim())) sections.push(current);
|
|
86
|
+
current = { heading: text, level, lines: [] };
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
current.lines.push(line);
|
|
92
|
+
}
|
|
93
|
+
if (current.lines.some((l) => l.trim())) sections.push(current);
|
|
94
|
+
return { title, sections };
|
|
95
|
+
}
|
|
96
|
+
function splitLongText(text) {
|
|
97
|
+
if (text.length <= MAX_CHUNK_CHARS) return [text];
|
|
98
|
+
const parts = [];
|
|
99
|
+
let buffer = "";
|
|
100
|
+
for (const paragraph of text.split(/\n{2,}/)) {
|
|
101
|
+
if (buffer && buffer.length + paragraph.length > MAX_CHUNK_CHARS) {
|
|
102
|
+
parts.push(buffer.trim());
|
|
103
|
+
buffer = "";
|
|
104
|
+
}
|
|
105
|
+
buffer += `${paragraph}
|
|
106
|
+
|
|
107
|
+
`;
|
|
108
|
+
}
|
|
109
|
+
if (buffer.trim()) parts.push(buffer.trim());
|
|
110
|
+
return parts;
|
|
111
|
+
}
|
|
112
|
+
export function chunkMarkdown(path, markdown) {
|
|
113
|
+
const posixPath = toPosix(path);
|
|
114
|
+
const segments = posixPath.split("/");
|
|
115
|
+
const section = segments.length > 1 ? segments[0] : "root";
|
|
116
|
+
const group = segments.length > 2 ? segments[1] : void 0;
|
|
117
|
+
const pkg = PKG_BY_PREFIX.find(
|
|
118
|
+
([prefix]) => posixPath.startsWith(prefix)
|
|
119
|
+
)?.[1];
|
|
120
|
+
const { title, sections } = splitSections(markdown);
|
|
121
|
+
const docTitle = title || segments.at(-1).replace(/\.md$/, "");
|
|
122
|
+
const isReferencePage = REFERENCE_PATH.test(posixPath);
|
|
123
|
+
const chunks = [];
|
|
124
|
+
const seenAnchors = /* @__PURE__ */ new Map();
|
|
125
|
+
for (const rawSection of sections) {
|
|
126
|
+
const heading = rawSection.heading || docTitle;
|
|
127
|
+
const body = rawSection.lines.join("\n").trim();
|
|
128
|
+
if (!body) continue;
|
|
129
|
+
const parts = splitLongText(body);
|
|
130
|
+
parts.forEach((text, partIndex) => {
|
|
131
|
+
const baseAnchor = rawSection.heading ? slugify(rawSection.heading) : "";
|
|
132
|
+
const seen = seenAnchors.get(baseAnchor) ?? 0;
|
|
133
|
+
seenAnchors.set(baseAnchor, seen + 1);
|
|
134
|
+
const anchor = `${baseAnchor}${seen > 0 ? `-${seen}` : ""}`;
|
|
135
|
+
chunks.push({
|
|
136
|
+
id: `${posixPath}#${anchor}${partIndex > 0 ? `~${partIndex}` : ""}`,
|
|
137
|
+
path: posixPath,
|
|
138
|
+
section,
|
|
139
|
+
...group ? { group } : {},
|
|
140
|
+
...pkg ? { pkg } : {},
|
|
141
|
+
title: docTitle,
|
|
142
|
+
heading,
|
|
143
|
+
anchor,
|
|
144
|
+
level: rawSection.heading ? rawSection.level : 1,
|
|
145
|
+
...isReferencePage || REFERENCE_HEADING.test(heading) ? { kind: "reference" } : {},
|
|
146
|
+
text,
|
|
147
|
+
tags: extractTags(text)
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return chunks;
|
|
152
|
+
}
|
|
153
|
+
export function buildIndex(chunks) {
|
|
154
|
+
const terms = {};
|
|
155
|
+
const lengths = [];
|
|
156
|
+
chunks.forEach((chunk, chunkIndex) => {
|
|
157
|
+
const counts = /* @__PURE__ */ new Map();
|
|
158
|
+
const add = (input, boost) => {
|
|
159
|
+
for (const token of tokenize(input)) {
|
|
160
|
+
counts.set(token, (counts.get(token) ?? 0) + boost);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
add(chunk.text, BOOST.text);
|
|
164
|
+
add(chunk.heading, BOOST.heading);
|
|
165
|
+
add(chunk.title, BOOST.title);
|
|
166
|
+
add(chunk.tags.join(" "), BOOST.tags);
|
|
167
|
+
let length = 0;
|
|
168
|
+
for (const [term, frequency] of counts) {
|
|
169
|
+
(terms[term] ??= []).push([chunkIndex, frequency]);
|
|
170
|
+
length += frequency;
|
|
171
|
+
}
|
|
172
|
+
lengths.push(length);
|
|
173
|
+
});
|
|
174
|
+
const total = chunks.length;
|
|
175
|
+
const avgLength = total ? lengths.reduce((a, b) => a + b, 0) / total : 0;
|
|
176
|
+
return { terms, lengths, avgLength, total };
|
|
177
|
+
}
|
|
178
|
+
export function buildDocsKnowledge(docsRoot) {
|
|
179
|
+
const files = collectMarkdownFiles(docsRoot);
|
|
180
|
+
const chunks = [];
|
|
181
|
+
for (const file of files) {
|
|
182
|
+
if (!statSync(file).isFile()) continue;
|
|
183
|
+
const markdown = readFileSync(file, "utf-8");
|
|
184
|
+
chunks.push(...chunkMarkdown(relative(docsRoot, file), markdown));
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
version: KNOWLEDGE_VERSION,
|
|
188
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
189
|
+
docsRoot: "docs",
|
|
190
|
+
chunks,
|
|
191
|
+
index: buildIndex(chunks)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { KNOWLEDGE_VERSION } from "./indexer.js";
|
|
5
|
+
export const DOCS_KNOWLEDGE_FILE = "docs.json";
|
|
6
|
+
export const API_KNOWLEDGE_FILE = "api.json";
|
|
7
|
+
export const API_KNOWLEDGE_VERSION = 1;
|
|
8
|
+
const cache = /* @__PURE__ */ new Map();
|
|
9
|
+
const apiCache = /* @__PURE__ */ new Map();
|
|
10
|
+
const CANDIDATE_SUFFIXES = [
|
|
11
|
+
"knowledge",
|
|
12
|
+
"../knowledge",
|
|
13
|
+
"../../knowledge",
|
|
14
|
+
"../../../knowledge",
|
|
15
|
+
"../dist/knowledge",
|
|
16
|
+
"../../dist/knowledge",
|
|
17
|
+
"../../../dist/knowledge",
|
|
18
|
+
"../../../../dist/knowledge"
|
|
19
|
+
];
|
|
20
|
+
export function resolveKnowledgeDir(fromUrl = import.meta.url) {
|
|
21
|
+
const override = process.env.MAPO_MCP_KNOWLEDGE_DIR;
|
|
22
|
+
if (override && existsSync(join(override, DOCS_KNOWLEDGE_FILE)))
|
|
23
|
+
return override;
|
|
24
|
+
const base = dirname(fileURLToPath(fromUrl));
|
|
25
|
+
for (const suffix of CANDIDATE_SUFFIXES) {
|
|
26
|
+
const candidate = resolve(base, suffix);
|
|
27
|
+
if (existsSync(join(candidate, DOCS_KNOWLEDGE_FILE))) return candidate;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
export class KnowledgeNotBuiltError extends Error {
|
|
32
|
+
constructor(searchedFrom) {
|
|
33
|
+
super(
|
|
34
|
+
`Mapo knowledge base not found (looked around ${searchedFrom}). Build it with \`pnpm --filter @mapomodule/mcp knowledge\`.`
|
|
35
|
+
);
|
|
36
|
+
this.name = "KnowledgeNotBuiltError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function loadDocsKnowledge(dir) {
|
|
40
|
+
const directory = dir ?? resolveKnowledgeDir();
|
|
41
|
+
if (!directory)
|
|
42
|
+
throw new KnowledgeNotBuiltError(fileURLToPath(import.meta.url));
|
|
43
|
+
const cached = cache.get(directory);
|
|
44
|
+
if (cached) return cached;
|
|
45
|
+
const file = join(directory, DOCS_KNOWLEDGE_FILE);
|
|
46
|
+
if (!existsSync(file)) throw new KnowledgeNotBuiltError(directory);
|
|
47
|
+
const knowledge = JSON.parse(readFileSync(file, "utf-8"));
|
|
48
|
+
if (knowledge.version !== KNOWLEDGE_VERSION) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Mapo knowledge base version mismatch: found ${knowledge.version}, expected ${KNOWLEDGE_VERSION}. Rebuild it.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
cache.set(directory, knowledge);
|
|
54
|
+
return knowledge;
|
|
55
|
+
}
|
|
56
|
+
export function loadApiKnowledge(dir) {
|
|
57
|
+
const directory = dir ?? resolveKnowledgeDir();
|
|
58
|
+
if (!directory)
|
|
59
|
+
throw new KnowledgeNotBuiltError(fileURLToPath(import.meta.url));
|
|
60
|
+
const cached = apiCache.get(directory);
|
|
61
|
+
if (cached) return cached;
|
|
62
|
+
const file = join(directory, API_KNOWLEDGE_FILE);
|
|
63
|
+
if (!existsSync(file)) throw new KnowledgeNotBuiltError(directory);
|
|
64
|
+
const api = JSON.parse(readFileSync(file, "utf-8"));
|
|
65
|
+
if (api.version !== API_KNOWLEDGE_VERSION) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Mapo API surface version mismatch: found ${api.version}, expected ${API_KNOWLEDGE_VERSION}. Rebuild it.`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
apiCache.set(directory, api);
|
|
71
|
+
return api;
|
|
72
|
+
}
|
|
73
|
+
export function clearKnowledgeCache() {
|
|
74
|
+
cache.clear();
|
|
75
|
+
apiCache.clear();
|
|
76
|
+
}
|
|
File without changes
|