payload-mcp-toolkit 0.2.0 → 0.3.0

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.
@@ -1,139 +0,0 @@
1
- import { z } from 'zod';
2
- import type { BlockCatalog } from '../types';
3
- import { type SectionInput } from './compose-helpers';
4
- /**
5
- * Create the composePageLayout MCP tool from the introspected block catalog.
6
- *
7
- * Validates and composes a layout array from natural section/leaf inputs.
8
- * Returns the composed JSON ready to be written to a doc's `layout` field —
9
- * use updateDocument or patchLayout to actually persist the result.
10
- */
11
- export declare function createComposeLayoutTool(catalog: BlockCatalog): {
12
- name: string;
13
- description: string;
14
- parameters: z.ZodObject<{
15
- sections: z.ZodArray<z.ZodObject<{
16
- sectionType: z.ZodString;
17
- config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
18
- content: z.ZodOptional<z.ZodArray<z.ZodObject<{
19
- blockType: z.ZodString;
20
- fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
21
- }, "strip", z.ZodTypeAny, {
22
- blockType: string;
23
- fields?: Record<string, unknown> | undefined;
24
- }, {
25
- blockType: string;
26
- fields?: Record<string, unknown> | undefined;
27
- }>, "many">>;
28
- leftColumn: z.ZodOptional<z.ZodArray<z.ZodObject<{
29
- blockType: z.ZodString;
30
- fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
31
- }, "strip", z.ZodTypeAny, {
32
- blockType: string;
33
- fields?: Record<string, unknown> | undefined;
34
- }, {
35
- blockType: string;
36
- fields?: Record<string, unknown> | undefined;
37
- }>, "many">>;
38
- rightColumn: z.ZodOptional<z.ZodArray<z.ZodObject<{
39
- blockType: z.ZodString;
40
- fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
41
- }, "strip", z.ZodTypeAny, {
42
- blockType: string;
43
- fields?: Record<string, unknown> | undefined;
44
- }, {
45
- blockType: string;
46
- fields?: Record<string, unknown> | undefined;
47
- }>, "many">>;
48
- fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
49
- }, "strip", z.ZodTypeAny, {
50
- sectionType: string;
51
- fields?: Record<string, unknown> | undefined;
52
- config?: Record<string, unknown> | undefined;
53
- content?: {
54
- blockType: string;
55
- fields?: Record<string, unknown> | undefined;
56
- }[] | undefined;
57
- leftColumn?: {
58
- blockType: string;
59
- fields?: Record<string, unknown> | undefined;
60
- }[] | undefined;
61
- rightColumn?: {
62
- blockType: string;
63
- fields?: Record<string, unknown> | undefined;
64
- }[] | undefined;
65
- }, {
66
- sectionType: string;
67
- fields?: Record<string, unknown> | undefined;
68
- config?: Record<string, unknown> | undefined;
69
- content?: {
70
- blockType: string;
71
- fields?: Record<string, unknown> | undefined;
72
- }[] | undefined;
73
- leftColumn?: {
74
- blockType: string;
75
- fields?: Record<string, unknown> | undefined;
76
- }[] | undefined;
77
- rightColumn?: {
78
- blockType: string;
79
- fields?: Record<string, unknown> | undefined;
80
- }[] | undefined;
81
- }>, "many">;
82
- operation: z.ZodDefault<z.ZodOptional<z.ZodEnum<["full", "append", "prepend", "insertAt", "replaceAt"]>>>;
83
- insertIndex: z.ZodOptional<z.ZodNumber>;
84
- existingLayout: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">>;
85
- }, "strip", z.ZodTypeAny, {
86
- sections: {
87
- sectionType: string;
88
- fields?: Record<string, unknown> | undefined;
89
- config?: Record<string, unknown> | undefined;
90
- content?: {
91
- blockType: string;
92
- fields?: Record<string, unknown> | undefined;
93
- }[] | undefined;
94
- leftColumn?: {
95
- blockType: string;
96
- fields?: Record<string, unknown> | undefined;
97
- }[] | undefined;
98
- rightColumn?: {
99
- blockType: string;
100
- fields?: Record<string, unknown> | undefined;
101
- }[] | undefined;
102
- }[];
103
- operation: "full" | "append" | "prepend" | "insertAt" | "replaceAt";
104
- insertIndex?: number | undefined;
105
- existingLayout?: Record<string, unknown>[] | undefined;
106
- }, {
107
- sections: {
108
- sectionType: string;
109
- fields?: Record<string, unknown> | undefined;
110
- config?: Record<string, unknown> | undefined;
111
- content?: {
112
- blockType: string;
113
- fields?: Record<string, unknown> | undefined;
114
- }[] | undefined;
115
- leftColumn?: {
116
- blockType: string;
117
- fields?: Record<string, unknown> | undefined;
118
- }[] | undefined;
119
- rightColumn?: {
120
- blockType: string;
121
- fields?: Record<string, unknown> | undefined;
122
- }[] | undefined;
123
- }[];
124
- operation?: "full" | "append" | "prepend" | "insertAt" | "replaceAt" | undefined;
125
- insertIndex?: number | undefined;
126
- existingLayout?: Record<string, unknown>[] | undefined;
127
- }>;
128
- handler: (args: {
129
- sections: SectionInput[];
130
- operation?: "full" | "append" | "prepend" | "insertAt" | "replaceAt";
131
- insertIndex?: number;
132
- existingLayout?: Record<string, unknown>[];
133
- }) => Promise<{
134
- content: {
135
- type: "text";
136
- text: string;
137
- }[];
138
- }>;
139
- };
@@ -1,61 +0,0 @@
1
- import { z } from 'zod';
2
- import { applyOperation, buildHint, composeSections, sectionSchema } from './compose-helpers';
3
- /**
4
- * Create the composePageLayout MCP tool from the introspected block catalog.
5
- *
6
- * Validates and composes a layout array from natural section/leaf inputs.
7
- * Returns the composed JSON ready to be written to a doc's `layout` field —
8
- * use updateDocument or patchLayout to actually persist the result.
9
- */ export function createComposeLayoutTool(catalog) {
10
- const sectionSlugs = catalog.sections.map((s)=>s.slug);
11
- const leafSlugs = catalog.leaves.map((l)=>l.slug);
12
- return {
13
- name: 'composePageLayout',
14
- description: 'Compose a page layout from section and leaf blocks. Validates nesting rules and required fields. ' + 'Returns block JSON ready for the Payload page layout field. ' + `Available sections: ${sectionSlugs.join(', ')}. Available leaves: ${leafSlugs.join(', ')}.`,
15
- parameters: z.object({
16
- sections: z.array(sectionSchema).describe('Array of section blocks to compose into a layout'),
17
- operation: z.enum([
18
- 'full',
19
- 'append',
20
- 'prepend',
21
- 'insertAt',
22
- 'replaceAt'
23
- ]).optional().default('full').describe('How to apply sections: full replace, append, prepend, insertAt, or replaceAt'),
24
- insertIndex: z.number().optional().describe('Index for insertAt/replaceAt operations'),
25
- existingLayout: z.array(z.record(z.string(), z.unknown())).optional().describe('Current page layout JSON for partial update operations')
26
- }),
27
- handler: async (args)=>{
28
- const { sections, operation = 'full', insertIndex, existingLayout } = args;
29
- const { blocks, errors } = composeSections(sections, catalog);
30
- if (errors.length > 0) {
31
- return {
32
- content: [
33
- {
34
- type: 'text',
35
- text: JSON.stringify({
36
- success: false,
37
- errors,
38
- hint: buildHint(catalog)
39
- })
40
- }
41
- ]
42
- };
43
- }
44
- const finalLayout = applyOperation(blocks, operation, insertIndex, existingLayout);
45
- return {
46
- content: [
47
- {
48
- type: 'text',
49
- text: JSON.stringify({
50
- success: true,
51
- layout: finalLayout,
52
- blockCount: finalLayout.length
53
- })
54
- }
55
- ]
56
- };
57
- }
58
- };
59
- }
60
-
61
- //# sourceMappingURL=compose-layout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/tools/compose-layout.ts"],"sourcesContent":["import { z } from 'zod'\nimport type { BlockCatalog } from '../types'\nimport {\n applyOperation,\n buildHint,\n composeSections,\n sectionSchema,\n type SectionInput,\n} from './compose-helpers'\n\n/**\n * Create the composePageLayout MCP tool from the introspected block catalog.\n *\n * Validates and composes a layout array from natural section/leaf inputs.\n * Returns the composed JSON ready to be written to a doc's `layout` field —\n * use updateDocument or patchLayout to actually persist the result.\n */\nexport function createComposeLayoutTool(catalog: BlockCatalog) {\n const sectionSlugs = catalog.sections.map((s) => s.slug)\n const leafSlugs = catalog.leaves.map((l) => l.slug)\n\n return {\n name: 'composePageLayout',\n description:\n 'Compose a page layout from section and leaf blocks. Validates nesting rules and required fields. ' +\n 'Returns block JSON ready for the Payload page layout field. ' +\n `Available sections: ${sectionSlugs.join(', ')}. Available leaves: ${leafSlugs.join(', ')}.`,\n parameters: z.object({\n sections: z\n .array(sectionSchema)\n .describe('Array of section blocks to compose into a layout'),\n operation: z\n .enum(['full', 'append', 'prepend', 'insertAt', 'replaceAt'])\n .optional()\n .default('full')\n .describe('How to apply sections: full replace, append, prepend, insertAt, or replaceAt'),\n insertIndex: z\n .number()\n .optional()\n .describe('Index for insertAt/replaceAt operations'),\n existingLayout: z\n .array(z.record(z.string(), z.unknown()))\n .optional()\n .describe('Current page layout JSON for partial update operations'),\n }),\n handler: async (args: {\n sections: SectionInput[]\n operation?: 'full' | 'append' | 'prepend' | 'insertAt' | 'replaceAt'\n insertIndex?: number\n existingLayout?: Record<string, unknown>[]\n }) => {\n const { sections, operation = 'full', insertIndex, existingLayout } = args\n\n const { blocks, errors } = composeSections(sections, catalog)\n\n if (errors.length > 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify({\n success: false,\n errors,\n hint: buildHint(catalog),\n }),\n },\n ],\n }\n }\n\n const finalLayout = applyOperation(blocks, operation, insertIndex, existingLayout)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify({\n success: true,\n layout: finalLayout,\n blockCount: finalLayout.length,\n }),\n },\n ],\n }\n },\n }\n}\n"],"names":["z","applyOperation","buildHint","composeSections","sectionSchema","createComposeLayoutTool","catalog","sectionSlugs","sections","map","s","slug","leafSlugs","leaves","l","name","description","join","parameters","object","array","describe","operation","enum","optional","default","insertIndex","number","existingLayout","record","string","unknown","handler","args","blocks","errors","length","content","type","text","JSON","stringify","success","hint","finalLayout","layout","blockCount"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SACEC,cAAc,EACdC,SAAS,EACTC,eAAe,EACfC,aAAa,QAER,oBAAmB;AAE1B;;;;;;CAMC,GACD,OAAO,SAASC,wBAAwBC,OAAqB;IAC3D,MAAMC,eAAeD,QAAQE,QAAQ,CAACC,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI;IACvD,MAAMC,YAAYN,QAAQO,MAAM,CAACJ,GAAG,CAAC,CAACK,IAAMA,EAAEH,IAAI;IAElD,OAAO;QACLI,MAAM;QACNC,aACE,sGACA,iE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