@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/dist/tools.js
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
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
|
+
import { validateGenerated } from '@intijs/genui';
|
|
9
|
+
// ============================================
|
|
10
|
+
// Argument validation
|
|
11
|
+
// ============================================
|
|
12
|
+
/** Invalid argument error: reported to the agent, not thrown to the transport */
|
|
13
|
+
class ArgError extends Error {
|
|
14
|
+
}
|
|
15
|
+
function str(args, key) {
|
|
16
|
+
const value = args[key];
|
|
17
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
18
|
+
throw new ArgError(`"${key}" is required and must be a non-empty string.`);
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Integer index >= 0. Accepts the number as a string because some MCP
|
|
24
|
+
* clients serialize the schema's integers as text.
|
|
25
|
+
*/
|
|
26
|
+
function index(args, key) {
|
|
27
|
+
const raw = args[key];
|
|
28
|
+
const value = typeof raw === 'string' && raw.trim() !== '' ? Number(raw) : raw;
|
|
29
|
+
if (typeof value !== 'number' || !Number.isInteger(value) || value < 0) {
|
|
30
|
+
throw new ArgError(`"${key}" is required and must be an integer >= 0.`);
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function optionalObject(args, key) {
|
|
35
|
+
const value = args[key];
|
|
36
|
+
if (value === undefined || value === null)
|
|
37
|
+
return undefined;
|
|
38
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
39
|
+
throw new ArgError(`"${key}" must be an object.`);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
// ============================================
|
|
44
|
+
// Result formatting
|
|
45
|
+
// ============================================
|
|
46
|
+
/**
|
|
47
|
+
* Normalizes an adapter WriteResult to text for the agent.
|
|
48
|
+
* An adapter may resolve with success: false instead of throwing.
|
|
49
|
+
*/
|
|
50
|
+
function formatWrite(action, result) {
|
|
51
|
+
if (result && result.success === false) {
|
|
52
|
+
return { ok: false, text: `${action} failed: ${result.error ?? 'unknown error'}` };
|
|
53
|
+
}
|
|
54
|
+
const source = result?.source ? ` (via ${result.source})` : '';
|
|
55
|
+
const detail = result?.value !== undefined ? `\nPersisted value: ${JSON.stringify(result.value)}` : '';
|
|
56
|
+
return { ok: true, text: `${action} succeeded${source}.${detail}` };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Serializes a page with each block's explicit index: the agent needs
|
|
60
|
+
* those indexes to be able to target the write tools.
|
|
61
|
+
*/
|
|
62
|
+
function formatPage(page) {
|
|
63
|
+
const blocks = Array.isArray(page?.blocks) ? page.blocks : [];
|
|
64
|
+
return JSON.stringify({
|
|
65
|
+
documentId: page?.id,
|
|
66
|
+
slug: page?.slug,
|
|
67
|
+
title: page?.title,
|
|
68
|
+
blockCount: blocks.length,
|
|
69
|
+
blocks: blocks.map((block, i) => ({
|
|
70
|
+
index: i,
|
|
71
|
+
type: block?.type,
|
|
72
|
+
nativeType: block?.meta?.label ?? undefined,
|
|
73
|
+
data: block?.data
|
|
74
|
+
}))
|
|
75
|
+
}, null, 2);
|
|
76
|
+
}
|
|
77
|
+
// ============================================
|
|
78
|
+
// Registry
|
|
79
|
+
// ============================================
|
|
80
|
+
const DOCUMENT_ID = {
|
|
81
|
+
type: 'string',
|
|
82
|
+
description: 'CMS document id. Get it from inti_get_page (field "documentId").'
|
|
83
|
+
};
|
|
84
|
+
export function createToolRegistry(adapter, options = {}) {
|
|
85
|
+
const readOnly = options.readOnly === true;
|
|
86
|
+
const vocabulary = options.vocabulary;
|
|
87
|
+
/**
|
|
88
|
+
* Validates blocks against the vocabulary. Anything dropped is returned as an error
|
|
89
|
+
* instead of writing a half-finished block: the agent can fix it and retry.
|
|
90
|
+
*/
|
|
91
|
+
function checkBlocks(blocks) {
|
|
92
|
+
if (!vocabulary)
|
|
93
|
+
return blocks;
|
|
94
|
+
const result = validateGenerated({ blocks }, vocabulary.blocks, {
|
|
95
|
+
max: 50,
|
|
96
|
+
candidates: vocabulary.sources ?? {}
|
|
97
|
+
});
|
|
98
|
+
if (result.warnings.length > 0) {
|
|
99
|
+
throw new ArgError(`Blocks rejected by the vocabulary:\n${result.warnings.join('\n')}`);
|
|
100
|
+
}
|
|
101
|
+
return result.blocks;
|
|
102
|
+
}
|
|
103
|
+
const entries = [
|
|
104
|
+
{
|
|
105
|
+
supported: typeof adapter.fetchPageBySlug === 'function',
|
|
106
|
+
write: false,
|
|
107
|
+
def: {
|
|
108
|
+
name: 'inti_get_page',
|
|
109
|
+
description: '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.',
|
|
110
|
+
inputSchema: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
slug: { type: 'string', description: 'Page slug, e.g. "home" or "about".' }
|
|
114
|
+
},
|
|
115
|
+
required: ['slug']
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
run: async (args) => {
|
|
119
|
+
const page = await adapter.fetchPageBySlug(str(args, 'slug'));
|
|
120
|
+
return { ok: true, text: formatPage(page) };
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
supported: typeof adapter.searchEntries === 'function',
|
|
125
|
+
write: false,
|
|
126
|
+
def: {
|
|
127
|
+
name: 'inti_search_entries',
|
|
128
|
+
description: 'Search entries in a CMS collection by text. Use it to find the id of a related entry.',
|
|
129
|
+
inputSchema: {
|
|
130
|
+
type: 'object',
|
|
131
|
+
properties: {
|
|
132
|
+
collection: { type: 'string', description: 'Collection or post type, e.g. "posts".' },
|
|
133
|
+
query: { type: 'string', description: 'Free-text query. Empty string lists the first results.' }
|
|
134
|
+
},
|
|
135
|
+
required: ['collection']
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
run: async (args) => {
|
|
139
|
+
const query = typeof args.query === 'string' ? args.query : '';
|
|
140
|
+
const results = await adapter.searchEntries(str(args, 'collection'), query);
|
|
141
|
+
return { ok: true, text: JSON.stringify(results, null, 2) };
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
supported: typeof adapter.updateBlockField === 'function',
|
|
146
|
+
write: true,
|
|
147
|
+
def: {
|
|
148
|
+
name: 'inti_update_field',
|
|
149
|
+
description: '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.',
|
|
150
|
+
inputSchema: {
|
|
151
|
+
type: 'object',
|
|
152
|
+
properties: {
|
|
153
|
+
documentId: DOCUMENT_ID,
|
|
154
|
+
blockIndex: {
|
|
155
|
+
type: 'integer',
|
|
156
|
+
description: 'Zero-based block index from inti_get_page, or -1 for a page-level field.'
|
|
157
|
+
},
|
|
158
|
+
field: { type: 'string', description: 'Field name. Dot-path allowed, e.g. "cta.label".' },
|
|
159
|
+
value: { description: 'New value. Usually a string.' }
|
|
160
|
+
},
|
|
161
|
+
required: ['documentId', 'blockIndex', 'field', 'value']
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
run: async (args) => {
|
|
165
|
+
// -1 is valid here (page-level field), so index() is not used
|
|
166
|
+
const raw = args.blockIndex;
|
|
167
|
+
const blockIndex = typeof raw === 'string' && raw.trim() !== '' ? Number(raw) : raw;
|
|
168
|
+
if (typeof blockIndex !== 'number' || !Number.isInteger(blockIndex) || blockIndex < -1) {
|
|
169
|
+
throw new ArgError('"blockIndex" must be an integer >= -1 (-1 targets a page-level field).');
|
|
170
|
+
}
|
|
171
|
+
if (args.value === undefined) {
|
|
172
|
+
throw new ArgError('"value" is required.');
|
|
173
|
+
}
|
|
174
|
+
if (/(^|\.)(__proto__|constructor|prototype)(\.|$)/.test(str(args, 'field'))) {
|
|
175
|
+
throw new ArgError('"field" is not a valid path.');
|
|
176
|
+
}
|
|
177
|
+
const result = await adapter.updateBlockField(str(args, 'documentId'), blockIndex, str(args, 'field'), args.value);
|
|
178
|
+
return formatWrite(`Update of "${str(args, 'field')}"`, result);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
supported: typeof adapter.updateBlock === 'function',
|
|
183
|
+
write: true,
|
|
184
|
+
def: {
|
|
185
|
+
name: 'inti_update_block',
|
|
186
|
+
description: 'Replace the entire data object of one block. Destructive: fields missing from "data" are dropped. Prefer inti_update_field for single edits.',
|
|
187
|
+
inputSchema: {
|
|
188
|
+
type: 'object',
|
|
189
|
+
properties: {
|
|
190
|
+
documentId: DOCUMENT_ID,
|
|
191
|
+
blockIndex: { type: 'integer', description: 'Zero-based block index.' },
|
|
192
|
+
data: { type: 'object', description: 'Complete replacement data for the block.' }
|
|
193
|
+
},
|
|
194
|
+
required: ['documentId', 'blockIndex', 'data']
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
run: async (args) => {
|
|
198
|
+
const data = optionalObject(args, 'data');
|
|
199
|
+
if (!data)
|
|
200
|
+
throw new ArgError('"data" is required and must be an object.');
|
|
201
|
+
const result = await adapter.updateBlock(str(args, 'documentId'), index(args, 'blockIndex'), data);
|
|
202
|
+
return formatWrite('Block replacement', result);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
supported: typeof adapter.insertBlock === 'function',
|
|
207
|
+
write: true,
|
|
208
|
+
def: {
|
|
209
|
+
name: 'inti_insert_block',
|
|
210
|
+
description: '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.',
|
|
211
|
+
inputSchema: {
|
|
212
|
+
type: 'object',
|
|
213
|
+
properties: {
|
|
214
|
+
documentId: DOCUMENT_ID,
|
|
215
|
+
index: { type: 'integer', description: 'Position to insert at. Use blockCount to append.' },
|
|
216
|
+
nativeType: {
|
|
217
|
+
type: 'string',
|
|
218
|
+
description: 'CMS-native block type, e.g. "hero_banner" or "sections.hero".'
|
|
219
|
+
},
|
|
220
|
+
data: { type: 'object', description: 'Optional initial field values.' }
|
|
221
|
+
},
|
|
222
|
+
required: ['documentId', 'index', 'nativeType']
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
run: async (args) => {
|
|
226
|
+
const [block] = checkBlocks([{ nativeType: str(args, 'nativeType'), data: optionalObject(args, 'data') ?? {} }]);
|
|
227
|
+
const result = await adapter.insertBlock(str(args, 'documentId'), index(args, 'index'), block.nativeType, block.data);
|
|
228
|
+
return formatWrite(`Insert of "${str(args, 'nativeType')}"`, result);
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
supported: typeof adapter.insertBlocks === 'function',
|
|
233
|
+
write: true,
|
|
234
|
+
def: {
|
|
235
|
+
name: 'inti_insert_blocks',
|
|
236
|
+
description: '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.',
|
|
237
|
+
inputSchema: {
|
|
238
|
+
type: 'object',
|
|
239
|
+
properties: {
|
|
240
|
+
documentId: DOCUMENT_ID,
|
|
241
|
+
index: { type: 'integer', description: 'Position to insert at. Use blockCount to append.' },
|
|
242
|
+
blocks: {
|
|
243
|
+
type: 'array',
|
|
244
|
+
description: 'Blocks in order: [{ "nativeType": "...", "data": { ... } }].',
|
|
245
|
+
items: {
|
|
246
|
+
type: 'object',
|
|
247
|
+
properties: { nativeType: { type: 'string' }, data: { type: 'object' } },
|
|
248
|
+
required: ['nativeType']
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
required: ['documentId', 'index', 'blocks']
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
run: async (args) => {
|
|
256
|
+
if (!Array.isArray(args.blocks) || args.blocks.length === 0) {
|
|
257
|
+
throw new ArgError('"blocks" is required and must be a non-empty array.');
|
|
258
|
+
}
|
|
259
|
+
const blocks = checkBlocks(args.blocks);
|
|
260
|
+
const result = await adapter.insertBlocks(str(args, 'documentId'), index(args, 'index'), blocks);
|
|
261
|
+
return formatWrite(`Insert of ${blocks.length} blocks`, result);
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
supported: vocabulary !== undefined,
|
|
266
|
+
write: false,
|
|
267
|
+
def: {
|
|
268
|
+
name: 'inti_get_vocabulary',
|
|
269
|
+
description: 'List the block types you may compose with, their fields, and the items available for reference fields. Call this before inserting blocks.',
|
|
270
|
+
inputSchema: { type: 'object', properties: {} }
|
|
271
|
+
},
|
|
272
|
+
run: async () => ({
|
|
273
|
+
ok: true,
|
|
274
|
+
text: JSON.stringify({
|
|
275
|
+
blocks: vocabulary.blocks,
|
|
276
|
+
// Only what is needed to choose: the server supplies the value
|
|
277
|
+
sources: Object.fromEntries(Object.entries(vocabulary.sources ?? {}).map(([name, items]) => [
|
|
278
|
+
name,
|
|
279
|
+
items.map(({ id, summary }) => ({ id, summary }))
|
|
280
|
+
]))
|
|
281
|
+
}, null, 2)
|
|
282
|
+
})
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
supported: typeof adapter.createDraft === 'function',
|
|
286
|
+
write: true,
|
|
287
|
+
def: {
|
|
288
|
+
name: 'inti_create_draft',
|
|
289
|
+
description: '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.',
|
|
290
|
+
inputSchema: {
|
|
291
|
+
type: 'object',
|
|
292
|
+
properties: { documentId: DOCUMENT_ID },
|
|
293
|
+
required: ['documentId']
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
run: async (args) => {
|
|
297
|
+
const result = await adapter.createDraft(str(args, 'documentId'));
|
|
298
|
+
if (result?.success === false)
|
|
299
|
+
return formatWrite('Draft', result);
|
|
300
|
+
return { ok: true, text: JSON.stringify({ draftDocumentId: result.documentId, slug: result.slug }) };
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
supported: typeof adapter.publishDraft === 'function',
|
|
305
|
+
write: true,
|
|
306
|
+
def: {
|
|
307
|
+
name: 'inti_publish_draft',
|
|
308
|
+
description: 'Publish a working copy over its page. Visitors see the change right away: do this only when asked to.',
|
|
309
|
+
inputSchema: {
|
|
310
|
+
type: 'object',
|
|
311
|
+
properties: { documentId: { type: 'string', description: 'The draft documentId from inti_create_draft.' } },
|
|
312
|
+
required: ['documentId']
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
run: async (args) => formatWrite('Publish', await adapter.publishDraft(str(args, 'documentId')))
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
supported: typeof adapter.discardDraft === 'function',
|
|
319
|
+
write: true,
|
|
320
|
+
def: {
|
|
321
|
+
name: 'inti_discard_draft',
|
|
322
|
+
description: 'Throw away a working copy. The published page does not change.',
|
|
323
|
+
inputSchema: {
|
|
324
|
+
type: 'object',
|
|
325
|
+
properties: { documentId: { type: 'string', description: 'The draft documentId from inti_create_draft.' } },
|
|
326
|
+
required: ['documentId']
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
run: async (args) => formatWrite('Discard', await adapter.discardDraft(str(args, 'documentId')))
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
supported: typeof adapter.moveBlock === 'function',
|
|
333
|
+
write: true,
|
|
334
|
+
def: {
|
|
335
|
+
name: 'inti_move_block',
|
|
336
|
+
description: 'Reorder blocks by moving one from a position to another.',
|
|
337
|
+
inputSchema: {
|
|
338
|
+
type: 'object',
|
|
339
|
+
properties: {
|
|
340
|
+
documentId: DOCUMENT_ID,
|
|
341
|
+
fromIndex: { type: 'integer', description: 'Current zero-based index.' },
|
|
342
|
+
toIndex: { type: 'integer', description: 'Target zero-based index.' }
|
|
343
|
+
},
|
|
344
|
+
required: ['documentId', 'fromIndex', 'toIndex']
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
run: async (args) => {
|
|
348
|
+
const result = await adapter.moveBlock(str(args, 'documentId'), index(args, 'fromIndex'), index(args, 'toIndex'));
|
|
349
|
+
return formatWrite('Move', result);
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
supported: typeof adapter.duplicateBlock === 'function',
|
|
354
|
+
write: true,
|
|
355
|
+
def: {
|
|
356
|
+
name: 'inti_duplicate_block',
|
|
357
|
+
description: 'Duplicate the block at a position, inserting the copy right after it.',
|
|
358
|
+
inputSchema: {
|
|
359
|
+
type: 'object',
|
|
360
|
+
properties: {
|
|
361
|
+
documentId: DOCUMENT_ID,
|
|
362
|
+
index: { type: 'integer', description: 'Zero-based index of the block to duplicate.' }
|
|
363
|
+
},
|
|
364
|
+
required: ['documentId', 'index']
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
run: async (args) => {
|
|
368
|
+
const result = await adapter.duplicateBlock(str(args, 'documentId'), index(args, 'index'));
|
|
369
|
+
return formatWrite('Duplicate', result);
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
supported: typeof adapter.removeBlock === 'function',
|
|
374
|
+
write: true,
|
|
375
|
+
def: {
|
|
376
|
+
name: 'inti_remove_block',
|
|
377
|
+
description: 'Delete the block at a position. Destructive and not undoable from here — confirm the index with inti_get_page first.',
|
|
378
|
+
inputSchema: {
|
|
379
|
+
type: 'object',
|
|
380
|
+
properties: {
|
|
381
|
+
documentId: DOCUMENT_ID,
|
|
382
|
+
index: { type: 'integer', description: 'Zero-based index of the block to delete.' }
|
|
383
|
+
},
|
|
384
|
+
required: ['documentId', 'index']
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
run: async (args) => {
|
|
388
|
+
const result = await adapter.removeBlock(str(args, 'documentId'), index(args, 'index'));
|
|
389
|
+
return formatWrite('Delete', result);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
];
|
|
393
|
+
/** Only what the adapter supports and the mode allows is advertised */
|
|
394
|
+
const available = () => entries.filter((e) => e.supported && !(readOnly && e.write));
|
|
395
|
+
return {
|
|
396
|
+
list: () => available().map((e) => e.def),
|
|
397
|
+
async call(name, args) {
|
|
398
|
+
const entry = entries.find((e) => e.def.name === name);
|
|
399
|
+
if (!entry) {
|
|
400
|
+
const names = available()
|
|
401
|
+
.map((e) => e.def.name)
|
|
402
|
+
.join(', ');
|
|
403
|
+
return { ok: false, text: `Unknown tool "${name}". Available: ${names || 'none'}` };
|
|
404
|
+
}
|
|
405
|
+
if (!entry.supported) {
|
|
406
|
+
return {
|
|
407
|
+
ok: false,
|
|
408
|
+
text: `Tool "${name}" is not supported by the "${adapter.name ?? 'configured'}" adapter.`
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (readOnly && entry.write) {
|
|
412
|
+
return {
|
|
413
|
+
ok: false,
|
|
414
|
+
text: `Tool "${name}" writes to the CMS and INTI_MCP_READONLY is set. Unset it to allow writes.`
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
try {
|
|
418
|
+
return await entry.run(args ?? {});
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
// A CMS failure or an invalid argument is reported to the agent
|
|
422
|
+
// as a tool result, never as a server crash.
|
|
423
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
424
|
+
return { ok: false, text: `${name} failed: ${message}` };
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AA8DlD,+CAA+C;AAC/C,sBAAsB;AACtB,+CAA+C;AAE/C,iFAAiF;AACjF,MAAM,QAAS,SAAQ,KAAK;CAAG;AAE/B,SAAS,GAAG,CAAC,IAA6B,EAAE,GAAW;IACnD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,QAAQ,CAAC,IAAI,GAAG,+CAA+C,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,SAAS,KAAK,CAAC,IAA6B,EAAE,GAAW;IACrD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACtB,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC/E,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,QAAQ,CAAC,IAAI,GAAG,4CAA4C,CAAC,CAAC;I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ACnG,CAAC;YACN,CAAC;YAED,IAAI,CAAC;gBACD,OAAO,MAAM,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;YACvC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,gEAAgE;gBAChE,6CAA6C;gBAC7C,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACvE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,YAAY,OAAO,EAAE,EAAE,CAAC;YAC7D,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@intijs/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@intijs/mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Victor Antinori Broce",
|
|
7
|
+
"homepage": "https://github.com/intijs/inti/tree/main/packages/mcp#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/intijs/inti.git",
|
|
11
|
+
"directory": "packages/mcp"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/intijs/inti/issues"
|
|
15
|
+
},
|
|
16
|
+
"description": "MCP server for Inti.js — let AI agents read and edit your headless CMS content",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"mcp",
|
|
19
|
+
"model-context-protocol",
|
|
20
|
+
"inti",
|
|
21
|
+
"astro",
|
|
22
|
+
"cms",
|
|
23
|
+
"wordpress",
|
|
24
|
+
"headless-cms",
|
|
25
|
+
"ai"
|
|
26
|
+
],
|
|
27
|
+
"bin": {
|
|
28
|
+
"inti-mcp": "./bin/inti-mcp.js"
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"bin",
|
|
41
|
+
"src",
|
|
42
|
+
"README.md"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"prepare": "node ../../scripts/prepare-package.mjs",
|
|
47
|
+
"dev": "tsc --watch",
|
|
48
|
+
"clean": "rm -rf dist",
|
|
49
|
+
"test": "bun test",
|
|
50
|
+
"prepublishOnly": "npm run build"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@intijs/genui": "^0.1.0",
|
|
54
|
+
"@modelcontextprotocol/sdk": "^1.32.2"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@intijs/core": "^0.1.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^20.0.0",
|
|
61
|
+
"typescript": "^5.7.3"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=18.0.0"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/index.ts
ADDED
package/src/server.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inti's MCP server over stdio.
|
|
3
|
+
*
|
|
4
|
+
* Exposes the WritableAdapter contract as Model Context Protocol tools, so
|
|
5
|
+
* that an agent (Claude Code, Cursor, Claude Desktop) can read and edit the
|
|
6
|
+
* CMS content with the same operations the browser's inline editing uses.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: over stdio, stdout is the protocol channel. Every log goes to
|
|
9
|
+
* stderr — a console.log would break the connection with the client.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
13
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
14
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
15
|
+
import { resolveWriteAdapter, env } from '@intijs/core/server';
|
|
16
|
+
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
|
|
19
|
+
import { createToolRegistry } from './tools.js';
|
|
20
|
+
import type { AgentVocabulary } from './tools.js';
|
|
21
|
+
|
|
22
|
+
/** Version advertised to the MCP client */
|
|
23
|
+
const VERSION = '0.1.0';
|
|
24
|
+
|
|
25
|
+
function log(message: string): void {
|
|
26
|
+
process.stderr.write(`[inti-mcp] ${message}\n`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function startServer(): Promise<void> {
|
|
30
|
+
const adapter = await resolveWriteAdapter();
|
|
31
|
+
|
|
32
|
+
if (!adapter) {
|
|
33
|
+
const configured = env('INTI_ADAPTER');
|
|
34
|
+
log(
|
|
35
|
+
configured && configured !== 'local'
|
|
36
|
+
? `Adapter "${configured}" could not be resolved or does not support write-back.\n` +
|
|
37
|
+
` Check that @intijs/adapter-${configured} is installed and its INTI_* credentials are set.`
|
|
38
|
+
: 'No CMS adapter configured. Set INTI_ADAPTER (e.g. "wordpress") plus its credentials.\n' +
|
|
39
|
+
' See .env.example for the full list of variables.'
|
|
40
|
+
);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const readOnly = /^(1|true|yes)$/i.test(env('INTI_MCP_READONLY') ?? '');
|
|
45
|
+
const vocabularyFile = env('INTI_MCP_VOCABULARY');
|
|
46
|
+
let vocabulary: AgentVocabulary | undefined;
|
|
47
|
+
if (vocabularyFile) {
|
|
48
|
+
try {
|
|
49
|
+
const parsed = JSON.parse(readFileSync(vocabularyFile, 'utf8'));
|
|
50
|
+
vocabulary = Array.isArray(parsed) ? { blocks: parsed } : parsed;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
// Without a vocabulary an agent could write anything: do not start
|
|
53
|
+
log(`Could not read INTI_MCP_VOCABULARY (${vocabularyFile}): ${error instanceof Error ? error.message : error}`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const registry = createToolRegistry(adapter, { readOnly, vocabulary });
|
|
59
|
+
const tools = registry.list();
|
|
60
|
+
|
|
61
|
+
const server = new Server({ name: 'inti', version: VERSION }, { capabilities: { tools: {} } });
|
|
62
|
+
|
|
63
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
|
|
64
|
+
|
|
65
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
66
|
+
const { name, arguments: args } = request.params;
|
|
67
|
+
const result = await registry.call(name, (args ?? {}) as Record<string, unknown>);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
content: [{ type: 'text' as const, text: result.text }],
|
|
71
|
+
isError: !result.ok
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
await server.connect(new StdioServerTransport());
|
|
76
|
+
|
|
77
|
+
log(
|
|
78
|
+
`Connected — adapter "${adapter.name}", ${tools.length} tools${readOnly ? ' (read-only mode)' : ''}: ` +
|
|
79
|
+
tools.map((t) => t.name).join(', ')
|
|
80
|
+
);
|
|
81
|
+
}
|