@cplace/mcp-server 2.2.2 → 2.4.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/README.md +19 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +11 -0
- package/dist/api.js.map +1 -1
- package/dist/backend-capabilities.d.ts +1 -1
- package/dist/backend-capabilities.d.ts.map +1 -1
- package/dist/backend-capabilities.js.map +1 -1
- package/dist/index.js +31 -4
- package/dist/index.js.map +1 -1
- package/dist/page-writes.d.ts +8 -0
- package/dist/page-writes.d.ts.map +1 -0
- package/dist/page-writes.js +30 -0
- package/dist/page-writes.js.map +1 -0
- package/dist/tools/pages.d.ts +1 -1
- package/dist/tools/pages.d.ts.map +1 -1
- package/dist/tools/pages.js +2 -1
- package/dist/tools/pages.js.map +1 -1
- package/dist/tools/type-management.d.ts +117 -15
- package/dist/tools/type-management.d.ts.map +1 -1
- package/dist/tools/type-management.js +417 -327
- package/dist/tools/type-management.js.map +1 -1
- package/package.json +1 -1
|
@@ -13,7 +13,8 @@ const TOOL_MANAGE_ATTRIBUTE_DEFINITION = 'cplace_manage_attribute_definition';
|
|
|
13
13
|
const TOOL_DELETE_TYPE_DEFINITION = 'cplace_delete_type_definition';
|
|
14
14
|
const TOOL_DELETE_ATTRIBUTE_DEFINITION = 'cplace_delete_attribute_definition';
|
|
15
15
|
const TOOL_LIST_CUSTOM_CONSTRAINT_TYPES = 'cplace_list_custom_constraint_types';
|
|
16
|
-
const
|
|
16
|
+
const TOOL_CREATE_ATTRIBUTE_DEFINITIONS = 'cplace_create_attribute_definitions';
|
|
17
|
+
const MANAGE_ATTRIBUTE_DESCRIPTION = 'Create or update attribute definitions within existing type definitions. Supports all major constraint types including string, number, boolean, date, reference, enumeration, and specialized types like rich text and colors. Provides comprehensive configuration options for display properties, validation, and low-code integration. To create several attributes of one type, use cplace_create_attribute_definitions: one call, in display order.\n\n' +
|
|
17
18
|
'Custom constraint types from installed plugins are supported. Call cplace_list_custom_constraint_types to see names and allowed multiplicities.';
|
|
18
19
|
function appendCustomConstraintHintIfNeeded(errorText) {
|
|
19
20
|
const isUnknownType = errorText.includes('Unknown constraint type');
|
|
@@ -90,6 +91,225 @@ const PERMISSIONS_UPDATE_GUARD = {
|
|
|
90
91
|
'the backend.');
|
|
91
92
|
},
|
|
92
93
|
};
|
|
94
|
+
const constraintConfigObject = z
|
|
95
|
+
.object({
|
|
96
|
+
constraintType: z
|
|
97
|
+
.string()
|
|
98
|
+
.describe("Built-in: 'string' | 'longString' | 'richString' | 'localizedString' | " +
|
|
99
|
+
"'number' | 'boolean' | 'date' | 'color' | 'reference' | 'textEnumeration'" +
|
|
100
|
+
ifCap('constraint.search', " | 'search'") +
|
|
101
|
+
'. ' +
|
|
102
|
+
ifCap('constraint.script', "Script: 'script' (the cplaceJS attribute type; single-valued only, multiplicity " +
|
|
103
|
+
'exactlyOne or maximalOne; see scriptLanguage). ') +
|
|
104
|
+
"Special: 'workflow', 'linkedAttribute'. " +
|
|
105
|
+
ifCap('constraint.search', "'search' makes a Search attribute that holds one saved search. It takes no further constraint " +
|
|
106
|
+
"fields, its multiplicity must be 'exactlyOne' or 'maximalOne', and its page value is a cplace " +
|
|
107
|
+
'search definition as a JSON string, not the searchFilter format of cplace_search_pages. ') +
|
|
108
|
+
'Custom constraints from installed plugins are also accepted by constraint name ' +
|
|
109
|
+
"(e.g. 'cf.cplace.timeBoundedValues.customAttributeType'). " +
|
|
110
|
+
'Call cplace_list_custom_constraint_types to see installed custom constraints. ' +
|
|
111
|
+
'Note: linkedAttribute constraints cannot be updated via PATCH — delete and recreate.'),
|
|
112
|
+
pattern: z
|
|
113
|
+
.string()
|
|
114
|
+
.optional()
|
|
115
|
+
.describe('Regex pattern for string validation.' +
|
|
116
|
+
ifCap('constraint.clear', " On update, pass '' (empty string) to clear an existing pattern.")),
|
|
117
|
+
patternErrorMessage: z
|
|
118
|
+
.record(z.string(), z.string())
|
|
119
|
+
.optional()
|
|
120
|
+
.describe('Localized error messages for pattern validation'),
|
|
121
|
+
precision: z.number().optional().describe('Decimal precision (-1 for unlimited)'),
|
|
122
|
+
suffix: z
|
|
123
|
+
.record(z.string(), z.string())
|
|
124
|
+
.optional()
|
|
125
|
+
.describe('Localized suffix text.' +
|
|
126
|
+
ifCap('constraint.clear', ' On update, pass {} (empty object) to clear an existing suffix.')),
|
|
127
|
+
specificity: z
|
|
128
|
+
.enum(['DAY', 'WEEK', 'MONTH', 'QUARTER', 'YEAR'])
|
|
129
|
+
.optional()
|
|
130
|
+
.describe("For 'date' constraints: granularity of the date value (default: 'DAY'). " +
|
|
131
|
+
"Time-of-day is controlled by the separate 'withTime' boolean, not by specificity. " +
|
|
132
|
+
"Note: the old values 'date'/'datetime'/'time' were never functional and are rejected."),
|
|
133
|
+
withTime: z
|
|
134
|
+
.boolean()
|
|
135
|
+
.optional()
|
|
136
|
+
.describe('Include time component.' +
|
|
137
|
+
ifCap('constraint.clear', ' On update, pass false to turn an existing time component back off.')),
|
|
138
|
+
dateFormat: z
|
|
139
|
+
.enum([
|
|
140
|
+
'YEAR_SHORT',
|
|
141
|
+
'YEAR_LONG',
|
|
142
|
+
'QUARTER_SLASH_YEAR_SHORT',
|
|
143
|
+
'QUARTER_SLASH_YEAR_LONG',
|
|
144
|
+
'QUARTER_DOT_YEAR_SHORT',
|
|
145
|
+
'QUARTER_DOT_YEAR_LONG',
|
|
146
|
+
'MONTH_SHORT_YEAR_SHORT',
|
|
147
|
+
'MONTH_SHORT',
|
|
148
|
+
'MONTH_FULL',
|
|
149
|
+
'MONTH_LONG',
|
|
150
|
+
'MONTH_SHORT_YEAR_SHORT_UNIFORM',
|
|
151
|
+
'MONTH_SHORT_YEAR_LONG',
|
|
152
|
+
'WEEK_YEAR_SHORT',
|
|
153
|
+
'WEEK_YEAR_LONG',
|
|
154
|
+
'DAY_ALL_SHORT',
|
|
155
|
+
'DAY_YEAR_LONG',
|
|
156
|
+
'DAY_MONTH_YEAR_LONG',
|
|
157
|
+
'DAY_NO_YEAR_UNIFORM',
|
|
158
|
+
'DAY_YEAR_SHORT_UNIFORM',
|
|
159
|
+
'DAY_YEAR_LONG_UNIFORM',
|
|
160
|
+
'ISO_8601',
|
|
161
|
+
'ISO_8601_RAW',
|
|
162
|
+
'DAY_WEEK_WEEKDAY_YEAR',
|
|
163
|
+
])
|
|
164
|
+
.optional()
|
|
165
|
+
.describe("For 'date' constraints: display format key. Patterns are locale-dependent (EN / DE): " +
|
|
166
|
+
'YEAR_SHORT = yy / yy; YEAR_LONG = yyyy / yyyy; ' +
|
|
167
|
+
'QUARTER_SLASH_YEAR_SHORT = QQQ/yy; QUARTER_SLASH_YEAR_LONG = QQQ/yyyy; ' +
|
|
168
|
+
'QUARTER_DOT_YEAR_SHORT = QQQ.yy; QUARTER_DOT_YEAR_LONG = QQQ.yyyy; ' +
|
|
169
|
+
'MONTH_SHORT_YEAR_SHORT = MM/yy / MM.yy; MONTH_SHORT = MM/yyyy / MM.yyyy; ' +
|
|
170
|
+
'MONTH_FULL = MMMM yyyy; MONTH_LONG = MMM yyyy; ' +
|
|
171
|
+
'MONTH_SHORT_YEAR_SHORT_UNIFORM = MM/yy; MONTH_SHORT_YEAR_LONG = MM/yyyy; ' +
|
|
172
|
+
'WEEK_YEAR_SHORT = ww/YY; WEEK_YEAR_LONG = ww/YYYY; ' +
|
|
173
|
+
'DAY_ALL_SHORT = MM/dd/yy / dd.MM.yy; DAY_YEAR_LONG = MM/dd/yyyy / dd.MM.yyyy; ' +
|
|
174
|
+
'DAY_MONTH_YEAR_LONG = dd-MMM-yyyy; DAY_NO_YEAR_UNIFORM = dd.MM.; ' +
|
|
175
|
+
'DAY_YEAR_SHORT_UNIFORM = dd.MM.yy; DAY_YEAR_LONG_UNIFORM = dd.MM.yyyy; ' +
|
|
176
|
+
'ISO_8601 = yyyy-MM-dd; ISO_8601_RAW = yyyyMMdd; DAY_WEEK_WEEKDAY_YEAR = ww.e/YY. ' +
|
|
177
|
+
"When omitted, the specificity's default format applies. " +
|
|
178
|
+
"Read responses return this key as 'dateFormatKey'. " +
|
|
179
|
+
'Free-form patterns (e.g. "dd.MM.yyyy") are not accepted.'),
|
|
180
|
+
targetTypeNames: z
|
|
181
|
+
.array(z.string())
|
|
182
|
+
.optional()
|
|
183
|
+
.describe("For 'reference' constraints: target type internal names (e.g., ['cf.example.targetType']). " +
|
|
184
|
+
"Required when targetEntityKind is 'page' or omitted. " +
|
|
185
|
+
"Not needed when targetEntityKind is 'person', 'group', 'principal', or 'document'. " +
|
|
186
|
+
'Each target type must already exist. For self-referencing attributes, ' +
|
|
187
|
+
'create the type first, then add the attribute referencing it in a separate call.'),
|
|
188
|
+
targetEntityKind: z
|
|
189
|
+
.string()
|
|
190
|
+
.optional()
|
|
191
|
+
.describe("Entity kind the reference targets. Valid values: 'page' (default when omitted — requires targetTypeNames), " +
|
|
192
|
+
"'person' (User), 'group' (Group), 'principal' (User or Group), 'document' (File), " +
|
|
193
|
+
"'any' (explicitly no entity-kind restriction; cannot be combined with isHierarchy or sameWorkspace). " +
|
|
194
|
+
'When set to a non-page kind, targetTypeNames is not required.'),
|
|
195
|
+
sameWorkspace: z
|
|
196
|
+
.boolean()
|
|
197
|
+
.optional()
|
|
198
|
+
.describe('Restrict to same workspace. When omitted, defaults to the value of isHierarchy ' +
|
|
199
|
+
'(a hierarchy requires same-workspace). Explicit false combined with ' +
|
|
200
|
+
'isHierarchy: true is rejected by the backend.'),
|
|
201
|
+
isHierarchy: z
|
|
202
|
+
.boolean()
|
|
203
|
+
.optional()
|
|
204
|
+
.describe('Whether this is a hierarchical (parent-child) reference. Requires single ' +
|
|
205
|
+
'multiplicity (exactlyOne or maximalOne) and same-workspace; sameWorkspace ' +
|
|
206
|
+
'defaults to true when isHierarchy is true. At most one hierarchy attribute per type.'),
|
|
207
|
+
inverseRoleName: z
|
|
208
|
+
.record(z.string(), z.string())
|
|
209
|
+
.optional()
|
|
210
|
+
.describe('Localized inverse role name shown on the referenced page - e.g., ' +
|
|
211
|
+
'{"en": "Referenced by", "de": "Referenziert von"}. ' +
|
|
212
|
+
'On update, the whole localized map is replaced.'),
|
|
213
|
+
showCreateNewButton: z
|
|
214
|
+
.boolean()
|
|
215
|
+
.optional()
|
|
216
|
+
.describe("For 'reference' constraints: show the 'Create new' button next to the reference picker (default: true)"),
|
|
217
|
+
showInverseRoleAsList: z
|
|
218
|
+
.boolean()
|
|
219
|
+
.optional()
|
|
220
|
+
.describe("For 'reference' constraints: display the inverse role as a list on the referenced page (default: false)"),
|
|
221
|
+
showInMenuIfHierarchy: requires(z
|
|
222
|
+
.boolean()
|
|
223
|
+
.optional()
|
|
224
|
+
.describe("For 'reference' constraints with isHierarchy: true: show the child pages as subpages of their " +
|
|
225
|
+
'parent in the workspace navigation menu (default: true). Set false to keep many or ' +
|
|
226
|
+
'machine-generated child pages out of the menu. Rejected on a reference that is not a hierarchy.'), 'constraint.show-in-menu-if-hierarchy'),
|
|
227
|
+
hideAdditionalReferenceInformation: z
|
|
228
|
+
.boolean()
|
|
229
|
+
.optional()
|
|
230
|
+
.describe("For 'reference' constraints: hide additional reference information (default: false)"),
|
|
231
|
+
showLinkAsTextOnly: z
|
|
232
|
+
.boolean()
|
|
233
|
+
.optional()
|
|
234
|
+
.describe("For 'reference' constraints: render the reference link as plain text (default: false)"),
|
|
235
|
+
sortOrderForReference: z
|
|
236
|
+
.object({
|
|
237
|
+
sortColumn: z
|
|
238
|
+
.string()
|
|
239
|
+
.describe("Attribute internal name to sort by (e.g., '_name_' for the page name)"),
|
|
240
|
+
sortOrder: z.enum(['asc', 'desc']).describe('Sort direction'),
|
|
241
|
+
})
|
|
242
|
+
.strict()
|
|
243
|
+
.optional()
|
|
244
|
+
.describe("For 'reference' constraints: sort order for reference auto-completion suggestions"),
|
|
245
|
+
elements: z
|
|
246
|
+
.array(z
|
|
247
|
+
.object({
|
|
248
|
+
value: z.string().describe('Enumeration value'),
|
|
249
|
+
localizedName: z.record(z.string(), z.string()).describe('Localized display names'),
|
|
250
|
+
icon: z.string().optional().describe('Optional icon name'),
|
|
251
|
+
})
|
|
252
|
+
.strict())
|
|
253
|
+
.optional()
|
|
254
|
+
.describe("Required for 'textEnumeration'/'numberEnumeration': Enumeration elements"),
|
|
255
|
+
providerClass: z.string().optional().describe('Provider class for dynamicEnumeration'),
|
|
256
|
+
providerSimpleName: z
|
|
257
|
+
.string()
|
|
258
|
+
.optional()
|
|
259
|
+
.describe('Provider simple name for dynamicEnumeration'),
|
|
260
|
+
linkedReferenceName: z
|
|
261
|
+
.string()
|
|
262
|
+
.optional()
|
|
263
|
+
.describe("Required for 'linkedAttribute': name of a reference attribute on the same type"),
|
|
264
|
+
linkedPropertyName: z
|
|
265
|
+
.string()
|
|
266
|
+
.optional()
|
|
267
|
+
.describe("Required for 'linkedAttribute': internal name of the property on the referenced type (e.g., 'cf.cplace.bo.name')"),
|
|
268
|
+
scriptLanguage: requires(z
|
|
269
|
+
.enum(['javascript', 'markdown', 'html'])
|
|
270
|
+
.optional()
|
|
271
|
+
.describe("For 'script' constraints: the language of the script value (default: 'javascript'). " +
|
|
272
|
+
"To change it on update, send constraintType 'script' with the new scriptLanguage."), 'constraint.script'),
|
|
273
|
+
})
|
|
274
|
+
.strict();
|
|
275
|
+
const ATTRIBUTE_SETTINGS_FIELDS = {
|
|
276
|
+
localizedNames: z
|
|
277
|
+
.record(z.string(), z.string())
|
|
278
|
+
.optional()
|
|
279
|
+
.describe('Localized attribute names - e.g., {"en": "My Attribute", "de": "Mein Attribut"}'),
|
|
280
|
+
localizedShortNames: z
|
|
281
|
+
.record(z.string(), z.string())
|
|
282
|
+
.optional()
|
|
283
|
+
.describe('Localized short names - e.g., {"en": "My Attr", "de": "Mein Attr"}'),
|
|
284
|
+
localizedShortHelp: z
|
|
285
|
+
.record(z.string(), z.string())
|
|
286
|
+
.optional()
|
|
287
|
+
.describe('Localized help text - e.g., {"en": "Help text", "de": "Hilfetext"}'),
|
|
288
|
+
readOnly: z.boolean().optional().describe('Whether attribute is read-only'),
|
|
289
|
+
showInTables: z.boolean().optional().describe('Show in table views'),
|
|
290
|
+
showInNewDialog: z.boolean().optional().describe('Show in new item dialogs'),
|
|
291
|
+
showValuesWithLineBreak: z.boolean().optional().describe('Display values with line breaks'),
|
|
292
|
+
showInAttributesWidget: z.boolean().optional().describe('Show in attribute widgets'),
|
|
293
|
+
showInColumnSelection: z.boolean().optional().describe('Include in column selection'),
|
|
294
|
+
tableColumnWidth: z
|
|
295
|
+
.number()
|
|
296
|
+
.int()
|
|
297
|
+
.optional()
|
|
298
|
+
.describe('Column width in tables, in pixels. -1 = default/auto width.'),
|
|
299
|
+
queryableForScripting: z
|
|
300
|
+
.boolean()
|
|
301
|
+
.optional()
|
|
302
|
+
.describe('Whether the attribute can be queried from low-code scripts (default: false)'),
|
|
303
|
+
defaultValues: z
|
|
304
|
+
.array(z.union([z.string(), z.number(), z.boolean()]))
|
|
305
|
+
.optional()
|
|
306
|
+
.describe('Default values for new pages, validated against the attribute constraint. ' +
|
|
307
|
+
'Examples by constraint type — string: ["Draft"]; number: [5]; boolean: [true]; ' +
|
|
308
|
+
'enumeration: ["high"] (must be an element); reference: page UID(s); ' +
|
|
309
|
+
'date: ISO date string (e.g. "2026-06-01"). ' +
|
|
310
|
+
'Single-valued attributes accept at most one value. ' +
|
|
311
|
+
'Mismatched values are rejected with an error. Empty array clears the defaults.'),
|
|
312
|
+
};
|
|
93
313
|
export const TYPE_MANAGEMENT_TOOL_DEFINITIONS = {
|
|
94
314
|
[TOOL_MANAGE_TYPE_DEFINITION]: {
|
|
95
315
|
description: 'Create or update a type definition in a workspace. An update changes only the fields it sends. ' +
|
|
@@ -244,183 +464,7 @@ export const TYPE_MANAGEMENT_TOOL_DEFINITIONS = {
|
|
|
244
464
|
.enum(['exactlyOne', 'maximalOne', 'atLeastOne', 'arbitrary'])
|
|
245
465
|
.optional()
|
|
246
466
|
.describe('Required for create (except linkedAttribute where it must be omitted). Optional for update.'),
|
|
247
|
-
constraintConfig:
|
|
248
|
-
.object({
|
|
249
|
-
constraintType: z
|
|
250
|
-
.string()
|
|
251
|
-
.describe("Built-in: 'string' | 'longString' | 'richString' | 'localizedString' | " +
|
|
252
|
-
"'number' | 'boolean' | 'date' | 'color' | 'reference' | 'textEnumeration'" +
|
|
253
|
-
ifCap('constraint.search', " | 'search'") +
|
|
254
|
-
'. ' +
|
|
255
|
-
ifCap('constraint.script', "Script: 'script' (the cplaceJS attribute type; single-valued only, multiplicity " +
|
|
256
|
-
'exactlyOne or maximalOne; see scriptLanguage). ') +
|
|
257
|
-
"Special: 'workflow', 'linkedAttribute'. " +
|
|
258
|
-
ifCap('constraint.search', "'search' makes a Search attribute that holds one saved search. It takes no further constraint " +
|
|
259
|
-
"fields, its multiplicity must be 'exactlyOne' or 'maximalOne', and its page value is a cplace " +
|
|
260
|
-
'search definition as a JSON string, not the searchFilter format of cplace_search_pages. ') +
|
|
261
|
-
'Custom constraints from installed plugins are also accepted by constraint name ' +
|
|
262
|
-
"(e.g. 'cf.cplace.timeBoundedValues.customAttributeType'). " +
|
|
263
|
-
'Call cplace_list_custom_constraint_types to see installed custom constraints. ' +
|
|
264
|
-
'Note: linkedAttribute constraints cannot be updated via PATCH — delete and recreate.'),
|
|
265
|
-
pattern: z
|
|
266
|
-
.string()
|
|
267
|
-
.optional()
|
|
268
|
-
.describe('Regex pattern for string validation.' +
|
|
269
|
-
ifCap('constraint.clear', " On update, pass '' (empty string) to clear an existing pattern.")),
|
|
270
|
-
patternErrorMessage: z
|
|
271
|
-
.record(z.string(), z.string())
|
|
272
|
-
.optional()
|
|
273
|
-
.describe('Localized error messages for pattern validation'),
|
|
274
|
-
precision: z.number().optional().describe('Decimal precision (-1 for unlimited)'),
|
|
275
|
-
suffix: z
|
|
276
|
-
.record(z.string(), z.string())
|
|
277
|
-
.optional()
|
|
278
|
-
.describe('Localized suffix text.' +
|
|
279
|
-
ifCap('constraint.clear', ' On update, pass {} (empty object) to clear an existing suffix.')),
|
|
280
|
-
specificity: z
|
|
281
|
-
.enum(['DAY', 'WEEK', 'MONTH', 'QUARTER', 'YEAR'])
|
|
282
|
-
.optional()
|
|
283
|
-
.describe("For 'date' constraints: granularity of the date value (default: 'DAY'). " +
|
|
284
|
-
"Time-of-day is controlled by the separate 'withTime' boolean, not by specificity. " +
|
|
285
|
-
"Note: the old values 'date'/'datetime'/'time' were never functional and are rejected."),
|
|
286
|
-
withTime: z
|
|
287
|
-
.boolean()
|
|
288
|
-
.optional()
|
|
289
|
-
.describe('Include time component.' +
|
|
290
|
-
ifCap('constraint.clear', ' On update, pass false to turn an existing time component back off.')),
|
|
291
|
-
dateFormat: z
|
|
292
|
-
.enum([
|
|
293
|
-
'YEAR_SHORT',
|
|
294
|
-
'YEAR_LONG',
|
|
295
|
-
'QUARTER_SLASH_YEAR_SHORT',
|
|
296
|
-
'QUARTER_SLASH_YEAR_LONG',
|
|
297
|
-
'QUARTER_DOT_YEAR_SHORT',
|
|
298
|
-
'QUARTER_DOT_YEAR_LONG',
|
|
299
|
-
'MONTH_SHORT_YEAR_SHORT',
|
|
300
|
-
'MONTH_SHORT',
|
|
301
|
-
'MONTH_FULL',
|
|
302
|
-
'MONTH_LONG',
|
|
303
|
-
'MONTH_SHORT_YEAR_SHORT_UNIFORM',
|
|
304
|
-
'MONTH_SHORT_YEAR_LONG',
|
|
305
|
-
'WEEK_YEAR_SHORT',
|
|
306
|
-
'WEEK_YEAR_LONG',
|
|
307
|
-
'DAY_ALL_SHORT',
|
|
308
|
-
'DAY_YEAR_LONG',
|
|
309
|
-
'DAY_MONTH_YEAR_LONG',
|
|
310
|
-
'DAY_NO_YEAR_UNIFORM',
|
|
311
|
-
'DAY_YEAR_SHORT_UNIFORM',
|
|
312
|
-
'DAY_YEAR_LONG_UNIFORM',
|
|
313
|
-
'ISO_8601',
|
|
314
|
-
'ISO_8601_RAW',
|
|
315
|
-
'DAY_WEEK_WEEKDAY_YEAR',
|
|
316
|
-
])
|
|
317
|
-
.optional()
|
|
318
|
-
.describe("For 'date' constraints: display format key. Patterns are locale-dependent (EN / DE): " +
|
|
319
|
-
'YEAR_SHORT = yy / yy; YEAR_LONG = yyyy / yyyy; ' +
|
|
320
|
-
'QUARTER_SLASH_YEAR_SHORT = QQQ/yy; QUARTER_SLASH_YEAR_LONG = QQQ/yyyy; ' +
|
|
321
|
-
'QUARTER_DOT_YEAR_SHORT = QQQ.yy; QUARTER_DOT_YEAR_LONG = QQQ.yyyy; ' +
|
|
322
|
-
'MONTH_SHORT_YEAR_SHORT = MM/yy / MM.yy; MONTH_SHORT = MM/yyyy / MM.yyyy; ' +
|
|
323
|
-
'MONTH_FULL = MMMM yyyy; MONTH_LONG = MMM yyyy; ' +
|
|
324
|
-
'MONTH_SHORT_YEAR_SHORT_UNIFORM = MM/yy; MONTH_SHORT_YEAR_LONG = MM/yyyy; ' +
|
|
325
|
-
'WEEK_YEAR_SHORT = ww/YY; WEEK_YEAR_LONG = ww/YYYY; ' +
|
|
326
|
-
'DAY_ALL_SHORT = MM/dd/yy / dd.MM.yy; DAY_YEAR_LONG = MM/dd/yyyy / dd.MM.yyyy; ' +
|
|
327
|
-
'DAY_MONTH_YEAR_LONG = dd-MMM-yyyy; DAY_NO_YEAR_UNIFORM = dd.MM.; ' +
|
|
328
|
-
'DAY_YEAR_SHORT_UNIFORM = dd.MM.yy; DAY_YEAR_LONG_UNIFORM = dd.MM.yyyy; ' +
|
|
329
|
-
'ISO_8601 = yyyy-MM-dd; ISO_8601_RAW = yyyyMMdd; DAY_WEEK_WEEKDAY_YEAR = ww.e/YY. ' +
|
|
330
|
-
"When omitted, the specificity's default format applies. " +
|
|
331
|
-
"Read responses return this key as 'dateFormatKey'. " +
|
|
332
|
-
'Free-form patterns (e.g. "dd.MM.yyyy") are not accepted.'),
|
|
333
|
-
targetTypeNames: z
|
|
334
|
-
.array(z.string())
|
|
335
|
-
.optional()
|
|
336
|
-
.describe("For 'reference' constraints: target type internal names (e.g., ['cf.example.targetType']). " +
|
|
337
|
-
"Required when targetEntityKind is 'page' or omitted. " +
|
|
338
|
-
"Not needed when targetEntityKind is 'person', 'group', 'principal', or 'document'. " +
|
|
339
|
-
'Each target type must already exist. For self-referencing attributes, ' +
|
|
340
|
-
'create the type first, then add the attribute referencing it in a separate call.'),
|
|
341
|
-
targetEntityKind: z
|
|
342
|
-
.string()
|
|
343
|
-
.optional()
|
|
344
|
-
.describe("Entity kind the reference targets. Valid values: 'page' (default when omitted — requires targetTypeNames), " +
|
|
345
|
-
"'person' (User), 'group' (Group), 'principal' (User or Group), 'document' (File), " +
|
|
346
|
-
"'any' (explicitly no entity-kind restriction; cannot be combined with isHierarchy or sameWorkspace). " +
|
|
347
|
-
'When set to a non-page kind, targetTypeNames is not required.'),
|
|
348
|
-
sameWorkspace: z
|
|
349
|
-
.boolean()
|
|
350
|
-
.optional()
|
|
351
|
-
.describe('Restrict to same workspace. When omitted, defaults to the value of isHierarchy ' +
|
|
352
|
-
'(a hierarchy requires same-workspace). Explicit false combined with ' +
|
|
353
|
-
'isHierarchy: true is rejected by the backend.'),
|
|
354
|
-
isHierarchy: z
|
|
355
|
-
.boolean()
|
|
356
|
-
.optional()
|
|
357
|
-
.describe('Whether this is a hierarchical (parent-child) reference. Requires single ' +
|
|
358
|
-
'multiplicity (exactlyOne or maximalOne) and same-workspace; sameWorkspace ' +
|
|
359
|
-
'defaults to true when isHierarchy is true. At most one hierarchy attribute per type.'),
|
|
360
|
-
inverseRoleName: z
|
|
361
|
-
.record(z.string(), z.string())
|
|
362
|
-
.optional()
|
|
363
|
-
.describe('Localized inverse role name shown on the referenced page - e.g., ' +
|
|
364
|
-
'{"en": "Referenced by", "de": "Referenziert von"}. ' +
|
|
365
|
-
'On update, the whole localized map is replaced.'),
|
|
366
|
-
showCreateNewButton: z
|
|
367
|
-
.boolean()
|
|
368
|
-
.optional()
|
|
369
|
-
.describe("For 'reference' constraints: show the 'Create new' button next to the reference picker (default: true)"),
|
|
370
|
-
showInverseRoleAsList: z
|
|
371
|
-
.boolean()
|
|
372
|
-
.optional()
|
|
373
|
-
.describe("For 'reference' constraints: display the inverse role as a list on the referenced page (default: false)"),
|
|
374
|
-
showInMenuIfHierarchy: requires(z
|
|
375
|
-
.boolean()
|
|
376
|
-
.optional()
|
|
377
|
-
.describe("For 'reference' constraints with isHierarchy: true: show the child pages as subpages of their " +
|
|
378
|
-
'parent in the workspace navigation menu (default: true). Set false to keep many or ' +
|
|
379
|
-
'machine-generated child pages out of the menu. Rejected on a reference that is not a hierarchy.'), 'constraint.show-in-menu-if-hierarchy'),
|
|
380
|
-
hideAdditionalReferenceInformation: z
|
|
381
|
-
.boolean()
|
|
382
|
-
.optional()
|
|
383
|
-
.describe("For 'reference' constraints: hide additional reference information (default: false)"),
|
|
384
|
-
showLinkAsTextOnly: z
|
|
385
|
-
.boolean()
|
|
386
|
-
.optional()
|
|
387
|
-
.describe("For 'reference' constraints: render the reference link as plain text (default: false)"),
|
|
388
|
-
sortOrderForReference: z
|
|
389
|
-
.object({
|
|
390
|
-
sortColumn: z
|
|
391
|
-
.string()
|
|
392
|
-
.describe("Attribute internal name to sort by (e.g., '_name_' for the page name)"),
|
|
393
|
-
sortOrder: z.enum(['asc', 'desc']).describe('Sort direction'),
|
|
394
|
-
})
|
|
395
|
-
.optional()
|
|
396
|
-
.describe("For 'reference' constraints: sort order for reference auto-completion suggestions"),
|
|
397
|
-
elements: z
|
|
398
|
-
.array(z.object({
|
|
399
|
-
value: z.string().describe('Enumeration value'),
|
|
400
|
-
localizedName: z.record(z.string(), z.string()).describe('Localized display names'),
|
|
401
|
-
icon: z.string().optional().describe('Optional icon name'),
|
|
402
|
-
}))
|
|
403
|
-
.optional()
|
|
404
|
-
.describe("Required for 'textEnumeration'/'numberEnumeration': Enumeration elements"),
|
|
405
|
-
providerClass: z.string().optional().describe('Provider class for dynamicEnumeration'),
|
|
406
|
-
providerSimpleName: z
|
|
407
|
-
.string()
|
|
408
|
-
.optional()
|
|
409
|
-
.describe('Provider simple name for dynamicEnumeration'),
|
|
410
|
-
linkedReferenceName: z
|
|
411
|
-
.string()
|
|
412
|
-
.optional()
|
|
413
|
-
.describe("Required for 'linkedAttribute': name of a reference attribute on the same type"),
|
|
414
|
-
linkedPropertyName: z
|
|
415
|
-
.string()
|
|
416
|
-
.optional()
|
|
417
|
-
.describe("Required for 'linkedAttribute': internal name of the property on the referenced type (e.g., 'cf.cplace.bo.name')"),
|
|
418
|
-
scriptLanguage: requires(z
|
|
419
|
-
.enum(['javascript', 'markdown', 'html'])
|
|
420
|
-
.optional()
|
|
421
|
-
.describe("For 'script' constraints: the language of the script value (default: 'javascript'). " +
|
|
422
|
-
"To change it on update, send constraintType 'script' with the new scriptLanguage."), 'constraint.script'),
|
|
423
|
-
})
|
|
467
|
+
constraintConfig: constraintConfigObject
|
|
424
468
|
.optional()
|
|
425
469
|
.describe('Required for create: Constraint configuration object. ' +
|
|
426
470
|
'Optional for update: replaces the configuration of the sub-fields you include. ' +
|
|
@@ -428,46 +472,44 @@ export const TYPE_MANAGEMENT_TOOL_DEFINITIONS = {
|
|
|
428
472
|
ifCap('constraint.clear', "; the documented clear sentinels (pattern '', suffix {}, withTime false) remove/reset a value") +
|
|
429
473
|
'.' +
|
|
430
474
|
ifNoCap('constraint.clear', ' This backend cannot clear pattern, suffix or withTime through MCP.')),
|
|
431
|
-
|
|
432
|
-
.record(z.string(), z.string())
|
|
433
|
-
.optional()
|
|
434
|
-
.describe('Localized attribute names - e.g., {"en": "My Attribute", "de": "Mein Attribut"}'),
|
|
435
|
-
localizedShortNames: z
|
|
436
|
-
.record(z.string(), z.string())
|
|
437
|
-
.optional()
|
|
438
|
-
.describe('Localized short names - e.g., {"en": "My Attr", "de": "Mein Attr"}'),
|
|
439
|
-
localizedShortHelp: z
|
|
440
|
-
.record(z.string(), z.string())
|
|
441
|
-
.optional()
|
|
442
|
-
.describe('Localized help text - e.g., {"en": "Help text", "de": "Hilfetext"}'),
|
|
443
|
-
readOnly: z.boolean().optional().describe('Whether attribute is read-only'),
|
|
444
|
-
showInTables: z.boolean().optional().describe('Show in table views'),
|
|
445
|
-
showInNewDialog: z.boolean().optional().describe('Show in new item dialogs'),
|
|
446
|
-
showValuesWithLineBreak: z.boolean().optional().describe('Display values with line breaks'),
|
|
447
|
-
showInAttributesWidget: z.boolean().optional().describe('Show in attribute widgets'),
|
|
448
|
-
showInColumnSelection: z.boolean().optional().describe('Include in column selection'),
|
|
449
|
-
tableColumnWidth: z
|
|
450
|
-
.number()
|
|
451
|
-
.int()
|
|
452
|
-
.optional()
|
|
453
|
-
.describe('Column width in tables, in pixels. -1 = default/auto width.'),
|
|
454
|
-
queryableForScripting: z
|
|
455
|
-
.boolean()
|
|
456
|
-
.optional()
|
|
457
|
-
.describe('Whether the attribute can be queried from low-code scripts (default: false)'),
|
|
458
|
-
defaultValues: z
|
|
459
|
-
.array(z.union([z.string(), z.number(), z.boolean()]))
|
|
460
|
-
.optional()
|
|
461
|
-
.describe('Default values for new pages, validated against the attribute constraint. ' +
|
|
462
|
-
'Examples by constraint type — string: ["Draft"]; number: [5]; boolean: [true]; ' +
|
|
463
|
-
'enumeration: ["high"] (must be an element); reference: page UID(s); ' +
|
|
464
|
-
'date: ISO date string (e.g. "2026-06-01"). ' +
|
|
465
|
-
'Single-valued attributes accept at most one value. ' +
|
|
466
|
-
'Mismatched values are rejected with an error. Empty array clears the defaults.'),
|
|
475
|
+
...ATTRIBUTE_SETTINGS_FIELDS,
|
|
467
476
|
},
|
|
468
477
|
annotations: { title: 'Manage Attribute Definition' },
|
|
469
478
|
guards: [CONSTRAINT_CLEAR_GUARD, REFERENCE_UPDATE_TO_ANY_GUARD],
|
|
470
479
|
},
|
|
480
|
+
[TOOL_CREATE_ATTRIBUTE_DEFINITIONS]: {
|
|
481
|
+
description: 'Create several attribute definitions on one existing type in one call, in the given order. Each ' +
|
|
482
|
+
'attribute is appended after the last one, so the list order becomes the display order. List a ' +
|
|
483
|
+
'reference attribute before the linked attributes that use it. The attributes are created one after ' +
|
|
484
|
+
'another; the first one the backend refuses stops the call, and the reply says which were created, ' +
|
|
485
|
+
'which failed and which were not tried. Nothing is rolled back. Custom constraint types from ' +
|
|
486
|
+
'installed plugins are supported; call cplace_list_custom_constraint_types to see names and ' +
|
|
487
|
+
'allowed multiplicities.',
|
|
488
|
+
inputSchema: {
|
|
489
|
+
workspaceId: z.string().describe("Target workspace ID (e.g., 'abc123')"),
|
|
490
|
+
typeInternalName: z
|
|
491
|
+
.string()
|
|
492
|
+
.describe("Target type internal name (e.g., 'cf.example.myType') (NOT `typeId` or `typeName`)"),
|
|
493
|
+
attributeDefinitions: z
|
|
494
|
+
.array(z
|
|
495
|
+
.object({
|
|
496
|
+
attributeName: z
|
|
497
|
+
.string()
|
|
498
|
+
.describe("Short name (e.g., 'myAttribute') or full internal name — the type's prefix is prepended if missing"),
|
|
499
|
+
multiplicity: z
|
|
500
|
+
.enum(['exactlyOne', 'maximalOne', 'atLeastOne', 'arbitrary'])
|
|
501
|
+
.optional()
|
|
502
|
+
.describe('Required, except for linkedAttribute, where it must be omitted.'),
|
|
503
|
+
constraintConfig: constraintConfigObject.describe('Constraint configuration object.'),
|
|
504
|
+
...ATTRIBUTE_SETTINGS_FIELDS,
|
|
505
|
+
})
|
|
506
|
+
.strict())
|
|
507
|
+
.min(1)
|
|
508
|
+
.max(50)
|
|
509
|
+
.describe('The attributes to create, in display order.'),
|
|
510
|
+
},
|
|
511
|
+
annotations: { title: 'Create Attribute Definitions' },
|
|
512
|
+
},
|
|
471
513
|
[TOOL_DELETE_TYPE_DEFINITION]: {
|
|
472
514
|
description: "Delete a type definition and all its attributes, validators, change listeners, and alternative layouts. Cannot delete types that have existing pages or are referenced by other types' attributes.",
|
|
473
515
|
inputSchema: {
|
|
@@ -528,6 +570,121 @@ function unappliedDefaultStrategyError(params, result) {
|
|
|
528
570
|
isError: true,
|
|
529
571
|
};
|
|
530
572
|
}
|
|
573
|
+
function checkAttributeCreate(item) {
|
|
574
|
+
const config = item.constraintConfig;
|
|
575
|
+
const ct = config.constraintType;
|
|
576
|
+
if (ct === 'reference') {
|
|
577
|
+
const entityKind = config.targetEntityKind;
|
|
578
|
+
if (entityKind &&
|
|
579
|
+
entityKind !== 'page' &&
|
|
580
|
+
!ENTITY_KINDS_NOT_REQUIRING_TYPE_NAMES.includes(entityKind)) {
|
|
581
|
+
return `Invalid targetEntityKind '${entityKind}'. Valid values: 'page' (requires targetTypeNames), 'person' (User), 'group' (Group), 'principal' (User or Group), 'document' (File), 'any' (no entity-kind restriction).`;
|
|
582
|
+
}
|
|
583
|
+
const isEntityKindReference = ENTITY_KINDS_NOT_REQUIRING_TYPE_NAMES.includes(entityKind);
|
|
584
|
+
if (!isEntityKindReference &&
|
|
585
|
+
(!config.targetTypeNames || config.targetTypeNames.length === 0)) {
|
|
586
|
+
return "Reference attributes require either 'targetTypeNames' for page references (e.g., [\"cf.example.targetType\"]) or 'targetEntityKind' for entity-kind references (valid values: 'person', 'group', 'principal', 'document'). Omitting targetEntityKind defaults to 'page'; use targetEntityKind 'any' for an unrestricted reference.";
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
if (ct === 'textEnumeration' || ct === 'numberEnumeration') {
|
|
590
|
+
if (!config.elements || config.elements.length === 0) {
|
|
591
|
+
return "Enumeration attributes require 'elements' in constraintConfig with at least one element.";
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (ct === 'linkedAttribute') {
|
|
595
|
+
if (!config.linkedReferenceName || !config.linkedPropertyName) {
|
|
596
|
+
return "Linked attributes require both 'linkedReferenceName' and 'linkedPropertyName' in constraintConfig.";
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return undefined;
|
|
600
|
+
}
|
|
601
|
+
function buildAttributeCreateBody(workspaceId, typeInternalName, item) {
|
|
602
|
+
const requestBody = {
|
|
603
|
+
workspaceId,
|
|
604
|
+
typeDefinitionInternalName: typeInternalName,
|
|
605
|
+
attributeName: item.attributeName,
|
|
606
|
+
constraintConfig: item.constraintConfig,
|
|
607
|
+
};
|
|
608
|
+
if (item.multiplicity)
|
|
609
|
+
requestBody.multiplicity = item.multiplicity;
|
|
610
|
+
if (item.localizedNames)
|
|
611
|
+
requestBody.localizedNames = item.localizedNames;
|
|
612
|
+
if (item.localizedShortNames)
|
|
613
|
+
requestBody.localizedShortNames = item.localizedShortNames;
|
|
614
|
+
if (item.localizedShortHelp)
|
|
615
|
+
requestBody.localizedShortHelp = item.localizedShortHelp;
|
|
616
|
+
if (item.readOnly !== undefined)
|
|
617
|
+
requestBody.readOnly = item.readOnly;
|
|
618
|
+
if (item.showInTables !== undefined)
|
|
619
|
+
requestBody.showInTables = item.showInTables;
|
|
620
|
+
if (item.showInNewDialog !== undefined)
|
|
621
|
+
requestBody.showInNewDialog = item.showInNewDialog;
|
|
622
|
+
if (item.showValuesWithLineBreak !== undefined)
|
|
623
|
+
requestBody.showValuesWithLineBreak = item.showValuesWithLineBreak;
|
|
624
|
+
if (item.showInAttributesWidget !== undefined)
|
|
625
|
+
requestBody.showInAttributesWidget = item.showInAttributesWidget;
|
|
626
|
+
if (item.showInColumnSelection !== undefined)
|
|
627
|
+
requestBody.showInColumnSelection = item.showInColumnSelection;
|
|
628
|
+
if (item.tableColumnWidth !== undefined)
|
|
629
|
+
requestBody.tableColumnWidth = item.tableColumnWidth;
|
|
630
|
+
if (item.queryableForScripting !== undefined)
|
|
631
|
+
requestBody.queryableForScripting = item.queryableForScripting;
|
|
632
|
+
if (item.defaultValues !== undefined)
|
|
633
|
+
requestBody.defaultValues = item.defaultValues;
|
|
634
|
+
return requestBody;
|
|
635
|
+
}
|
|
636
|
+
function sameAttributeName(a, b) {
|
|
637
|
+
return a === b || a.endsWith(`.${b}`) || b.endsWith(`.${a}`);
|
|
638
|
+
}
|
|
639
|
+
function checkAttributeList(items) {
|
|
640
|
+
const problems = [];
|
|
641
|
+
items.forEach((item, index) => {
|
|
642
|
+
const label = `item ${index + 1} (${item.attributeName}): `;
|
|
643
|
+
const problem = checkAttributeCreate(item);
|
|
644
|
+
if (problem)
|
|
645
|
+
problems.push(label + problem);
|
|
646
|
+
const first = items.findIndex((other) => other.attributeName === item.attributeName);
|
|
647
|
+
if (first < index)
|
|
648
|
+
problems.push(`${label}the same attributeName as item ${first + 1}.`);
|
|
649
|
+
const reference = item.constraintConfig.linkedReferenceName;
|
|
650
|
+
if (item.constraintConfig.constraintType === 'linkedAttribute' && reference) {
|
|
651
|
+
const at = items.findIndex((other) => sameAttributeName(other.attributeName, reference));
|
|
652
|
+
if (at >= index) {
|
|
653
|
+
problems.push(`${label}its linkedReferenceName '${reference}' is item ${at + 1}. List the reference ` +
|
|
654
|
+
'attribute before the linked attributes that use it.');
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
return problems;
|
|
659
|
+
}
|
|
660
|
+
function formatCreateReport(typeInternalName, items, created, failure, seconds) {
|
|
661
|
+
const total = items.length;
|
|
662
|
+
const lines = items.map((item, index) => {
|
|
663
|
+
if (index < created.length)
|
|
664
|
+
return `${index + 1}. created ${created[index]}`;
|
|
665
|
+
if (failure && index === created.length)
|
|
666
|
+
return `${index + 1}. failed ${item.attributeName}: ${failure.message}`;
|
|
667
|
+
return `${index + 1}. not tried ${item.attributeName}`;
|
|
668
|
+
});
|
|
669
|
+
const head = `Created ${created.length} of ${total} attribute definitions on ${typeInternalName} in ${seconds} s`;
|
|
670
|
+
if (!failure) {
|
|
671
|
+
return [
|
|
672
|
+
`${head}, in list order:`,
|
|
673
|
+
...lines,
|
|
674
|
+
'Confirm the attributes and their order with one cplace_get_type_datamodel read.',
|
|
675
|
+
].join('\n');
|
|
676
|
+
}
|
|
677
|
+
const failed = created.length + 1;
|
|
678
|
+
const rest = failed === total ? `item ${failed}` : `items ${failed} to ${total}`;
|
|
679
|
+
return [
|
|
680
|
+
failed === total
|
|
681
|
+
? `${head}. Item ${failed} failed:`
|
|
682
|
+
: `${head}. Item ${failed} failed, so the rest were not tried:`,
|
|
683
|
+
...lines,
|
|
684
|
+
`Fix item ${failed} and send ${rest} again. They are appended after the created ones, so the order stays right.` +
|
|
685
|
+
failure.hint,
|
|
686
|
+
].join('\n');
|
|
687
|
+
}
|
|
531
688
|
export function registerTypeManagementTools(server, client) {
|
|
532
689
|
server.registerTool(TOOL_MANAGE_TYPE_DEFINITION, TYPE_MANAGEMENT_TOOL_DEFINITIONS[TOOL_MANAGE_TYPE_DEFINITION], async (params) => {
|
|
533
690
|
try {
|
|
@@ -720,109 +877,13 @@ export function registerTypeManagementTools(server, client) {
|
|
|
720
877
|
isError: true,
|
|
721
878
|
};
|
|
722
879
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
type: 'text',
|
|
728
|
-
text: 'Error: additionalConstraintData is not supported for custom constraint types in this version.',
|
|
729
|
-
},
|
|
730
|
-
],
|
|
731
|
-
isError: true,
|
|
732
|
-
};
|
|
733
|
-
}
|
|
734
|
-
const ct = params.constraintConfig.constraintType;
|
|
735
|
-
if (ct === 'reference') {
|
|
736
|
-
const entityKind = params.constraintConfig.targetEntityKind;
|
|
737
|
-
if (entityKind &&
|
|
738
|
-
entityKind !== 'page' &&
|
|
739
|
-
!ENTITY_KINDS_NOT_REQUIRING_TYPE_NAMES.includes(entityKind)) {
|
|
740
|
-
return {
|
|
741
|
-
content: [
|
|
742
|
-
{
|
|
743
|
-
type: 'text',
|
|
744
|
-
text: `Error: Invalid targetEntityKind '${entityKind}'. Valid values: 'page' (requires targetTypeNames), 'person' (User), 'group' (Group), 'principal' (User or Group), 'document' (File), 'any' (no entity-kind restriction).`,
|
|
745
|
-
},
|
|
746
|
-
],
|
|
747
|
-
isError: true,
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
const isEntityKindReference = ENTITY_KINDS_NOT_REQUIRING_TYPE_NAMES.includes(entityKind);
|
|
751
|
-
if (!isEntityKindReference &&
|
|
752
|
-
(!params.constraintConfig.targetTypeNames ||
|
|
753
|
-
params.constraintConfig.targetTypeNames.length === 0)) {
|
|
754
|
-
return {
|
|
755
|
-
content: [
|
|
756
|
-
{
|
|
757
|
-
type: 'text',
|
|
758
|
-
text: "Error: Reference attributes require either 'targetTypeNames' for page references (e.g., [\"cf.example.targetType\"]) or 'targetEntityKind' for entity-kind references (valid values: 'person', 'group', 'principal', 'document'). Omitting targetEntityKind defaults to 'page'; use targetEntityKind 'any' for an unrestricted reference.",
|
|
759
|
-
},
|
|
760
|
-
],
|
|
761
|
-
isError: true,
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
if (ct === 'textEnumeration' || ct === 'numberEnumeration') {
|
|
766
|
-
if (!params.constraintConfig.elements ||
|
|
767
|
-
params.constraintConfig.elements.length === 0) {
|
|
768
|
-
return {
|
|
769
|
-
content: [
|
|
770
|
-
{
|
|
771
|
-
type: 'text',
|
|
772
|
-
text: "Error: Enumeration attributes require 'elements' in constraintConfig with at least one element.",
|
|
773
|
-
},
|
|
774
|
-
],
|
|
775
|
-
isError: true,
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
if (ct === 'linkedAttribute') {
|
|
780
|
-
if (!params.constraintConfig.linkedReferenceName ||
|
|
781
|
-
!params.constraintConfig.linkedPropertyName) {
|
|
782
|
-
return {
|
|
783
|
-
content: [
|
|
784
|
-
{
|
|
785
|
-
type: 'text',
|
|
786
|
-
text: "Error: Linked attributes require both 'linkedReferenceName' and 'linkedPropertyName' in constraintConfig.",
|
|
787
|
-
},
|
|
788
|
-
],
|
|
789
|
-
isError: true,
|
|
790
|
-
};
|
|
791
|
-
}
|
|
880
|
+
const item = { ...params, constraintConfig: params.constraintConfig };
|
|
881
|
+
const problem = checkAttributeCreate(item);
|
|
882
|
+
if (problem) {
|
|
883
|
+
return { content: [{ type: 'text', text: `Error: ${problem}` }], isError: true };
|
|
792
884
|
}
|
|
793
885
|
debugLogWithTag('ATTRIBUTE_CREATION', `Creating attribute: ${params.attributeName} for type: ${params.typeInternalName} in workspace: ${params.workspaceId}`);
|
|
794
|
-
const requestBody =
|
|
795
|
-
workspaceId: params.workspaceId,
|
|
796
|
-
typeDefinitionInternalName: params.typeInternalName,
|
|
797
|
-
attributeName: params.attributeName,
|
|
798
|
-
constraintConfig: params.constraintConfig,
|
|
799
|
-
};
|
|
800
|
-
if (params.multiplicity)
|
|
801
|
-
requestBody.multiplicity = params.multiplicity;
|
|
802
|
-
if (params.localizedNames)
|
|
803
|
-
requestBody.localizedNames = params.localizedNames;
|
|
804
|
-
if (params.localizedShortNames)
|
|
805
|
-
requestBody.localizedShortNames = params.localizedShortNames;
|
|
806
|
-
if (params.localizedShortHelp)
|
|
807
|
-
requestBody.localizedShortHelp = params.localizedShortHelp;
|
|
808
|
-
if (params.readOnly !== undefined)
|
|
809
|
-
requestBody.readOnly = params.readOnly;
|
|
810
|
-
if (params.showInTables !== undefined)
|
|
811
|
-
requestBody.showInTables = params.showInTables;
|
|
812
|
-
if (params.showInNewDialog !== undefined)
|
|
813
|
-
requestBody.showInNewDialog = params.showInNewDialog;
|
|
814
|
-
if (params.showValuesWithLineBreak !== undefined)
|
|
815
|
-
requestBody.showValuesWithLineBreak = params.showValuesWithLineBreak;
|
|
816
|
-
if (params.showInAttributesWidget !== undefined)
|
|
817
|
-
requestBody.showInAttributesWidget = params.showInAttributesWidget;
|
|
818
|
-
if (params.showInColumnSelection !== undefined)
|
|
819
|
-
requestBody.showInColumnSelection = params.showInColumnSelection;
|
|
820
|
-
if (params.tableColumnWidth !== undefined)
|
|
821
|
-
requestBody.tableColumnWidth = params.tableColumnWidth;
|
|
822
|
-
if (params.queryableForScripting !== undefined)
|
|
823
|
-
requestBody.queryableForScripting = params.queryableForScripting;
|
|
824
|
-
if (params.defaultValues !== undefined)
|
|
825
|
-
requestBody.defaultValues = params.defaultValues;
|
|
886
|
+
const requestBody = buildAttributeCreateBody(params.workspaceId, params.typeInternalName, item);
|
|
826
887
|
const result = await client.makeApiRequest('json/attribute-definition', 'POST', undefined, requestBody);
|
|
827
888
|
debugLogWithTag('ATTRIBUTE_CREATION', `Successfully created attribute: ${params.attributeName}`);
|
|
828
889
|
return {
|
|
@@ -841,18 +902,6 @@ export function registerTypeManagementTools(server, client) {
|
|
|
841
902
|
isError: true,
|
|
842
903
|
};
|
|
843
904
|
}
|
|
844
|
-
if (params.constraintConfig &&
|
|
845
|
-
params.constraintConfig.additionalConstraintData !== undefined) {
|
|
846
|
-
return {
|
|
847
|
-
content: [
|
|
848
|
-
{
|
|
849
|
-
type: 'text',
|
|
850
|
-
text: 'Error: additionalConstraintData is not supported for custom constraint types in this version.',
|
|
851
|
-
},
|
|
852
|
-
],
|
|
853
|
-
isError: true,
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
905
|
debugLogWithTag('ATTRIBUTE_UPDATE', `Updating attribute: ${params.attributeName} for type: ${params.typeInternalName} in workspace: ${params.workspaceId}`);
|
|
857
906
|
const requestBody = {
|
|
858
907
|
workspaceId: params.workspaceId,
|
|
@@ -909,6 +958,47 @@ export function registerTypeManagementTools(server, client) {
|
|
|
909
958
|
};
|
|
910
959
|
}
|
|
911
960
|
});
|
|
961
|
+
server.registerTool(TOOL_CREATE_ATTRIBUTE_DEFINITIONS, TYPE_MANAGEMENT_TOOL_DEFINITIONS[TOOL_CREATE_ATTRIBUTE_DEFINITIONS], async ({ workspaceId, typeInternalName, attributeDefinitions: items }) => {
|
|
962
|
+
const problems = checkAttributeList(items);
|
|
963
|
+
if (problems.length > 0) {
|
|
964
|
+
return {
|
|
965
|
+
content: [
|
|
966
|
+
{
|
|
967
|
+
type: 'text',
|
|
968
|
+
text: 'Error: nothing was created. Fix these items and send the whole list again:\n' +
|
|
969
|
+
problems.join('\n'),
|
|
970
|
+
},
|
|
971
|
+
],
|
|
972
|
+
isError: true,
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
debugLogWithTag('ATTRIBUTE_CREATION', `Creating ${items.length} attributes for type: ${typeInternalName} in workspace: ${workspaceId}`);
|
|
976
|
+
const start = Date.now();
|
|
977
|
+
const created = [];
|
|
978
|
+
let failure;
|
|
979
|
+
for (const item of items) {
|
|
980
|
+
try {
|
|
981
|
+
const result = await client.makeApiRequest('json/attribute-definition', 'POST', undefined, buildAttributeCreateBody(workspaceId, typeInternalName, item));
|
|
982
|
+
const name = typeof result?.name === 'string' ? result.name : item.attributeName;
|
|
983
|
+
created.push(name);
|
|
984
|
+
debugLogWithTag('ATTRIBUTE_CREATION', `Created attribute ${created.length}: ${name}`);
|
|
985
|
+
}
|
|
986
|
+
catch (error) {
|
|
987
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
988
|
+
failure = {
|
|
989
|
+
message,
|
|
990
|
+
hint: appendCustomConstraintHintIfNeeded(message).slice(message.length),
|
|
991
|
+
};
|
|
992
|
+
debugLogWithTag('ATTRIBUTE_CREATION', `Stopped at item ${created.length + 1} (${item.attributeName}): ${message}`);
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
const seconds = ((Date.now() - start) / 1000).toFixed(1);
|
|
997
|
+
const text = formatCreateReport(typeInternalName, items, created, failure, seconds);
|
|
998
|
+
return failure
|
|
999
|
+
? { content: [{ type: 'text', text }], isError: true }
|
|
1000
|
+
: { content: [{ type: 'text', text }] };
|
|
1001
|
+
});
|
|
912
1002
|
server.registerTool(TOOL_LIST_CUSTOM_CONSTRAINT_TYPES, TYPE_MANAGEMENT_TOOL_DEFINITIONS[TOOL_LIST_CUSTOM_CONSTRAINT_TYPES], async () => {
|
|
913
1003
|
try {
|
|
914
1004
|
const result = await client.makeApiRequest('json/custom-constraint-types', 'GET');
|