@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
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import context from "#mapo-mcp/context.mjs";
|
|
2
|
+
import { loadApiKnowledge, loadDocsKnowledge } from "../core/knowledge.js";
|
|
3
|
+
export function useMapoMcpContext() {
|
|
4
|
+
return context;
|
|
5
|
+
}
|
|
6
|
+
export function useMapoManifest() {
|
|
7
|
+
return context.manifest;
|
|
8
|
+
}
|
|
9
|
+
export function useDocsKnowledge() {
|
|
10
|
+
return loadDocsKnowledge(context.knowledgeDir);
|
|
11
|
+
}
|
|
12
|
+
export function useMapoBackend() {
|
|
13
|
+
const { schemaUrl, tokenEnv } = context.backend;
|
|
14
|
+
return {
|
|
15
|
+
schemaUrl: schemaUrl ?? process.env.MAPO_BACKEND_SCHEMA_URL ?? null,
|
|
16
|
+
token: (tokenEnv ? process.env[tokenEnv] : void 0) ?? null
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function useApiKnowledge() {
|
|
20
|
+
return loadApiKnowledge(context.knowledgeDir);
|
|
21
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineMcpPrompt } from "@nuxtjs/mcp-toolkit/server";
|
|
2
|
+
export function toMcpPrompt(prompt) {
|
|
3
|
+
return defineMcpPrompt({
|
|
4
|
+
name: prompt.name,
|
|
5
|
+
title: prompt.title,
|
|
6
|
+
description: prompt.description,
|
|
7
|
+
inputSchema: prompt.argsSchema,
|
|
8
|
+
// The toolkit types the callback from the zod shape, which widens to
|
|
9
|
+
// `unknown` for a generic `ZodRawShape`; every argument here is an optional
|
|
10
|
+
// string, validated by zod before the handler runs.
|
|
11
|
+
handler: (args) => ({
|
|
12
|
+
messages: [
|
|
13
|
+
{
|
|
14
|
+
role: "user",
|
|
15
|
+
content: {
|
|
16
|
+
type: "text",
|
|
17
|
+
text: prompt.render(args)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineMcpTool } from "@nuxtjs/mcp-toolkit/server";
|
|
2
|
+
import {
|
|
3
|
+
useApiKnowledge,
|
|
4
|
+
useDocsKnowledge,
|
|
5
|
+
useMapoBackend,
|
|
6
|
+
useMapoManifest
|
|
7
|
+
} from "./context.js";
|
|
8
|
+
export function toMcpTool(spec) {
|
|
9
|
+
return defineMcpTool({
|
|
10
|
+
name: spec.name,
|
|
11
|
+
title: spec.title,
|
|
12
|
+
description: spec.description,
|
|
13
|
+
inputSchema: spec.inputSchema,
|
|
14
|
+
annotations: spec.annotations,
|
|
15
|
+
inputExamples: spec.inputExamples,
|
|
16
|
+
handler: async (args) => spec.run(args, {
|
|
17
|
+
knowledge: useDocsKnowledge,
|
|
18
|
+
api: useApiKnowledge,
|
|
19
|
+
manifest: useMapoManifest,
|
|
20
|
+
rootDir: () => useMapoManifest().rootDir,
|
|
21
|
+
// The module only registers in development, but be explicit: a write
|
|
22
|
+
// tool reachable from a production build is a remote code execution
|
|
23
|
+
// primitive.
|
|
24
|
+
canWrite: () => useMapoManifest().dev,
|
|
25
|
+
backend: useMapoBackend
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module.mjs'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { type MapoAppManifest, type MapoMcpContext } from './index.mjs'
|
|
8
|
+
|
|
9
|
+
export { type MapoMcpOptions, default } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "Mapo MCP server: grounded docs, component and field APIs, live app introspection and scaffolding for AI assistants",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Lotrek Agency (https://lotrek.it)",
|
|
8
|
+
"homepage": "https://lotrekagency.github.io/mapo-new/",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/lotrekagency/mapo-new.git",
|
|
12
|
+
"directory": "packages/@mapomodule/mcp"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/lotrekagency/mapo-new/issues"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"tag": "next"
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"mapo-mcp": "bin/mapo-mcp.mjs"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/module.d.mts",
|
|
27
|
+
"import": "./dist/module.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./types": {
|
|
30
|
+
"types": "./dist/index.d.mts",
|
|
31
|
+
"import": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./runtime/*": {
|
|
34
|
+
"types": "./src/runtime/*.ts",
|
|
35
|
+
"import": "./dist/runtime/*.js",
|
|
36
|
+
"default": "./src/runtime/*"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"src",
|
|
42
|
+
"bin"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "nuxt-module-build build && node scripts/clean-handler-dts.mjs && node scripts/build-knowledge.mjs",
|
|
46
|
+
"dev": "nuxt-module-build build --stub --watch",
|
|
47
|
+
"dev:prepare": "nuxt-module-build build --stub && node scripts/build-knowledge.mjs",
|
|
48
|
+
"knowledge": "node scripts/build-knowledge.mjs",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"lint": "eslint src",
|
|
51
|
+
"test": "vitest run --passWithNoTests"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
55
|
+
"@nuxtjs/mcp-toolkit": "^0.18.0",
|
|
56
|
+
"citty": "^0.1.6",
|
|
57
|
+
"consola": "^3.4.2",
|
|
58
|
+
"zod": "^4.1.13"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"nuxt": ">=4.0.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@nuxt/kit": "4.4.2",
|
|
65
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
66
|
+
"@nuxt/schema": "4.4.2",
|
|
67
|
+
"@types/node": "^25.6.0",
|
|
68
|
+
"jiti": "^2.7.0",
|
|
69
|
+
"nuxt": "^4.4.2",
|
|
70
|
+
"typescript": "^6.0.3",
|
|
71
|
+
"vitest": "^4.1.5",
|
|
72
|
+
"vue": "^3.5.32",
|
|
73
|
+
"vue-component-meta": "^3.3.4"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end check of the stdio transport: spawns the published bin and talks
|
|
3
|
+
* to it with a real MCP client. Skipped until the package is built.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
8
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
9
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
10
|
+
|
|
11
|
+
/** `contents` is a text/blob union; every resource this server serves is text. */
|
|
12
|
+
interface TextResourceContent {
|
|
13
|
+
uri: string;
|
|
14
|
+
text: string;
|
|
15
|
+
mimeType?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const binPath = fileURLToPath(
|
|
19
|
+
new URL("../../bin/mapo-mcp.mjs", import.meta.url),
|
|
20
|
+
);
|
|
21
|
+
const cliBuilt = existsSync(
|
|
22
|
+
fileURLToPath(new URL("../../dist/cli.mjs", import.meta.url)),
|
|
23
|
+
);
|
|
24
|
+
const describeBuilt = cliBuilt ? describe : describe.skip;
|
|
25
|
+
|
|
26
|
+
describeBuilt("mapo-mcp stdio server", () => {
|
|
27
|
+
let client: Client;
|
|
28
|
+
|
|
29
|
+
beforeAll(async () => {
|
|
30
|
+
client = new Client({ name: "mapo-mcp-test", version: "0.0.0" });
|
|
31
|
+
await client.connect(
|
|
32
|
+
new StdioClientTransport({
|
|
33
|
+
command: process.execPath,
|
|
34
|
+
// Port 9 (discard) is always refused: the live tools must degrade
|
|
35
|
+
// predictably instead of hitting a dev server that may be running.
|
|
36
|
+
args: [binPath, "serve", "--app", "http://127.0.0.1:9/mcp/mapo"],
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterAll(async () => {
|
|
42
|
+
await client?.close();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("advertises every tool that works without the dev server", async () => {
|
|
46
|
+
const { tools } = await client.listTools();
|
|
47
|
+
expect(tools.map((tool) => tool.name).sort()).toEqual([
|
|
48
|
+
"mapo_backend_schema",
|
|
49
|
+
"mapo_component_api",
|
|
50
|
+
"mapo_composable_api",
|
|
51
|
+
"mapo_doctor",
|
|
52
|
+
"mapo_get_doc",
|
|
53
|
+
"mapo_inspect_app",
|
|
54
|
+
"mapo_list_field_types",
|
|
55
|
+
"mapo_list_recipes",
|
|
56
|
+
"mapo_scaffold",
|
|
57
|
+
"mapo_search_docs",
|
|
58
|
+
]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("exposes the knowledge resources, including the templated ones", async () => {
|
|
62
|
+
const { resources } = await client.listResources();
|
|
63
|
+
const uris = resources.map((resource) => resource.uri);
|
|
64
|
+
|
|
65
|
+
expect(uris).toContain("mapo://knowledge/index");
|
|
66
|
+
expect(uris.some((uri) => uri.startsWith("mapo://docs/"))).toBe(true);
|
|
67
|
+
expect(uris.some((uri) => uri.startsWith("mapo://fields/"))).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("reads a documentation page through its resource URI", async () => {
|
|
71
|
+
const result = await client.readResource({
|
|
72
|
+
uri: "mapo://docs/howto/crud-list.md",
|
|
73
|
+
});
|
|
74
|
+
const content = result.contents[0] as TextResourceContent;
|
|
75
|
+
|
|
76
|
+
expect(content.mimeType).toBe("text/markdown");
|
|
77
|
+
expect(content.text).toContain("MapoList");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("reads a field type contract through its resource URI", async () => {
|
|
81
|
+
const result = await client.readResource({ uri: "mapo://fields/select" });
|
|
82
|
+
const content = result.contents[0] as TextResourceContent;
|
|
83
|
+
|
|
84
|
+
expect(content.text).toContain("Field type `select`");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("answers a docs search", async () => {
|
|
88
|
+
const result = (await client.callTool({
|
|
89
|
+
name: "mapo_search_docs",
|
|
90
|
+
arguments: { query: "CRUD list pagination", limit: 2 },
|
|
91
|
+
})) as { content: Array<{ text: string }>; isError?: boolean };
|
|
92
|
+
|
|
93
|
+
expect(result.isError).toBeFalsy();
|
|
94
|
+
expect(result.content[0]!.text).toContain("howto/");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("degrades gracefully when the app endpoint is unreachable", async () => {
|
|
98
|
+
const result = (await client.callTool({
|
|
99
|
+
name: "mapo_inspect_app",
|
|
100
|
+
arguments: {},
|
|
101
|
+
})) as { content: Array<{ text: string }>; isError?: boolean };
|
|
102
|
+
|
|
103
|
+
const text = result.content[0]!.text;
|
|
104
|
+
expect(text).toContain("mapo_inspect_app");
|
|
105
|
+
expect(text).toContain("dev server");
|
|
106
|
+
expect(text).toContain("127.0.0.1:9");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("reports invalid input instead of crashing", async () => {
|
|
110
|
+
const result = (await client
|
|
111
|
+
.callTool({
|
|
112
|
+
name: "mapo_get_doc",
|
|
113
|
+
arguments: { path: "does-not-exist.md" },
|
|
114
|
+
})
|
|
115
|
+
.catch((error: Error) => ({ content: [{ text: error.message }] }))) as {
|
|
116
|
+
content: Array<{ text: string }>;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
expect(result.content[0]!.text).toContain("mapo_search_docs");
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { runDoctor } from "../runtime/core/doctor.js";
|
|
3
|
+
import { makeManifest } from "./fixtures.js";
|
|
4
|
+
|
|
5
|
+
/** Convenience: the rule ids reported for a manifest. */
|
|
6
|
+
function rulesFor(
|
|
7
|
+
overrides: Parameters<typeof makeManifest>[0] = {},
|
|
8
|
+
): string[] {
|
|
9
|
+
return runDoctor(makeManifest(overrides)).map((finding) => finding.rule);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe("runDoctor", () => {
|
|
13
|
+
it("stays silent on a healthy app", () => {
|
|
14
|
+
expect(runDoctor(makeManifest())).toEqual([]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("flags @nuxt/ui declared after Mapo", () => {
|
|
18
|
+
const findings = runDoctor(
|
|
19
|
+
makeManifest({ moduleOrder: ["mapomodule", "@nuxt/ui"] }),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(findings[0]!.rule).toBe("nuxt-ui-order");
|
|
23
|
+
expect(findings[0]!.severity).toBe("error");
|
|
24
|
+
expect(findings[0]!.fix).toContain("before");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("flags @nuxt/ui missing entirely", () => {
|
|
28
|
+
expect(rulesFor({ moduleOrder: ["mapomodule"] })).toContain(
|
|
29
|
+
"nuxt-ui-missing",
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("ignores module order when Mapo is not registered by name", () => {
|
|
34
|
+
// An app may register the modules through a layer or an inline function.
|
|
35
|
+
expect(rulesFor({ moduleOrder: ["@nuxt/ui"] })).not.toContain(
|
|
36
|
+
"nuxt-ui-order",
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("flags a missing login route against the configured loginUrl", () => {
|
|
41
|
+
const findings = runDoctor(
|
|
42
|
+
makeManifest({ routes: [{ path: "/articles" }] }),
|
|
43
|
+
);
|
|
44
|
+
const login = findings.find(
|
|
45
|
+
(finding) => finding.rule === "login-route-missing",
|
|
46
|
+
)!;
|
|
47
|
+
|
|
48
|
+
expect(login.severity).toBe("error");
|
|
49
|
+
expect(login.message).toContain("/login");
|
|
50
|
+
expect(login.fix).toContain("MapoLogin");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("honours a custom loginUrl", () => {
|
|
54
|
+
const manifest = makeManifest({
|
|
55
|
+
config: { mapoCore: { loginUrl: "/admin/signin" } },
|
|
56
|
+
routes: [{ path: "/admin/signin" }, { path: "/articles" }],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(runDoctor(manifest).map((f) => f.rule)).not.toContain(
|
|
60
|
+
"login-route-missing",
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("reports untouched auth endpoints as info, not as an error", () => {
|
|
65
|
+
const findings = runDoctor(
|
|
66
|
+
makeManifest({ config: { mapoCore: { loginUrl: "/login" } } }),
|
|
67
|
+
);
|
|
68
|
+
const auth = findings.find(
|
|
69
|
+
(finding) => finding.rule === "auth-endpoints-default",
|
|
70
|
+
)!;
|
|
71
|
+
|
|
72
|
+
expect(auth.severity).toBe("info");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("notices an app with no admin page yet", () => {
|
|
76
|
+
expect(rulesFor({ routes: [{ path: "/login" }] })).toContain(
|
|
77
|
+
"no-admin-pages",
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("warns about locales Mapo has no catalog for", () => {
|
|
82
|
+
const findings = runDoctor(makeManifest({ locales: ["en", "fr", "de"] }));
|
|
83
|
+
const locale = findings.find((f) => f.rule === "locale-without-catalog")!;
|
|
84
|
+
|
|
85
|
+
expect(locale.message).toContain("fr, de");
|
|
86
|
+
expect(locale.message).not.toContain("en,");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("flags media fields left on the default endpoints", () => {
|
|
90
|
+
const rules = rulesFor({
|
|
91
|
+
fieldTypes: [{ type: "enhanced-media", source: "default" }],
|
|
92
|
+
});
|
|
93
|
+
expect(rules).toContain("media-endpoints-default");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("stays silent when the media endpoints are configured", () => {
|
|
97
|
+
const rules = rulesFor({
|
|
98
|
+
fieldTypes: [{ type: "media", source: "default" }],
|
|
99
|
+
config: {
|
|
100
|
+
mapoCore: makeManifest().config.mapoCore,
|
|
101
|
+
mapoMedia: {
|
|
102
|
+
endpoints: { media: "/api/cms/media", folders: "/api/cms/folders" },
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
expect(rules).not.toContain("media-endpoints-default");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("stays silent when an integration provides the media endpoints", () => {
|
|
110
|
+
const rules = rulesFor({
|
|
111
|
+
fieldTypes: [{ type: "media", source: "default" }],
|
|
112
|
+
modules: [
|
|
113
|
+
...makeManifest().modules,
|
|
114
|
+
{ name: "mapo-integrations-camomilla", version: "0.0.0" },
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
expect(rules).not.toContain("media-endpoints-default");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("detects a broken install", () => {
|
|
121
|
+
const rules = rulesFor({ modules: [{ name: "@mapomodule/uikit" }] });
|
|
122
|
+
expect(rules).toContain("core-missing");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("sorts errors before warnings and warnings before info", () => {
|
|
126
|
+
const findings = runDoctor(
|
|
127
|
+
makeManifest({
|
|
128
|
+
moduleOrder: ["mapomodule", "@nuxt/ui"],
|
|
129
|
+
routes: [],
|
|
130
|
+
locales: ["fr"],
|
|
131
|
+
config: { mapoCore: {} },
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
const severities = findings.map((finding) => finding.severity);
|
|
135
|
+
|
|
136
|
+
expect(severities).toEqual(
|
|
137
|
+
[...severities].sort(
|
|
138
|
+
(a, b) =>
|
|
139
|
+
({ error: 0, warning: 1, info: 2 })[a] -
|
|
140
|
+
{ error: 0, warning: 1, info: 2 }[b],
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
expect(severities[0]).toBe("error");
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.3",
|
|
3
|
+
"info": { "title": "Example CMS API", "version": "1.0.0" },
|
|
4
|
+
"paths": {
|
|
5
|
+
"/api/articles/": {
|
|
6
|
+
"get": {
|
|
7
|
+
"responses": {
|
|
8
|
+
"200": {
|
|
9
|
+
"content": {
|
|
10
|
+
"application/json": {
|
|
11
|
+
"schema": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"properties": {
|
|
14
|
+
"count": { "type": "integer" },
|
|
15
|
+
"results": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": { "$ref": "#/components/schemas/Article" }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"/api/articles/{id}/": {
|
|
28
|
+
"get": {
|
|
29
|
+
"responses": {
|
|
30
|
+
"200": {
|
|
31
|
+
"content": {
|
|
32
|
+
"application/json": {
|
|
33
|
+
"schema": { "$ref": "#/components/schemas/Article" }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"/api/authors/": {
|
|
41
|
+
"get": {
|
|
42
|
+
"responses": {
|
|
43
|
+
"200": {
|
|
44
|
+
"content": {
|
|
45
|
+
"application/json": {
|
|
46
|
+
"schema": {
|
|
47
|
+
"type": "array",
|
|
48
|
+
"items": { "$ref": "#/components/schemas/Author" }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"/api/tags/": {
|
|
57
|
+
"get": {
|
|
58
|
+
"responses": {
|
|
59
|
+
"200": {
|
|
60
|
+
"content": {
|
|
61
|
+
"application/json": {
|
|
62
|
+
"schema": {
|
|
63
|
+
"type": "object",
|
|
64
|
+
"properties": {
|
|
65
|
+
"results": {
|
|
66
|
+
"type": "array",
|
|
67
|
+
"items": { "$ref": "#/components/schemas/Tag" }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"components": {
|
|
79
|
+
"schemas": {
|
|
80
|
+
"Article": {
|
|
81
|
+
"type": "object",
|
|
82
|
+
"description": "A published article.",
|
|
83
|
+
"required": ["title", "status"],
|
|
84
|
+
"properties": {
|
|
85
|
+
"id": { "type": "integer", "readOnly": true },
|
|
86
|
+
"title": { "type": "string", "maxLength": 200 },
|
|
87
|
+
"body": { "type": "string" },
|
|
88
|
+
"summary": { "type": "string", "maxLength": 900 },
|
|
89
|
+
"status": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"enum": ["draft", "published", "archived"],
|
|
92
|
+
"title": "Publication status"
|
|
93
|
+
},
|
|
94
|
+
"published_at": {
|
|
95
|
+
"type": "string",
|
|
96
|
+
"format": "date-time",
|
|
97
|
+
"nullable": true
|
|
98
|
+
},
|
|
99
|
+
"release_date": { "type": "string", "format": "date" },
|
|
100
|
+
"is_featured": { "type": "boolean" },
|
|
101
|
+
"priority": { "type": "integer", "minimum": 1, "maximum": 10 },
|
|
102
|
+
"contact_email": { "type": "string", "format": "email" },
|
|
103
|
+
"canonical_url": { "type": "string", "format": "uri" },
|
|
104
|
+
"cover": { "type": "string", "format": "binary" },
|
|
105
|
+
"author": {
|
|
106
|
+
"allOf": [{ "$ref": "#/components/schemas/Author" }],
|
|
107
|
+
"nullable": true
|
|
108
|
+
},
|
|
109
|
+
"tags": {
|
|
110
|
+
"type": "array",
|
|
111
|
+
"items": { "$ref": "#/components/schemas/Tag" }
|
|
112
|
+
},
|
|
113
|
+
"keywords": { "type": "array", "items": { "type": "string" } },
|
|
114
|
+
"editor": { "allOf": [{ "$ref": "#/components/schemas/Editor" }] },
|
|
115
|
+
"created_at": {
|
|
116
|
+
"type": "string",
|
|
117
|
+
"format": "date-time",
|
|
118
|
+
"readOnly": true
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"Author": {
|
|
123
|
+
"type": "object",
|
|
124
|
+
"properties": {
|
|
125
|
+
"id": { "type": "integer", "readOnly": true },
|
|
126
|
+
"name": { "type": "string", "maxLength": 120 }
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"Tag": {
|
|
130
|
+
"type": "object",
|
|
131
|
+
"properties": {
|
|
132
|
+
"id": { "type": "integer", "readOnly": true },
|
|
133
|
+
"label": { "type": "string", "maxLength": 40 }
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"Editor": {
|
|
137
|
+
"type": "object",
|
|
138
|
+
"properties": { "id": { "type": "integer" } }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|