@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,28 @@
|
|
|
1
|
+
import { defineMcpResource } from "@nuxtjs/mcp-toolkit/server";
|
|
2
|
+
import { MANIFEST_URI } from "../../../../core/resources.js";
|
|
3
|
+
import { useMapoManifest } from "../../../../nitro/context.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The only resource that depends on the running app: a build-time snapshot of
|
|
7
|
+
* the consuming project (installed mapo modules, public config, registered
|
|
8
|
+
* field types, Mapo components, admin routes, locales).
|
|
9
|
+
*
|
|
10
|
+
* Not available from the stdio CLI, which knows nothing about the app.
|
|
11
|
+
*/
|
|
12
|
+
export default defineMcpResource({
|
|
13
|
+
name: "mapo-app-manifest",
|
|
14
|
+
title: "This app's Mapo setup",
|
|
15
|
+
description:
|
|
16
|
+
"Installed Mapo modules, public Mapo config, registered field types, available components, admin routes and locales of the app currently running.",
|
|
17
|
+
uri: MANIFEST_URI,
|
|
18
|
+
metadata: { mimeType: "application/json" },
|
|
19
|
+
handler: (uri: URL) => ({
|
|
20
|
+
contents: [
|
|
21
|
+
{
|
|
22
|
+
uri: uri.toString(),
|
|
23
|
+
mimeType: "application/json",
|
|
24
|
+
text: JSON.stringify(useMapoManifest(), null, 2),
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { defineMcpResource } from "@nuxtjs/mcp-toolkit/server";
|
|
3
|
+
import {
|
|
4
|
+
DOCS_URI_PREFIX,
|
|
5
|
+
docResourceList,
|
|
6
|
+
renderDocResource,
|
|
7
|
+
} from "../../../../core/resources.js";
|
|
8
|
+
import { useDocsKnowledge } from "../../../../nitro/context.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `{+path}` (reserved expansion) is required: doc paths contain slashes, which
|
|
12
|
+
* a plain `{path}` variable would not match.
|
|
13
|
+
*/
|
|
14
|
+
export default defineMcpResource({
|
|
15
|
+
name: "mapo-doc",
|
|
16
|
+
title: "Mapo documentation page",
|
|
17
|
+
description:
|
|
18
|
+
"A full Mapo documentation page, addressed by its path (e.g. howto/crud-list.md).",
|
|
19
|
+
uri: new ResourceTemplate(`${DOCS_URI_PREFIX}{+path}`, {
|
|
20
|
+
list: () => ({ resources: docResourceList(useDocsKnowledge()) }),
|
|
21
|
+
}),
|
|
22
|
+
metadata: { mimeType: "text/markdown" },
|
|
23
|
+
handler: (uri: URL, variables: Record<string, string | string[]>) => {
|
|
24
|
+
const raw = variables.path;
|
|
25
|
+
const path = Array.isArray(raw) ? raw.join("/") : (raw ?? "");
|
|
26
|
+
const text = renderDocResource(
|
|
27
|
+
useDocsKnowledge(),
|
|
28
|
+
decodeURIComponent(path),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
contents: [
|
|
33
|
+
{
|
|
34
|
+
uri: uri.toString(),
|
|
35
|
+
mimeType: "text/markdown",
|
|
36
|
+
text: text ?? `No documentation page at "${path}".`,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { defineMcpResource } from "@nuxtjs/mcp-toolkit/server";
|
|
3
|
+
import {
|
|
4
|
+
FIELD_URI_PREFIX,
|
|
5
|
+
fieldResourceList,
|
|
6
|
+
renderFieldResource,
|
|
7
|
+
} from "../../../../core/resources.js";
|
|
8
|
+
import { useApiKnowledge } from "../../../../nitro/context.js";
|
|
9
|
+
|
|
10
|
+
export default defineMcpResource({
|
|
11
|
+
name: "mapo-field-type",
|
|
12
|
+
title: "Mapo form field type",
|
|
13
|
+
description:
|
|
14
|
+
"The full contract of a form field type: the component behind it, its attrs and the shared descriptor properties.",
|
|
15
|
+
uri: new ResourceTemplate(`${FIELD_URI_PREFIX}{type}`, {
|
|
16
|
+
list: () => ({ resources: fieldResourceList(useApiKnowledge()) }),
|
|
17
|
+
}),
|
|
18
|
+
metadata: { mimeType: "text/markdown" },
|
|
19
|
+
handler: (uri: URL, variables: Record<string, string | string[]>) => {
|
|
20
|
+
const raw = variables.type;
|
|
21
|
+
const type = Array.isArray(raw) ? raw[0]! : (raw ?? "");
|
|
22
|
+
const text = renderFieldResource(
|
|
23
|
+
useApiKnowledge(),
|
|
24
|
+
decodeURIComponent(type),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
contents: [
|
|
29
|
+
{
|
|
30
|
+
uri: uri.toString(),
|
|
31
|
+
mimeType: "text/markdown",
|
|
32
|
+
text: text ?? `No field type "${type}" is registered.`,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineMcpResource } from "@nuxtjs/mcp-toolkit/server";
|
|
2
|
+
import { INDEX_URI, renderKnowledgeIndex } from "../../../../core/resources.js";
|
|
3
|
+
import {
|
|
4
|
+
useApiKnowledge,
|
|
5
|
+
useDocsKnowledge,
|
|
6
|
+
} from "../../../../nitro/context.js";
|
|
7
|
+
|
|
8
|
+
export default defineMcpResource({
|
|
9
|
+
name: "mapo-knowledge-index",
|
|
10
|
+
title: "Mapo knowledge index",
|
|
11
|
+
description:
|
|
12
|
+
"Everything the Mapo MCP server knows: recipes, documentation pages, components, field types and composables.",
|
|
13
|
+
uri: INDEX_URI,
|
|
14
|
+
metadata: { mimeType: "text/markdown" },
|
|
15
|
+
handler: (uri: URL) => ({
|
|
16
|
+
contents: [
|
|
17
|
+
{
|
|
18
|
+
uri: uri.toString(),
|
|
19
|
+
mimeType: "text/markdown",
|
|
20
|
+
text: renderKnowledgeIndex(useDocsKnowledge(), useApiKnowledge()),
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge between the Nitro-side MCP definitions and the build-time context
|
|
3
|
+
* injected by the module (`#mapo-mcp/context.mjs`).
|
|
4
|
+
*/
|
|
5
|
+
import context from "#mapo-mcp/context.mjs";
|
|
6
|
+
import { loadApiKnowledge, loadDocsKnowledge } from "../core/knowledge.js";
|
|
7
|
+
import type { ApiKnowledge, DocsKnowledge } from "../core/types.js";
|
|
8
|
+
import type { MapoAppManifest, MapoMcpContext } from "../../index";
|
|
9
|
+
|
|
10
|
+
export function useMapoMcpContext(): MapoMcpContext {
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function useMapoManifest(): MapoAppManifest {
|
|
15
|
+
return context.manifest;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Loads the bundled docs index from the absolute path resolved at build time. */
|
|
19
|
+
export function useDocsKnowledge(): DocsKnowledge {
|
|
20
|
+
return loadDocsKnowledge(context.knowledgeDir);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Backend schema source. The module stores the *name* of the env var holding
|
|
25
|
+
* the token; resolving it here keeps the secret out of the build output.
|
|
26
|
+
*/
|
|
27
|
+
export function useMapoBackend(): {
|
|
28
|
+
schemaUrl: string | null;
|
|
29
|
+
token: string | null;
|
|
30
|
+
} {
|
|
31
|
+
const { schemaUrl, tokenEnv } = context.backend;
|
|
32
|
+
return {
|
|
33
|
+
schemaUrl: schemaUrl ?? process.env.MAPO_BACKEND_SCHEMA_URL ?? null,
|
|
34
|
+
token: (tokenEnv ? process.env[tokenEnv] : undefined) ?? null,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Loads the component/field/composable surface extracted from source. */
|
|
39
|
+
export function useApiKnowledge(): ApiKnowledge {
|
|
40
|
+
return loadApiKnowledge(context.knowledgeDir);
|
|
41
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Adapter: shared prompt spec → `@nuxtjs/mcp-toolkit` definition. */
|
|
2
|
+
import { defineMcpPrompt } from "@nuxtjs/mcp-toolkit/server";
|
|
3
|
+
import type { MapoPrompt } from "../core/prompts.js";
|
|
4
|
+
|
|
5
|
+
// Lives outside `runtime/mcp/` for the same reason as `to-mcp-tool.ts`: every
|
|
6
|
+
// top-level file of a scanned path is loaded as a handler definition.
|
|
7
|
+
export function toMcpPrompt(
|
|
8
|
+
prompt: MapoPrompt<Record<string, string | undefined>>,
|
|
9
|
+
) {
|
|
10
|
+
return defineMcpPrompt({
|
|
11
|
+
name: prompt.name,
|
|
12
|
+
title: prompt.title,
|
|
13
|
+
description: prompt.description,
|
|
14
|
+
inputSchema: prompt.argsSchema,
|
|
15
|
+
// The toolkit types the callback from the zod shape, which widens to
|
|
16
|
+
// `unknown` for a generic `ZodRawShape`; every argument here is an optional
|
|
17
|
+
// string, validated by zod before the handler runs.
|
|
18
|
+
handler: (args: Record<string, unknown>) => ({
|
|
19
|
+
messages: [
|
|
20
|
+
{
|
|
21
|
+
role: "user" as const,
|
|
22
|
+
content: {
|
|
23
|
+
type: "text" as const,
|
|
24
|
+
text: prompt.render(args as Record<string, string | undefined>),
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Adapter: shared tool spec → `@nuxtjs/mcp-toolkit` definition. */
|
|
2
|
+
import { defineMcpTool } from "@nuxtjs/mcp-toolkit/server";
|
|
3
|
+
import {
|
|
4
|
+
useApiKnowledge,
|
|
5
|
+
useDocsKnowledge,
|
|
6
|
+
useMapoBackend,
|
|
7
|
+
useMapoManifest,
|
|
8
|
+
} from "./context.js";
|
|
9
|
+
import type { AnyMapoToolSpec } from "../core/tool-spec.js";
|
|
10
|
+
// NOTE: this file must stay OUT of `runtime/mcp/`. The toolkit treats every
|
|
11
|
+
// top-level file of a scanned handler path as a handler definition, so a helper
|
|
12
|
+
// living there would be loaded as one and fail the Nitro build.
|
|
13
|
+
|
|
14
|
+
export function toMcpTool(spec: AnyMapoToolSpec) {
|
|
15
|
+
return defineMcpTool({
|
|
16
|
+
name: spec.name,
|
|
17
|
+
title: spec.title,
|
|
18
|
+
description: spec.description,
|
|
19
|
+
inputSchema: spec.inputSchema,
|
|
20
|
+
annotations: spec.annotations,
|
|
21
|
+
inputExamples: spec.inputExamples,
|
|
22
|
+
handler: async (args: Record<string, unknown>) =>
|
|
23
|
+
spec.run(args, {
|
|
24
|
+
knowledge: useDocsKnowledge,
|
|
25
|
+
api: useApiKnowledge,
|
|
26
|
+
manifest: useMapoManifest,
|
|
27
|
+
rootDir: () => useMapoManifest().rootDir,
|
|
28
|
+
// The module only registers in development, but be explicit: a write
|
|
29
|
+
// tool reachable from a production build is a remote code execution
|
|
30
|
+
// primitive.
|
|
31
|
+
canWrite: () => useMapoManifest().dev,
|
|
32
|
+
backend: useMapoBackend,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
}
|