@intijs/mcp 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +125 -2
- package/bin/inti-mcp.js +7 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +63 -0
- package/dist/server.js.map +1 -0
- package/dist/tools.d.ts +67 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +429 -0
- package/dist/tools.js.map +1 -0
- package/package.json +69 -6
- package/src/index.ts +3 -0
- package/src/server.ts +81 -0
- package/src/tools.ts +544 -0
package/src/tools.ts
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Definition and dispatch of Inti's MCP tools.
|
|
3
|
+
*
|
|
4
|
+
* Pure module: it touches neither stdio nor the MCP SDK. It receives an
|
|
5
|
+
* already resolved adapter and exposes which tools it supports and how to
|
|
6
|
+
* run them. That keeps the protocol isolated in server.ts and this logic testable.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { validateGenerated } from '@intijs/genui';
|
|
10
|
+
import type { DataItem, Vocabulary } from '@intijs/genui';
|
|
11
|
+
|
|
12
|
+
export interface McpToolDef {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
inputSchema: {
|
|
16
|
+
type: 'object';
|
|
17
|
+
properties: Record<string, unknown>;
|
|
18
|
+
required?: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ToolCallResult {
|
|
23
|
+
/** false → the MCP client marks it as a tool error */
|
|
24
|
+
ok: boolean;
|
|
25
|
+
/** Text the agent sees */
|
|
26
|
+
text: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ToolRegistryOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Blocks every tool that writes to the CMS. Write tools stop being
|
|
32
|
+
* advertised and are rejected if they are invoked anyway.
|
|
33
|
+
*/
|
|
34
|
+
readOnly?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The blocks an agent may compose. With it, what the agent inserts is validated
|
|
37
|
+
* with the same rules as the editor's generation; without it, only the CMS decides.
|
|
38
|
+
*/
|
|
39
|
+
vocabulary?: AgentVocabulary;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AgentVocabulary {
|
|
43
|
+
blocks: Vocabulary;
|
|
44
|
+
/** What can be picked in reference fields, per source */
|
|
45
|
+
sources?: Record<string, DataItem[]>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ToolRegistry {
|
|
49
|
+
list(): McpToolDef[];
|
|
50
|
+
call(name: string, args: Record<string, unknown>): Promise<ToolCallResult>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Minimal adapter the registry expects (everything optional except the name) */
|
|
54
|
+
interface AdapterLike {
|
|
55
|
+
name?: string;
|
|
56
|
+
fetchPageBySlug?(slug: string): Promise<any>;
|
|
57
|
+
updateBlockField?(documentId: string, blockIndex: number, field: string, value: any): Promise<any>;
|
|
58
|
+
updateBlock?(documentId: string, blockIndex: number, data: Record<string, any>): Promise<any>;
|
|
59
|
+
moveBlock?(documentId: string, fromIndex: number, toIndex: number): Promise<any>;
|
|
60
|
+
insertBlock?(documentId: string, index: number, nativeType: string, data?: Record<string, any>): Promise<any>;
|
|
61
|
+
insertBlocks?(documentId: string, index: number, blocks: Array<{ nativeType: string; data?: Record<string, any> }>): Promise<any>;
|
|
62
|
+
createDraft?(documentId: string): Promise<any>;
|
|
63
|
+
publishDraft?(documentId: string): Promise<any>;
|
|
64
|
+
discardDraft?(documentId: string): Promise<any>;
|
|
65
|
+
fetchDraftBySlug?(slug: string): Promise<any>;
|
|
66
|
+
removeBlock?(documentId: string, index: number): Promise<any>;
|
|
67
|
+
duplicateBlock?(documentId: string, index: number): Promise<any>;
|
|
68
|
+
searchEntries?(collection: string, query: string): Promise<any>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ============================================
|
|
72
|
+
// Argument validation
|
|
73
|
+
// ============================================
|
|
74
|
+
|
|
75
|
+
/** Invalid argument error: reported to the agent, not thrown to the transport */
|
|
76
|
+
class ArgError extends Error {}
|
|
77
|
+
|
|
78
|
+
function str(args: Record<string, unknown>, key: string): string {
|
|
79
|
+
const value = args[key];
|
|
80
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
81
|
+
throw new ArgError(`"${key}" is required and must be a non-empty string.`);
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Integer index >= 0. Accepts the number as a string because some MCP
|
|
88
|
+
* clients serialize the schema's integers as text.
|
|
89
|
+
*/
|
|
90
|
+
function index(args: Record<string, unknown>, key: string): number {
|
|
91
|
+
const raw = args[key];
|
|
92
|
+
const value = typeof raw === 'string' && raw.trim() !== '' ? Number(raw) : raw;
|
|
93
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 0) {
|
|
94
|
+
throw new ArgError(`"${key}" is required and must be an integer >= 0.`);
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function optionalObject(args: Record<string, unknown>, key: string): Record<string, any> | undefined {
|
|
100
|
+
const value = args[key];
|
|
101
|
+
if (value === undefined || value === null) return undefined;
|
|
102
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
103
|
+
throw new ArgError(`"${key}" must be an object.`);
|
|
104
|
+
}
|
|
105
|
+
return value as Record<string, any>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ============================================
|
|
109
|
+
// Result formatting
|
|
110
|
+
// ============================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Normalizes an adapter WriteResult to text for the agent.
|
|
114
|
+
* An adapter may resolve with success: false instead of throwing.
|
|
115
|
+
*/
|
|
116
|
+
function formatWrite(action: string, result: any): ToolCallResult {
|
|
117
|
+
if (result && result.success === false) {
|
|
118
|
+
return { ok: false, text: `${action} failed: ${result.error ?? 'unknown error'}` };
|
|
119
|
+
}
|
|
120
|
+
const source = result?.source ? ` (via ${result.source})` : '';
|
|
121
|
+
const detail = result?.value !== undefined ? `\nPersisted value: ${JSON.stringify(result.value)}` : '';
|
|
122
|
+
return { ok: true, text: `${action} succeeded${source}.${detail}` };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Serializes a page with each block's explicit index: the agent needs
|
|
127
|
+
* those indexes to be able to target the write tools.
|
|
128
|
+
*/
|
|
129
|
+
function formatPage(page: any): string {
|
|
130
|
+
const blocks = Array.isArray(page?.blocks) ? page.blocks : [];
|
|
131
|
+
return JSON.stringify(
|
|
132
|
+
{
|
|
133
|
+
documentId: page?.id,
|
|
134
|
+
slug: page?.slug,
|
|
135
|
+
title: page?.title,
|
|
136
|
+
blockCount: blocks.length,
|
|
137
|
+
blocks: blocks.map((block: any, i: number) => ({
|
|
138
|
+
index: i,
|
|
139
|
+
type: block?.type,
|
|
140
|
+
nativeType: block?.meta?.label ?? undefined,
|
|
141
|
+
data: block?.data
|
|
142
|
+
}))
|
|
143
|
+
},
|
|
144
|
+
null,
|
|
145
|
+
2
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ============================================
|
|
150
|
+
// Registry
|
|
151
|
+
// ============================================
|
|
152
|
+
|
|
153
|
+
const DOCUMENT_ID = {
|
|
154
|
+
type: 'string',
|
|
155
|
+
description: 'CMS document id. Get it from inti_get_page (field "documentId").'
|
|
156
|
+
} as const;
|
|
157
|
+
|
|
158
|
+
export function createToolRegistry(adapter: AdapterLike, options: ToolRegistryOptions = {}): ToolRegistry {
|
|
159
|
+
const readOnly = options.readOnly === true;
|
|
160
|
+
const vocabulary = options.vocabulary;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Validates blocks against the vocabulary. Anything dropped is returned as an error
|
|
164
|
+
* instead of writing a half-finished block: the agent can fix it and retry.
|
|
165
|
+
*/
|
|
166
|
+
function checkBlocks(blocks: Array<{ nativeType: string; data?: Record<string, any> }>) {
|
|
167
|
+
if (!vocabulary) return blocks;
|
|
168
|
+
|
|
169
|
+
const result = validateGenerated({ blocks }, vocabulary.blocks, {
|
|
170
|
+
max: 50,
|
|
171
|
+
candidates: vocabulary.sources ?? {}
|
|
172
|
+
});
|
|
173
|
+
if (result.warnings.length > 0) {
|
|
174
|
+
throw new ArgError(`Blocks rejected by the vocabulary:\n${result.warnings.join('\n')}`);
|
|
175
|
+
}
|
|
176
|
+
return result.blocks;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Tool advertised only if the adapter implements it (and if writing is allowed) */
|
|
180
|
+
interface Entry {
|
|
181
|
+
def: McpToolDef;
|
|
182
|
+
supported: boolean;
|
|
183
|
+
write: boolean;
|
|
184
|
+
run(args: Record<string, unknown>): Promise<ToolCallResult>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const entries: Entry[] = [
|
|
188
|
+
{
|
|
189
|
+
supported: typeof adapter.fetchPageBySlug === 'function',
|
|
190
|
+
write: false,
|
|
191
|
+
def: {
|
|
192
|
+
name: 'inti_get_page',
|
|
193
|
+
description:
|
|
194
|
+
'Read a page and its blocks from the CMS by slug. Call this FIRST: it returns the documentId and the index of every block, which the write tools require.',
|
|
195
|
+
inputSchema: {
|
|
196
|
+
type: 'object',
|
|
197
|
+
properties: {
|
|
198
|
+
slug: { type: 'string', description: 'Page slug, e.g. "home" or "about".' }
|
|
199
|
+
},
|
|
200
|
+
required: ['slug']
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
run: async (args) => {
|
|
204
|
+
const page = await adapter.fetchPageBySlug!(str(args, 'slug'));
|
|
205
|
+
return { ok: true, text: formatPage(page) };
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
supported: typeof adapter.searchEntries === 'function',
|
|
210
|
+
write: false,
|
|
211
|
+
def: {
|
|
212
|
+
name: 'inti_search_entries',
|
|
213
|
+
description: 'Search entries in a CMS collection by text. Use it to find the id of a related entry.',
|
|
214
|
+
inputSchema: {
|
|
215
|
+
type: 'object',
|
|
216
|
+
properties: {
|
|
217
|
+
collection: { type: 'string', description: 'Collection or post type, e.g. "posts".' },
|
|
218
|
+
query: { type: 'string', description: 'Free-text query. Empty string lists the first results.' }
|
|
219
|
+
},
|
|
220
|
+
required: ['collection']
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
run: async (args) => {
|
|
224
|
+
const query = typeof args.query === 'string' ? args.query : '';
|
|
225
|
+
const results = await adapter.searchEntries!(str(args, 'collection'), query);
|
|
226
|
+
return { ok: true, text: JSON.stringify(results, null, 2) };
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
supported: typeof adapter.updateBlockField === 'function',
|
|
231
|
+
write: true,
|
|
232
|
+
def: {
|
|
233
|
+
name: 'inti_update_field',
|
|
234
|
+
description:
|
|
235
|
+
'Write a single field of one block back to the CMS. Supports dot-paths for nested fields ("cta.label"). Use blockIndex -1 to target a page-level field.',
|
|
236
|
+
inputSchema: {
|
|
237
|
+
type: 'object',
|
|
238
|
+
properties: {
|
|
239
|
+
documentId: DOCUMENT_ID,
|
|
240
|
+
blockIndex: {
|
|
241
|
+
type: 'integer',
|
|
242
|
+
description: 'Zero-based block index from inti_get_page, or -1 for a page-level field.'
|
|
243
|
+
},
|
|
244
|
+
field: { type: 'string', description: 'Field name. Dot-path allowed, e.g. "cta.label".' },
|
|
245
|
+
value: { description: 'New value. Usually a string.' }
|
|
246
|
+
},
|
|
247
|
+
required: ['documentId', 'blockIndex', 'field', 'value']
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
run: async (args) => {
|
|
251
|
+
// -1 is valid here (page-level field), so index() is not used
|
|
252
|
+
const raw = args.blockIndex;
|
|
253
|
+
const blockIndex = typeof raw === 'string' && raw.trim() !== '' ? Number(raw) : raw;
|
|
254
|
+
if (typeof blockIndex !== 'number' || !Number.isInteger(blockIndex) || blockIndex < -1) {
|
|
255
|
+
throw new ArgError('"blockIndex" must be an integer >= -1 (-1 targets a page-level field).');
|
|
256
|
+
}
|
|
257
|
+
if (args.value === undefined) {
|
|
258
|
+
throw new ArgError('"value" is required.');
|
|
259
|
+
}
|
|
260
|
+
if (/(^|\.)(__proto__|constructor|prototype)(\.|$)/.test(str(args, 'field'))) {
|
|
261
|
+
throw new ArgError('"field" is not a valid path.');
|
|
262
|
+
}
|
|
263
|
+
const result = await adapter.updateBlockField!(
|
|
264
|
+
str(args, 'documentId'),
|
|
265
|
+
blockIndex,
|
|
266
|
+
str(args, 'field'),
|
|
267
|
+
args.value
|
|
268
|
+
);
|
|
269
|
+
return formatWrite(`Update of "${str(args, 'field')}"`, result);
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
supported: typeof adapter.updateBlock === 'function',
|
|
274
|
+
write: true,
|
|
275
|
+
def: {
|
|
276
|
+
name: 'inti_update_block',
|
|
277
|
+
description:
|
|
278
|
+
'Replace the entire data object of one block. Destructive: fields missing from "data" are dropped. Prefer inti_update_field for single edits.',
|
|
279
|
+
inputSchema: {
|
|
280
|
+
type: 'object',
|
|
281
|
+
properties: {
|
|
282
|
+
documentId: DOCUMENT_ID,
|
|
283
|
+
blockIndex: { type: 'integer', description: 'Zero-based block index.' },
|
|
284
|
+
data: { type: 'object', description: 'Complete replacement data for the block.' }
|
|
285
|
+
},
|
|
286
|
+
required: ['documentId', 'blockIndex', 'data']
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
run: async (args) => {
|
|
290
|
+
const data = optionalObject(args, 'data');
|
|
291
|
+
if (!data) throw new ArgError('"data" is required and must be an object.');
|
|
292
|
+
const result = await adapter.updateBlock!(str(args, 'documentId'), index(args, 'blockIndex'), data);
|
|
293
|
+
return formatWrite('Block replacement', result);
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
supported: typeof adapter.insertBlock === 'function',
|
|
298
|
+
write: true,
|
|
299
|
+
def: {
|
|
300
|
+
name: 'inti_insert_block',
|
|
301
|
+
description:
|
|
302
|
+
'Insert a new block at a position. "nativeType" must be a type the CMS already knows (acf_fc_layout in WordPress, component uid in Strapi) — you cannot invent new block types here.',
|
|
303
|
+
inputSchema: {
|
|
304
|
+
type: 'object',
|
|
305
|
+
properties: {
|
|
306
|
+
documentId: DOCUMENT_ID,
|
|
307
|
+
index: { type: 'integer', description: 'Position to insert at. Use blockCount to append.' },
|
|
308
|
+
nativeType: {
|
|
309
|
+
type: 'string',
|
|
310
|
+
description: 'CMS-native block type, e.g. "hero_banner" or "sections.hero".'
|
|
311
|
+
},
|
|
312
|
+
data: { type: 'object', description: 'Optional initial field values.' }
|
|
313
|
+
},
|
|
314
|
+
required: ['documentId', 'index', 'nativeType']
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
run: async (args) => {
|
|
318
|
+
const [block] = checkBlocks([{ nativeType: str(args, 'nativeType'), data: optionalObject(args, 'data') ?? {} }]);
|
|
319
|
+
const result = await adapter.insertBlock!(
|
|
320
|
+
str(args, 'documentId'),
|
|
321
|
+
index(args, 'index'),
|
|
322
|
+
block.nativeType,
|
|
323
|
+
block.data
|
|
324
|
+
);
|
|
325
|
+
return formatWrite(`Insert of "${str(args, 'nativeType')}"`, result);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
supported: typeof adapter.insertBlocks === 'function',
|
|
330
|
+
write: true,
|
|
331
|
+
def: {
|
|
332
|
+
name: 'inti_insert_blocks',
|
|
333
|
+
description:
|
|
334
|
+
'Insert several blocks at once, in order. They all go in or none does, so prefer this over repeated inti_insert_block when composing a section.',
|
|
335
|
+
inputSchema: {
|
|
336
|
+
type: 'object',
|
|
337
|
+
properties: {
|
|
338
|
+
documentId: DOCUMENT_ID,
|
|
339
|
+
index: { type: 'integer', description: 'Position to insert at. Use blockCount to append.' },
|
|
340
|
+
blocks: {
|
|
341
|
+
type: 'array',
|
|
342
|
+
description: 'Blocks in order: [{ "nativeType": "...", "data": { ... } }].',
|
|
343
|
+
items: {
|
|
344
|
+
type: 'object',
|
|
345
|
+
properties: { nativeType: { type: 'string' }, data: { type: 'object' } },
|
|
346
|
+
required: ['nativeType']
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
required: ['documentId', 'index', 'blocks']
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
run: async (args) => {
|
|
354
|
+
if (!Array.isArray(args.blocks) || args.blocks.length === 0) {
|
|
355
|
+
throw new ArgError('"blocks" is required and must be a non-empty array.');
|
|
356
|
+
}
|
|
357
|
+
const blocks = checkBlocks(args.blocks as Array<{ nativeType: string; data?: Record<string, any> }>);
|
|
358
|
+
const result = await adapter.insertBlocks!(str(args, 'documentId'), index(args, 'index'), blocks);
|
|
359
|
+
return formatWrite(`Insert of ${blocks.length} blocks`, result);
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
supported: vocabulary !== undefined,
|
|
364
|
+
write: false,
|
|
365
|
+
def: {
|
|
366
|
+
name: 'inti_get_vocabulary',
|
|
367
|
+
description:
|
|
368
|
+
'List the block types you may compose with, their fields, and the items available for reference fields. Call this before inserting blocks.',
|
|
369
|
+
inputSchema: { type: 'object', properties: {} }
|
|
370
|
+
},
|
|
371
|
+
run: async () => ({
|
|
372
|
+
ok: true,
|
|
373
|
+
text: JSON.stringify(
|
|
374
|
+
{
|
|
375
|
+
blocks: vocabulary!.blocks,
|
|
376
|
+
// Only what is needed to choose: the server supplies the value
|
|
377
|
+
sources: Object.fromEntries(
|
|
378
|
+
Object.entries(vocabulary!.sources ?? {}).map(([name, items]) => [
|
|
379
|
+
name,
|
|
380
|
+
items.map(({ id, summary }) => ({ id, summary }))
|
|
381
|
+
])
|
|
382
|
+
)
|
|
383
|
+
},
|
|
384
|
+
null,
|
|
385
|
+
2
|
|
386
|
+
)
|
|
387
|
+
})
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
supported: typeof adapter.createDraft === 'function',
|
|
391
|
+
write: true,
|
|
392
|
+
def: {
|
|
393
|
+
name: 'inti_create_draft',
|
|
394
|
+
description:
|
|
395
|
+
'Create a working copy of a page and return its documentId. Edit that documentId instead of the published page: visitors see nothing until a person publishes it. Prefer this for any non-trivial change.',
|
|
396
|
+
inputSchema: {
|
|
397
|
+
type: 'object',
|
|
398
|
+
properties: { documentId: DOCUMENT_ID },
|
|
399
|
+
required: ['documentId']
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
run: async (args) => {
|
|
403
|
+
const result = await adapter.createDraft!(str(args, 'documentId'));
|
|
404
|
+
if (result?.success === false) return formatWrite('Draft', result);
|
|
405
|
+
return { ok: true, text: JSON.stringify({ draftDocumentId: result.documentId, slug: result.slug }) };
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
supported: typeof adapter.publishDraft === 'function',
|
|
410
|
+
write: true,
|
|
411
|
+
def: {
|
|
412
|
+
name: 'inti_publish_draft',
|
|
413
|
+
description: 'Publish a working copy over its page. Visitors see the change right away: do this only when asked to.',
|
|
414
|
+
inputSchema: {
|
|
415
|
+
type: 'object',
|
|
416
|
+
properties: { documentId: { type: 'string', description: 'The draft documentId from inti_create_draft.' } },
|
|
417
|
+
required: ['documentId']
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
run: async (args) => formatWrite('Publish', await adapter.publishDraft!(str(args, 'documentId')))
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
supported: typeof adapter.discardDraft === 'function',
|
|
424
|
+
write: true,
|
|
425
|
+
def: {
|
|
426
|
+
name: 'inti_discard_draft',
|
|
427
|
+
description: 'Throw away a working copy. The published page does not change.',
|
|
428
|
+
inputSchema: {
|
|
429
|
+
type: 'object',
|
|
430
|
+
properties: { documentId: { type: 'string', description: 'The draft documentId from inti_create_draft.' } },
|
|
431
|
+
required: ['documentId']
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
run: async (args) => formatWrite('Discard', await adapter.discardDraft!(str(args, 'documentId')))
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
supported: typeof adapter.moveBlock === 'function',
|
|
438
|
+
write: true,
|
|
439
|
+
def: {
|
|
440
|
+
name: 'inti_move_block',
|
|
441
|
+
description: 'Reorder blocks by moving one from a position to another.',
|
|
442
|
+
inputSchema: {
|
|
443
|
+
type: 'object',
|
|
444
|
+
properties: {
|
|
445
|
+
documentId: DOCUMENT_ID,
|
|
446
|
+
fromIndex: { type: 'integer', description: 'Current zero-based index.' },
|
|
447
|
+
toIndex: { type: 'integer', description: 'Target zero-based index.' }
|
|
448
|
+
},
|
|
449
|
+
required: ['documentId', 'fromIndex', 'toIndex']
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
run: async (args) => {
|
|
453
|
+
const result = await adapter.moveBlock!(
|
|
454
|
+
str(args, 'documentId'),
|
|
455
|
+
index(args, 'fromIndex'),
|
|
456
|
+
index(args, 'toIndex')
|
|
457
|
+
);
|
|
458
|
+
return formatWrite('Move', result);
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
supported: typeof adapter.duplicateBlock === 'function',
|
|
463
|
+
write: true,
|
|
464
|
+
def: {
|
|
465
|
+
name: 'inti_duplicate_block',
|
|
466
|
+
description: 'Duplicate the block at a position, inserting the copy right after it.',
|
|
467
|
+
inputSchema: {
|
|
468
|
+
type: 'object',
|
|
469
|
+
properties: {
|
|
470
|
+
documentId: DOCUMENT_ID,
|
|
471
|
+
index: { type: 'integer', description: 'Zero-based index of the block to duplicate.' }
|
|
472
|
+
},
|
|
473
|
+
required: ['documentId', 'index']
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
run: async (args) => {
|
|
477
|
+
const result = await adapter.duplicateBlock!(str(args, 'documentId'), index(args, 'index'));
|
|
478
|
+
return formatWrite('Duplicate', result);
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
supported: typeof adapter.removeBlock === 'function',
|
|
483
|
+
write: true,
|
|
484
|
+
def: {
|
|
485
|
+
name: 'inti_remove_block',
|
|
486
|
+
description:
|
|
487
|
+
'Delete the block at a position. Destructive and not undoable from here — confirm the index with inti_get_page first.',
|
|
488
|
+
inputSchema: {
|
|
489
|
+
type: 'object',
|
|
490
|
+
properties: {
|
|
491
|
+
documentId: DOCUMENT_ID,
|
|
492
|
+
index: { type: 'integer', description: 'Zero-based index of the block to delete.' }
|
|
493
|
+
},
|
|
494
|
+
required: ['documentId', 'index']
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
run: async (args) => {
|
|
498
|
+
const result = await adapter.removeBlock!(str(args, 'documentId'), index(args, 'index'));
|
|
499
|
+
return formatWrite('Delete', result);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
];
|
|
503
|
+
|
|
504
|
+
/** Only what the adapter supports and the mode allows is advertised */
|
|
505
|
+
const available = () => entries.filter((e) => e.supported && !(readOnly && e.write));
|
|
506
|
+
|
|
507
|
+
return {
|
|
508
|
+
list: () => available().map((e) => e.def),
|
|
509
|
+
|
|
510
|
+
async call(name, args) {
|
|
511
|
+
const entry = entries.find((e) => e.def.name === name);
|
|
512
|
+
|
|
513
|
+
if (!entry) {
|
|
514
|
+
const names = available()
|
|
515
|
+
.map((e) => e.def.name)
|
|
516
|
+
.join(', ');
|
|
517
|
+
return { ok: false, text: `Unknown tool "${name}". Available: ${names || 'none'}` };
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (!entry.supported) {
|
|
521
|
+
return {
|
|
522
|
+
ok: false,
|
|
523
|
+
text: `Tool "${name}" is not supported by the "${adapter.name ?? 'configured'}" adapter.`
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (readOnly && entry.write) {
|
|
528
|
+
return {
|
|
529
|
+
ok: false,
|
|
530
|
+
text: `Tool "${name}" writes to the CMS and INTI_MCP_READONLY is set. Unset it to allow writes.`
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
try {
|
|
535
|
+
return await entry.run(args ?? {});
|
|
536
|
+
} catch (error) {
|
|
537
|
+
// A CMS failure or an invalid argument is reported to the agent
|
|
538
|
+
// as a tool result, never as a server crash.
|
|
539
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
540
|
+
return { ok: false, text: `${name} failed: ${message}` };
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
}
|