@testomatio/mcp 2.1.1 → 2.2.0-beta
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 +37 -6
- package/package.json +1 -1
- package/src/api/testomatio-client.js +2 -6
- package/src/cli/main.js +4 -0
- package/src/config/constants.js +4 -0
- package/src/config/load-config.js +10 -1
- package/src/index.js +8 -1
- package/src/mcp/configs/attachments-config.js +7 -0
- package/src/mcp/configs/entity-crud-config.js +0 -6
- package/src/mcp/definitions/attachments.js +70 -0
- package/src/mcp/definitions/issues.js +0 -37
- package/src/mcp/definitions/plans.js +0 -39
- package/src/mcp/definitions/projects.js +12 -0
- package/src/mcp/definitions/requirements.js +0 -27
- package/src/mcp/definitions/runs.js +0 -23
- package/src/mcp/definitions/suites.js +10 -37
- package/src/mcp/definitions/system.js +8 -0
- package/src/mcp/definitions/testruns.js +14 -123
- package/src/mcp/definitions/tests.js +28 -27
- package/src/mcp/definitions/tql-reference.js +31 -51
- package/src/mcp/list-projection.js +140 -0
- package/src/mcp/registry/attachments.js +40 -0
- package/src/mcp/registry/handlers.js +73 -20
- package/src/mcp/registry/issues.js +0 -4
- package/src/mcp/registry/listings.js +0 -37
- package/src/mcp/tool-definitions.js +7 -2
- package/src/mcp/tool-profiles.js +37 -0
- package/src/mcp/tool-registry.js +33 -2
|
@@ -149,7 +149,13 @@ export const TESTRUNS_TOOLS = [
|
|
|
149
149
|
"type": "string"
|
|
150
150
|
},
|
|
151
151
|
"status": {
|
|
152
|
-
"type": "string"
|
|
152
|
+
"type": "string",
|
|
153
|
+
"enum": [
|
|
154
|
+
"passed",
|
|
155
|
+
"failed",
|
|
156
|
+
"skipped",
|
|
157
|
+
"pending"
|
|
158
|
+
]
|
|
153
159
|
},
|
|
154
160
|
"message": {
|
|
155
161
|
"type": "string"
|
|
@@ -189,7 +195,13 @@ export const TESTRUNS_TOOLS = [
|
|
|
189
195
|
"type": "string"
|
|
190
196
|
},
|
|
191
197
|
"status": {
|
|
192
|
-
"type": "string"
|
|
198
|
+
"type": "string",
|
|
199
|
+
"enum": [
|
|
200
|
+
"passed",
|
|
201
|
+
"failed",
|
|
202
|
+
"skipped",
|
|
203
|
+
"pending"
|
|
204
|
+
]
|
|
193
205
|
},
|
|
194
206
|
"message": {
|
|
195
207
|
"type": "string"
|
|
@@ -229,127 +241,6 @@ export const TESTRUNS_TOOLS = [
|
|
|
229
241
|
"additionalProperties": false
|
|
230
242
|
}
|
|
231
243
|
},
|
|
232
|
-
{
|
|
233
|
-
"name": "testruns_search",
|
|
234
|
-
"description": "Search testruns (delegates to testruns list; docs has no dedicated search parameter)",
|
|
235
|
-
"inputSchema": {
|
|
236
|
-
"type": "object",
|
|
237
|
-
"properties": {
|
|
238
|
-
"run_id": {
|
|
239
|
-
"type": "string"
|
|
240
|
-
},
|
|
241
|
-
"test_ids": {
|
|
242
|
-
"type": [
|
|
243
|
-
"array",
|
|
244
|
-
"string"
|
|
245
|
-
],
|
|
246
|
-
"items": {
|
|
247
|
-
"type": "string"
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
"filter_status": {
|
|
251
|
-
"type": "string",
|
|
252
|
-
"enum": [
|
|
253
|
-
"passed",
|
|
254
|
-
"failed",
|
|
255
|
-
"skipped",
|
|
256
|
-
"pending"
|
|
257
|
-
]
|
|
258
|
-
},
|
|
259
|
-
"filter_kind": {
|
|
260
|
-
"type": "string",
|
|
261
|
-
"enum": [
|
|
262
|
-
"manual",
|
|
263
|
-
"automated"
|
|
264
|
-
]
|
|
265
|
-
},
|
|
266
|
-
"filter_user": {
|
|
267
|
-
"type": [
|
|
268
|
-
"integer",
|
|
269
|
-
"string"
|
|
270
|
-
]
|
|
271
|
-
},
|
|
272
|
-
"filter_priority": {
|
|
273
|
-
"type": "string",
|
|
274
|
-
"enum": [
|
|
275
|
-
"low",
|
|
276
|
-
"normal",
|
|
277
|
-
"important",
|
|
278
|
-
"high",
|
|
279
|
-
"critical"
|
|
280
|
-
]
|
|
281
|
-
},
|
|
282
|
-
"filter_substatus": {
|
|
283
|
-
"type": "string"
|
|
284
|
-
},
|
|
285
|
-
"filter_search": {
|
|
286
|
-
"type": "string"
|
|
287
|
-
},
|
|
288
|
-
"page": {
|
|
289
|
-
"type": "integer",
|
|
290
|
-
"minimum": 1
|
|
291
|
-
},
|
|
292
|
-
"per_page": {
|
|
293
|
-
"type": "integer",
|
|
294
|
-
"minimum": 1,
|
|
295
|
-
"maximum": 100
|
|
296
|
-
},
|
|
297
|
-
"filter_message": {
|
|
298
|
-
"type": "boolean"
|
|
299
|
-
},
|
|
300
|
-
"filter_link": {
|
|
301
|
-
"type": "boolean"
|
|
302
|
-
},
|
|
303
|
-
"filter_finished_at_date_range": {
|
|
304
|
-
"type": "string"
|
|
305
|
-
},
|
|
306
|
-
"tags": {
|
|
307
|
-
"type": [
|
|
308
|
-
"array",
|
|
309
|
-
"string"
|
|
310
|
-
],
|
|
311
|
-
"items": {
|
|
312
|
-
"type": "string"
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
"labels": {
|
|
316
|
-
"type": [
|
|
317
|
-
"array",
|
|
318
|
-
"string"
|
|
319
|
-
],
|
|
320
|
-
"items": {
|
|
321
|
-
"type": "string"
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
|
-
"envs": {
|
|
325
|
-
"type": [
|
|
326
|
-
"array",
|
|
327
|
-
"string"
|
|
328
|
-
],
|
|
329
|
-
"items": {
|
|
330
|
-
"type": "string"
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
"rungroups": {
|
|
334
|
-
"type": [
|
|
335
|
-
"array",
|
|
336
|
-
"string"
|
|
337
|
-
],
|
|
338
|
-
"items": {
|
|
339
|
-
"type": "string"
|
|
340
|
-
}
|
|
341
|
-
},
|
|
342
|
-
"defects": {
|
|
343
|
-
"type": "string",
|
|
344
|
-
"enum": [
|
|
345
|
-
"has_defects",
|
|
346
|
-
"without_defects"
|
|
347
|
-
]
|
|
348
|
-
}
|
|
349
|
-
},
|
|
350
|
-
"additionalProperties": false
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
244
|
{
|
|
354
245
|
"name": "testruns_issues_list",
|
|
355
246
|
"description": "List linked issues for a testrun (/api/v2/{project_id}/issues?testrun_id=...)",
|
|
@@ -59,7 +59,14 @@ export const TESTS_TOOLS = [
|
|
|
59
59
|
"type": "string"
|
|
60
60
|
},
|
|
61
61
|
"priority": {
|
|
62
|
-
"type": "string"
|
|
62
|
+
"type": "string",
|
|
63
|
+
"enum": [
|
|
64
|
+
"low",
|
|
65
|
+
"normal",
|
|
66
|
+
"important",
|
|
67
|
+
"high",
|
|
68
|
+
"critical"
|
|
69
|
+
]
|
|
63
70
|
},
|
|
64
71
|
"assigned_to": {
|
|
65
72
|
"type": "string"
|
|
@@ -68,7 +75,12 @@ export const TESTS_TOOLS = [
|
|
|
68
75
|
"type": "string"
|
|
69
76
|
},
|
|
70
77
|
"state": {
|
|
71
|
-
"type": "string"
|
|
78
|
+
"type": "string",
|
|
79
|
+
"enum": [
|
|
80
|
+
"manual",
|
|
81
|
+
"detached",
|
|
82
|
+
"automated"
|
|
83
|
+
]
|
|
72
84
|
},
|
|
73
85
|
"link": {
|
|
74
86
|
"type": "array",
|
|
@@ -135,7 +147,14 @@ export const TESTS_TOOLS = [
|
|
|
135
147
|
"type": "string"
|
|
136
148
|
},
|
|
137
149
|
"priority": {
|
|
138
|
-
"type": "string"
|
|
150
|
+
"type": "string",
|
|
151
|
+
"enum": [
|
|
152
|
+
"low",
|
|
153
|
+
"normal",
|
|
154
|
+
"important",
|
|
155
|
+
"high",
|
|
156
|
+
"critical"
|
|
157
|
+
]
|
|
139
158
|
},
|
|
140
159
|
"assigned_to": {
|
|
141
160
|
"type": "string"
|
|
@@ -144,7 +163,12 @@ export const TESTS_TOOLS = [
|
|
|
144
163
|
"type": "string"
|
|
145
164
|
},
|
|
146
165
|
"state": {
|
|
147
|
-
"type": "string"
|
|
166
|
+
"type": "string",
|
|
167
|
+
"enum": [
|
|
168
|
+
"manual",
|
|
169
|
+
"detached",
|
|
170
|
+
"automated"
|
|
171
|
+
]
|
|
148
172
|
},
|
|
149
173
|
"sync": {
|
|
150
174
|
"type": "boolean"
|
|
@@ -207,29 +231,6 @@ export const TESTS_TOOLS = [
|
|
|
207
231
|
"additionalProperties": false
|
|
208
232
|
}
|
|
209
233
|
},
|
|
210
|
-
{
|
|
211
|
-
"name": "tests_search",
|
|
212
|
-
"description": `Search tests using TQL (delegates to tests_list). ${TESTS_TQL_REFERENCE}`,
|
|
213
|
-
"inputSchema": {
|
|
214
|
-
"type": "object",
|
|
215
|
-
"properties": {
|
|
216
|
-
"page": {
|
|
217
|
-
"type": "integer",
|
|
218
|
-
"minimum": 1
|
|
219
|
-
},
|
|
220
|
-
"per_page": {
|
|
221
|
-
"type": "integer",
|
|
222
|
-
"minimum": 1,
|
|
223
|
-
"maximum": 100
|
|
224
|
-
},
|
|
225
|
-
"tql": {
|
|
226
|
-
"type": "string",
|
|
227
|
-
"description": TESTS_TQL_INPUT_DESCRIPTION
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
"additionalProperties": false
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
234
|
{
|
|
234
235
|
"name": "tests_issues_list",
|
|
235
236
|
"description": "List linked issues for a test (/api/v2/{project_id}/issues?test_id=...)",
|
|
@@ -89,62 +89,42 @@ const RUNS_TQL_EXAMPLES = [
|
|
|
89
89
|
const COMMON_TQL_SYNTAX =
|
|
90
90
|
"Supported syntax includes logical operators `and`, `or`, `not`, equality operators `==` and `!=`, list membership `in [...]`, `%` for partial text match on supported text fields, and parentheses for grouping. Ordered comparisons `>`, `<`, `>=`, `<=` are for ordered fields such as `priority`, dates, and numeric counters/durations. Use quotes for string values, for example `state == 'automated'`.";
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
`Documented test variables: ${TESTS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
95
|
-
`Documented examples: ${TESTS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
96
|
-
'Do not invent undocumented fields or syntax. If a query fails, simplify it to one documented predicate.';
|
|
92
|
+
const TESTS_TQL_FIELDS = TESTS_TQL_VARIABLES.join(', ');
|
|
93
|
+
const RUNS_TQL_FIELDS = RUNS_TQL_VARIABLES.join(', ');
|
|
97
94
|
|
|
98
|
-
export const
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
export const TQL_FULL_REFERENCE = [
|
|
96
|
+
'TQL (Testomat.io Query Language) is a string expression used to filter tests and runs.',
|
|
97
|
+
COMMON_TQL_SYNTAX,
|
|
98
|
+
'',
|
|
99
|
+
`Tests filter variables: ${TESTS_TQL_VARIABLES.map((v) => `\`${v}\``).join(', ')}.`,
|
|
100
|
+
`Tests examples: ${TESTS_TQL_EXAMPLES.map((e) => `\`${e}\``).join(', ')}.`,
|
|
101
|
+
'',
|
|
102
|
+
`Runs filter variables: ${RUNS_TQL_VARIABLES.map((v) => `\`${v}\``).join(', ')}.`,
|
|
103
|
+
'Runs also support boolean flags used without comparison, e.g. `failed`, `finished`, `automated`, `with_defect`.',
|
|
104
|
+
`Runs examples: ${RUNS_TQL_EXAMPLES.map((e) => `\`${e}\``).join(', ')}.`,
|
|
105
|
+
'',
|
|
106
|
+
'Parameter name: tests/runs/plans use `tql`; analytics tools use `q`.',
|
|
107
|
+
'Do not invent undocumented fields or syntax. If a query fails, simplify it to one documented predicate.',
|
|
108
|
+
].join('\n');
|
|
101
109
|
|
|
110
|
+
export const TESTS_TQL_REFERENCE =
|
|
111
|
+
'Filter tests with `tql` (TQL); call `tql_help` for the syntax and full field list.';
|
|
102
112
|
export const RUNS_TQL_REFERENCE =
|
|
103
|
-
`
|
|
104
|
-
'Runs also support boolean flags without comparison such as `failed`, `finished`, `automated`, or `with_defect`. ' +
|
|
105
|
-
`Documented run variables: ${RUNS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
106
|
-
`Documented examples: ${RUNS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
107
|
-
'Do not invent undocumented fields or syntax. If a query fails, simplify it to one documented predicate.';
|
|
108
|
-
|
|
109
|
-
export const RUNS_TQL_INPUT_DESCRIPTION =
|
|
110
|
-
`TQL filter for runs. Documented variables: ${RUNS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
111
|
-
`Examples: ${RUNS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}.`;
|
|
112
|
-
|
|
113
|
+
'Filter runs with `tql` (TQL); runs also accept boolean flags. Call `tql_help` for the syntax and full field list.';
|
|
113
114
|
export const PLANS_TQL_REFERENCE =
|
|
114
|
-
|
|
115
|
-
`Plan TQL uses documented test variables: ${TESTS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
116
|
-
`Documented examples: ${TESTS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
117
|
-
'Use `tql` when you want the API to resolve matching tests automatically instead of sending explicit `test_ids`. Do not invent undocumented fields or syntax. If a query fails, simplify it to one documented predicate.';
|
|
118
|
-
|
|
119
|
-
export const PLANS_TQL_INPUT_DESCRIPTION =
|
|
120
|
-
'TQL filter for selecting tests included in the plan. ' +
|
|
121
|
-
`Documented test variables: ${TESTS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
122
|
-
`Examples: ${TESTS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}.`;
|
|
123
|
-
|
|
115
|
+
'Select tests for the plan with `tql` (TQL); the API resolves matching tests. Call `tql_help` for the syntax and full field list.';
|
|
124
116
|
export const ANALYTICS_TESTS_TQL_REFERENCE =
|
|
125
|
-
|
|
126
|
-
'For analytics tools, the API parameter name is `q`, not `tql`. ' +
|
|
127
|
-
`Documented analytics test variables: ${TESTS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
128
|
-
`Documented examples: ${TESTS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
129
|
-
'Do not invent undocumented fields or syntax. If a query fails, simplify it to one documented predicate.';
|
|
130
|
-
|
|
131
|
-
export const ANALYTICS_TESTS_TQL_INPUT_DESCRIPTION =
|
|
132
|
-
'TQL filter for analytics test reports. The API parameter name is `q`, not `tql`. ' +
|
|
133
|
-
`Documented variables: ${TESTS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
134
|
-
`Examples: ${TESTS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}.`;
|
|
135
|
-
|
|
117
|
+
'Filter analytics test reports with `q` (TQL). Call `tql_help` for the syntax and full field list.';
|
|
136
118
|
export const ANALYTICS_STATS_TQL_REFERENCE =
|
|
137
|
-
|
|
138
|
-
'For analytics tools, the API parameter name is `q`, not `tql`. ' +
|
|
139
|
-
'According to the official Analytics docs, analytics queries are configured using supported query variables for two data sources: `Tests Variables` and `Runs Variables`. ' +
|
|
140
|
-
`Documented Tests Variables: ${TESTS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
141
|
-
`Documented Runs Variables: ${RUNS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
142
|
-
`Documented Tests examples: ${TESTS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
143
|
-
`Documented Runs examples: ${RUNS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
144
|
-
'Use Tests Variables for test-centric filters and Runs Variables for run-centric filters such as `plan`, `rungroup`, `env`, `finished_at`, or `has_test_tag`. Do not invent undocumented fields or syntax. If a query fails, simplify it to one documented predicate.';
|
|
119
|
+
'Filter analytics aggregated reports with `q` (TQL; tests or runs variables). Call `tql_help` for the syntax and full field list.';
|
|
145
120
|
|
|
121
|
+
export const TESTS_TQL_INPUT_DESCRIPTION =
|
|
122
|
+
`TQL filter for tests. Fields: ${TESTS_TQL_FIELDS}. Call \`tql_help\` for syntax. Examples: \`priority == 'high'\`, \`state == 'automated'\`, \`suite % 'Checkout'\`.`;
|
|
123
|
+
export const RUNS_TQL_INPUT_DESCRIPTION =
|
|
124
|
+
`TQL filter for runs. Fields: ${RUNS_TQL_FIELDS}. Call \`tql_help\` for syntax. Examples: \`finished and with_defect\`, \`env in ['Windows', 'Linux']\`, \`has_retries > 2\`.`;
|
|
125
|
+
export const PLANS_TQL_INPUT_DESCRIPTION =
|
|
126
|
+
`TQL to select tests for the plan. Fields: ${TESTS_TQL_FIELDS}. Call \`tql_help\` for syntax. Examples: \`priority == 'high'\`, \`tag in ['smoke', 'stage1']\`.`;
|
|
127
|
+
export const ANALYTICS_TESTS_TQL_INPUT_DESCRIPTION =
|
|
128
|
+
`TQL filter (param \`q\`) for analytics test reports. Fields: ${TESTS_TQL_FIELDS}. Call \`tql_help\` for syntax. Examples: \`priority == 'high'\`, \`state == 'automated'\`.`;
|
|
146
129
|
export const ANALYTICS_STATS_TQL_INPUT_DESCRIPTION =
|
|
147
|
-
|
|
148
|
-
`Documented Tests Variables: ${TESTS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
149
|
-
`Documented Runs Variables: ${RUNS_TQL_VARIABLES.map((item) => `\`${item}\``).join(', ')}. ` +
|
|
150
|
-
`Examples: ${TESTS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}, ${RUNS_TQL_EXAMPLES.map((item) => `\`${item}\``).join(', ')}.`;
|
|
130
|
+
`TQL filter (param \`q\`) for analytics reports. Test fields: ${TESTS_TQL_FIELDS}. Run fields: ${RUNS_TQL_FIELDS}. Call \`tql_help\` for syntax. Examples: \`priority == 'high'\`, \`finished_at >= '2025-07-01' and failed\`.`;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slim projection for list-tool responses.
|
|
3
|
+
*
|
|
4
|
+
* List tools return only what an index view needs: entity-specific heavy fields
|
|
5
|
+
* and null values are dropped.
|
|
6
|
+
* `verbose:true` returns the full body; `fields:[...]` selects a custom field set.
|
|
7
|
+
* Every shaped response carries a `_view` marker so the caller knows it is partial.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const HEAVY_FIELDS_BY_ENTITY = {
|
|
11
|
+
tests: new Set(['description', 'code', 'cleanTitle', 'publicTitle']),
|
|
12
|
+
suites: new Set(['description', 'code', 'cleanTitle', 'publicTitle']),
|
|
13
|
+
runs: new Set(['description']),
|
|
14
|
+
testruns: new Set(['description', 'code']),
|
|
15
|
+
rungroups: new Set(['description']),
|
|
16
|
+
steps: new Set(['description']),
|
|
17
|
+
snippets: new Set(['description']),
|
|
18
|
+
plans: new Set(['description']),
|
|
19
|
+
requirements: new Set(['description']),
|
|
20
|
+
analytics_tests: new Set(['description', 'code', 'cleanTitle', 'publicTitle']),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function isNullish(value) {
|
|
24
|
+
return value === null || value === undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function pickFields(item, fields) {
|
|
28
|
+
const result = {};
|
|
29
|
+
for (const key of fields) {
|
|
30
|
+
if (!(key in item)) continue;
|
|
31
|
+
const value = item[key];
|
|
32
|
+
if (isNullish(value)) continue;
|
|
33
|
+
result[key] = value;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function stripHeavy(item, heavyFields) {
|
|
39
|
+
const result = {};
|
|
40
|
+
for (const [key, value] of Object.entries(item)) {
|
|
41
|
+
if (heavyFields.has(key)) continue;
|
|
42
|
+
if (isNullish(value)) continue;
|
|
43
|
+
result[key] = value;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function mapItems(items, fn) {
|
|
49
|
+
return items.map((item) =>
|
|
50
|
+
item && typeof item === 'object' && !Array.isArray(item) ? fn(item) : item
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function applyToEnvelope(payload, fn) {
|
|
55
|
+
if (!payload || typeof payload !== 'object') return payload;
|
|
56
|
+
if (Array.isArray(payload)) return mapItems(payload, fn);
|
|
57
|
+
if (Array.isArray(payload.data)) {
|
|
58
|
+
return { ...payload, data: mapItems(payload.data, fn) };
|
|
59
|
+
}
|
|
60
|
+
return payload;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const VIEW_NOTE =
|
|
64
|
+
'Entity-specific heavy fields and null values removed. Pass verbose:true for full bodies or fields:[...] to select fields.';
|
|
65
|
+
|
|
66
|
+
function withViewMarker(result, note = VIEW_NOTE) {
|
|
67
|
+
if (
|
|
68
|
+
result &&
|
|
69
|
+
typeof result === 'object' &&
|
|
70
|
+
!Array.isArray(result) &&
|
|
71
|
+
Array.isArray(result.data)
|
|
72
|
+
) {
|
|
73
|
+
return { ...result, _view: note };
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Shape a list payload: drop entity-specific heavy and null fields by default, full body on `verbose`,
|
|
80
|
+
* custom field set on `fields`. A `_view` marker is added to shaped envelopes.
|
|
81
|
+
*
|
|
82
|
+
* @param {*} payload raw API response ({ data, meta } or a bare array)
|
|
83
|
+
* @param {{ verbose?: boolean, fields?: string[], entity?: string }} [opts]
|
|
84
|
+
*/
|
|
85
|
+
export function slimList(payload, { verbose = false, fields, entity } = {}) {
|
|
86
|
+
if (verbose) {
|
|
87
|
+
return payload;
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(fields) && fields.length) {
|
|
90
|
+
return withViewMarker(
|
|
91
|
+
applyToEnvelope(payload, (item) => pickFields(item, fields)),
|
|
92
|
+
`Custom fields [${fields.join(', ')}]. Pass verbose:true for the full object.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const heavyFields = HEAVY_FIELDS_BY_ENTITY[entity] ?? new Set();
|
|
96
|
+
return withViewMarker(applyToEnvelope(payload, (item) => stripHeavy(item, heavyFields)));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const LIST_OPTION_PROPERTIES = {
|
|
100
|
+
verbose: {
|
|
101
|
+
type: 'boolean',
|
|
102
|
+
default: false,
|
|
103
|
+
description:
|
|
104
|
+
'Return full response bodies. Default strips entity-specific heavy fields and null values; set true when you need those.',
|
|
105
|
+
},
|
|
106
|
+
fields: {
|
|
107
|
+
type: 'array',
|
|
108
|
+
items: { type: 'string' },
|
|
109
|
+
description:
|
|
110
|
+
'Fields to keep per item (e.g. ["id","title","status","message"]). Ignored when verbose is true.',
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Inject `verbose`/`fields` input params into every list-style tool definition so the
|
|
116
|
+
* model can opt into full bodies or a custom projection. Returns shallow copies; the
|
|
117
|
+
* source definitions are not mutated.
|
|
118
|
+
*
|
|
119
|
+
* @param {Array} tools
|
|
120
|
+
* @param {{ extraNames?: string[] }} [options] additional tool names to augment
|
|
121
|
+
*/
|
|
122
|
+
export function withListOptions(tools, { extraNames = [] } = {}) {
|
|
123
|
+
return tools.map((tool) => {
|
|
124
|
+
if (!tool || !tool.name) return tool;
|
|
125
|
+
const isListStyle = tool.name.endsWith('_list') || extraNames.includes(tool.name);
|
|
126
|
+
if (!isListStyle) return tool;
|
|
127
|
+
|
|
128
|
+
const inputSchema = tool.inputSchema || { type: 'object', properties: {} };
|
|
129
|
+
const properties = { ...(inputSchema.properties || {}), ...LIST_OPTION_PROPERTIES };
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
...tool,
|
|
133
|
+
description: `${tool.description ?? ''} Entity-specific heavy fields are stripped by default; verbose:true for full bodies.`.trim(),
|
|
134
|
+
inputSchema: {
|
|
135
|
+
...inputSchema,
|
|
136
|
+
properties,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { ATTACHMENT_RESOURCE_KEYS } from '../configs/attachments-config.js';
|
|
5
|
+
|
|
6
|
+
export const attachmentMethods = {
|
|
7
|
+
listAttachmentsForKey({ resourceKey, resourceId }) {
|
|
8
|
+
this.assertSupportedAttachmentResourceKey(resourceKey);
|
|
9
|
+
return this.apiClient.list('attachments', { [resourceKey]: resourceId });
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
async uploadAttachmentForKey({ resourceKey, resourceId, filePath }) {
|
|
13
|
+
this.assertSupportedAttachmentResourceKey(resourceKey);
|
|
14
|
+
const formData = await this.buildAttachmentFormData(filePath);
|
|
15
|
+
|
|
16
|
+
return this.apiClient.createMultipart('attachments', formData, {
|
|
17
|
+
[resourceKey]: resourceId,
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
deleteAttachmentForKey({ resourceKey, resourceId, attachmentId }) {
|
|
22
|
+
this.assertSupportedAttachmentResourceKey(resourceKey);
|
|
23
|
+
return this.apiClient.delete('attachments', attachmentId, { [resourceKey]: resourceId });
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
async buildAttachmentFormData(filePath) {
|
|
27
|
+
const resolvedPath = path.resolve(String(filePath));
|
|
28
|
+
const data = await fs.readFile(resolvedPath);
|
|
29
|
+
const formData = new FormData();
|
|
30
|
+
|
|
31
|
+
formData.append('file', new Blob([data]), path.basename(resolvedPath));
|
|
32
|
+
return formData;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
assertSupportedAttachmentResourceKey(resourceKey) {
|
|
36
|
+
if (!ATTACHMENT_RESOURCE_KEYS.includes(resourceKey)) {
|
|
37
|
+
throw new Error(`Unsupported attachment resource key: ${resourceKey}`);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { ENTITY_CRUD_CONFIGS } from '../configs/entity-crud-config.js';
|
|
2
|
+
import { ATTACHMENT_SCOPED_TOOL_CONFIGS } from '../configs/attachments-config.js';
|
|
2
3
|
import { ISSUE_SCOPED_TOOL_CONFIGS } from '../configs/issues-config.js';
|
|
4
|
+
import { slimList } from '../list-projection.js';
|
|
3
5
|
|
|
4
6
|
export const handlerMethods = {
|
|
5
7
|
registerEntityCrudHandlers(handlers) {
|
|
6
8
|
for (const spec of ENTITY_CRUD_CONFIGS) {
|
|
7
|
-
const { toolPrefix, resource, idArg, listMethod
|
|
8
|
-
|
|
9
|
-
handlers[`${toolPrefix}_list`] = async (args = {}) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const { toolPrefix, resource, idArg, listMethod } = spec;
|
|
10
|
+
|
|
11
|
+
handlers[`${toolPrefix}_list`] = async (args = {}) => {
|
|
12
|
+
const { verbose, fields, ...listArgs } = args;
|
|
13
|
+
return this.asText(
|
|
14
|
+
slimList(await this[listMethod](listArgs), {
|
|
15
|
+
verbose,
|
|
16
|
+
fields,
|
|
17
|
+
entity: toolPrefix,
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
};
|
|
15
21
|
handlers[`${toolPrefix}_get`] = async (args = {}) =>
|
|
16
22
|
this.asText(await this.apiClient.get(resource, this.pickRequiredArg(args, idArg)));
|
|
17
23
|
handlers[`${toolPrefix}_create`] = async (args = {}) =>
|
|
@@ -30,13 +36,16 @@ export const handlerMethods = {
|
|
|
30
36
|
for (const { toolPrefix, resourceKey } of ISSUE_SCOPED_TOOL_CONFIGS) {
|
|
31
37
|
handlers[`${toolPrefix}_issues_list`] = async (args = {}) =>
|
|
32
38
|
this.asText(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
slimList(
|
|
40
|
+
await this.listIssuesForKey({
|
|
41
|
+
resourceKey,
|
|
42
|
+
resourceId: this.pickRequiredArg(args, resourceKey),
|
|
43
|
+
page: args.page,
|
|
44
|
+
per_page: args.per_page,
|
|
45
|
+
source: args.source,
|
|
46
|
+
}),
|
|
47
|
+
{ verbose: args.verbose, fields: args.fields, entity: 'issues' }
|
|
48
|
+
)
|
|
40
49
|
);
|
|
41
50
|
|
|
42
51
|
handlers[`${toolPrefix}_issues_link`] = async (args = {}) =>
|
|
@@ -54,17 +63,61 @@ export const handlerMethods = {
|
|
|
54
63
|
}
|
|
55
64
|
},
|
|
56
65
|
|
|
66
|
+
registerScopedAttachmentHandlers(handlers) {
|
|
67
|
+
for (const { toolPrefix, resourceKey } of ATTACHMENT_SCOPED_TOOL_CONFIGS) {
|
|
68
|
+
handlers[`${toolPrefix}_attachments_list`] = async (args = {}) =>
|
|
69
|
+
this.asText(
|
|
70
|
+
slimList(
|
|
71
|
+
await this.listAttachmentsForKey({
|
|
72
|
+
resourceKey,
|
|
73
|
+
resourceId: this.pickRequiredArg(args, resourceKey),
|
|
74
|
+
}),
|
|
75
|
+
{ verbose: args.verbose, fields: args.fields, entity: 'attachments' }
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
handlers[`${toolPrefix}_attachments_upload`] = async (args = {}) =>
|
|
80
|
+
this.asText(
|
|
81
|
+
await this.uploadAttachmentForKey({
|
|
82
|
+
resourceKey,
|
|
83
|
+
resourceId: this.pickRequiredArg(args, resourceKey),
|
|
84
|
+
filePath: this.pickRequiredArg(args, 'file_path'),
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
handlers[`${toolPrefix}_attachments_delete`] = async (args = {}) =>
|
|
89
|
+
this.asText(
|
|
90
|
+
await this.deleteAttachmentForKey({
|
|
91
|
+
resourceKey,
|
|
92
|
+
resourceId: this.pickRequiredArg(args, resourceKey),
|
|
93
|
+
attachmentId: this.pickRequiredArg(args, 'attachment_id'),
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
|
|
57
99
|
registerGlobalHandlers(handlers) {
|
|
58
|
-
handlers.
|
|
100
|
+
handlers.project_info = async () => this.asText(await this.apiClient.get('info'));
|
|
101
|
+
|
|
102
|
+
handlers.tags_list = async (args = {}) =>
|
|
103
|
+
this.asText(slimList(await this.listTags(), { ...args, entity: 'tags' }));
|
|
59
104
|
handlers.tags_get = async ({ tag_id: tagId }) => this.asText(await this.getTagByTitle(tagId));
|
|
60
|
-
handlers.tags_search = async (args = {}) => this.asText(await this.searchTags(args));
|
|
61
105
|
|
|
62
|
-
handlers.milestones_list = async (args = {}) =>
|
|
106
|
+
handlers.milestones_list = async (args = {}) => {
|
|
107
|
+
const { verbose, fields, ...listArgs } = args;
|
|
108
|
+
return this.asText(
|
|
109
|
+
slimList(await this.listMilestones(listArgs), { verbose, fields, entity: 'milestones' })
|
|
110
|
+
);
|
|
111
|
+
};
|
|
63
112
|
handlers.milestones_get = async ({ milestone_id: milestoneId }) =>
|
|
64
113
|
this.asText(await this.apiClient.get('milestones', milestoneId));
|
|
65
114
|
|
|
66
|
-
handlers.issues_list = async (args = {}) =>
|
|
67
|
-
|
|
115
|
+
handlers.issues_list = async (args = {}) => {
|
|
116
|
+
const { verbose, fields, ...listArgs } = args;
|
|
117
|
+
return this.asText(
|
|
118
|
+
slimList(await this.listIssues(listArgs), { verbose, fields, entity: 'issues' })
|
|
119
|
+
);
|
|
120
|
+
};
|
|
68
121
|
handlers.issues_create = async (args = {}) => this.asText(await this.createIssue(args));
|
|
69
122
|
handlers.issues_delete = async ({ issue_id: issueId, type }) =>
|
|
70
123
|
this.asText(await this.apiClient.delete('issues', issueId, { type }));
|
|
@@ -11,10 +11,6 @@ export const issueMethods = {
|
|
|
11
11
|
});
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
-
searchIssues(args = {}) {
|
|
15
|
-
return this.listIssues(args);
|
|
16
|
-
},
|
|
17
|
-
|
|
18
14
|
createIssue({ url, jira_id: jiraId, ...resourceQuery } = {}) {
|
|
19
15
|
this.validateIssueResourceQuery(resourceQuery, { allowEmpty: false, allowMany: false });
|
|
20
16
|
return this.linkIssueToResource({
|