@pixlcore/xycli 1.2.6 → 1.2.7
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/docs/mcp.md +66 -3
- package/lib/mcp/context.js +14 -2
- package/lib/mcp/definition-tools.js +52 -0
- package/lib/mcp/registry.js +17 -14
- package/lib/mcp/tools/definitions.js +112 -0
- package/lib/mcp/tools/list-active-jobs.js +19 -0
- package/lib/mcp/tools/lookups.js +74 -0
- package/package.json +1 -1
- package/test/mcp-http-unit.test.js +9 -3
- package/test/mcp-stdio-unit.test.js +216 -3
- package/test/mcp-tools-unit.test.js +1 -1
package/docs/mcp.md
CHANGED
|
@@ -165,6 +165,7 @@ This opens only the HTTPS listener. Restart after replacing certificate files. U
|
|
|
165
165
|
| `update_event` | Apply changes using an exact ID and the revision returned by `get_event`. |
|
|
166
166
|
| `delete_event` | Delete an event while retaining historical jobs. Active jobs prevent deletion. |
|
|
167
167
|
| `run_event` | Launch an enabled event with a manual trigger, optionally supplying parameters and input data. |
|
|
168
|
+
| `list_active_jobs` | Find running, queued, and other in-progress jobs by state, event, category or server. Returns job IDs and status summaries. |
|
|
168
169
|
| `get_job` | Inspect job state, completion and output. Optional `fields` selects other job properties. |
|
|
169
170
|
| `get_job_log` | Read a completed job's console log, including archived logs, in bounded byte ranges. |
|
|
170
171
|
| `tail_job_log` | Read recent console output from a running job, along with its current state. |
|
|
@@ -174,12 +175,50 @@ This opens only the HTTPS listener. Restart after replacing certificate files. U
|
|
|
174
175
|
| `update_ticket` | Apply only supplied fields to a ticket by exact ID. |
|
|
175
176
|
| `delete_ticket` | Permanently delete a ticket by exact ID. |
|
|
176
177
|
| `comment_ticket` | Append a Markdown comment with the authenticated key as its author. |
|
|
178
|
+
| `list_plugins` | Find plugin definitions by title or type, including Monitor Plugins. |
|
|
179
|
+
| `get_plugin` | Read a plugin definition and its revision by exact ID. |
|
|
180
|
+
| `create_plugin` | Create a plugin definition, including a Monitor Plugin. |
|
|
181
|
+
| `update_plugin` | Update selected plugin fields by exact ID, with an optional revision check. |
|
|
182
|
+
| `delete_plugin` | Delete a plugin definition by exact ID. |
|
|
183
|
+
| `list_monitors` | Find server monitor definitions by title. |
|
|
184
|
+
| `get_monitor` | Read a monitor definition and its revision by exact ID. |
|
|
185
|
+
| `create_monitor` | Create a server monitor with a source expression and data type. |
|
|
186
|
+
| `update_monitor` | Update selected monitor fields by exact ID, with an optional revision check. |
|
|
187
|
+
| `delete_monitor` | Delete a monitor definition by exact ID. |
|
|
188
|
+
| `list_alerts` | Find alert definitions by title. |
|
|
189
|
+
| `get_alert` | Read an alert definition and its revision by exact ID. |
|
|
190
|
+
| `create_alert` | Create an alert definition with an expression, message and enabled status. |
|
|
191
|
+
| `update_alert` | Update selected alert definition fields by exact ID, with an optional revision check. |
|
|
192
|
+
| `delete_alert` | Delete an alert definition by exact ID. |
|
|
193
|
+
| `list_groups` | Find server group definitions by title. |
|
|
194
|
+
| `get_group` | Read a server group definition and its revision by exact ID. |
|
|
195
|
+
| `create_group` | Create a server group with optional hostname matching. |
|
|
196
|
+
| `update_group` | Update selected server group fields by exact ID, with an optional revision check. |
|
|
197
|
+
| `delete_group` | Delete a server group definition by exact ID. |
|
|
198
|
+
| `set_server_groups` | Replace the manual group memberships for one server. |
|
|
199
|
+
| `test_monitor` | Evaluate a monitor expression against a server's latest saved sample. |
|
|
200
|
+
| `test_alert` | Evaluate an alert expression and render its message using a server's latest saved sample. |
|
|
177
201
|
| `search_alerts` | Search active and historical alert invocations, rather than alert definitions. |
|
|
178
202
|
| `search_snapshots` | Search server/group snapshots, optionally including verbose monitoring details. |
|
|
179
203
|
| `take_snapshot` | Capture the latest monitoring data for exactly one server or group. |
|
|
180
204
|
| `list_servers` | List connected workers, optionally filtering by hostname, group or enabled state. |
|
|
181
|
-
|
|
182
|
-
|
|
205
|
+
| `list_tags` | Find tag IDs for events, jobs and tickets. |
|
|
206
|
+
| `get_tag` | Read a tag's title, icon, notes and revision by exact ID. |
|
|
207
|
+
| `create_tag` | Create a tag with a title and optional ID, icon and notes. |
|
|
208
|
+
| `update_tag` | Update a tag by exact ID, with an optional revision check. |
|
|
209
|
+
| `delete_tag` | Delete a tag by exact ID. |
|
|
210
|
+
| `list_web_hooks` | Find existing Web Hooks by title. Returns IDs, titles and enabled status. |
|
|
211
|
+
| `get_web_hook` | Read a Web Hook's delivery settings and revision by exact ID. |
|
|
212
|
+
| `create_web_hook` | Save a Web Hook with a URL, HTTP method and optional request template. |
|
|
213
|
+
| `update_web_hook` | Update a Web Hook by exact ID, with an optional revision check. |
|
|
214
|
+
| `delete_web_hook` | Delete a Web Hook by exact ID. |
|
|
215
|
+
| `list_channels` | Find existing notification Channels by title. Returns IDs, titles and enabled status. |
|
|
216
|
+
| `get_channel` | Read a notification Channel's configuration and revision by exact ID. |
|
|
217
|
+
| `create_channel` | Create a notification Channel with optional recipients, a Web Hook or an event to run. |
|
|
218
|
+
| `update_channel` | Update a notification Channel by exact ID, with an optional revision check. |
|
|
219
|
+
| `delete_channel` | Delete a notification Channel by exact ID. |
|
|
220
|
+
|
|
221
|
+
Pages default to 25 rows, capped by `max_page_size`. Events, servers and lookup collections are paginated locally after fetching the authorized collection. xyOps paginates active jobs and job, alert and snapshot searches on the server. Each lookup collection has its own total and uses the requested offset/limit.
|
|
183
222
|
|
|
184
223
|
Updates, deletions and executions require exact IDs. Event creation requires an explicit `enabled` value. Ordinary events require category, plugin, targets and a server-selection algorithm. Workflows require a workflow object with nodes and connections. xyOps validates the full definition and permissions.
|
|
185
224
|
|
|
@@ -189,6 +228,8 @@ Event updates preserve omitted top-level fields. Supplied objects and arrays rep
|
|
|
189
228
|
|
|
190
229
|
### Job output
|
|
191
230
|
|
|
231
|
+
Use `list_active_jobs` to find job IDs for `get_job` or `tail_job_log`. Jobs are sorted by newest start time. Use `state` to narrow the list, for example `queued`, `active`, or `retry_delay`. The optional `event`, `category` and `server` filters take exact IDs. xyOps applies the caller's category and group restrictions before paging.
|
|
232
|
+
|
|
192
233
|
`get_job` includes structured output `data` and any console `output` stored inline with the job. Use the log tools when you need live console text or a completed log that was archived separately. All three tools are available in read-only mode and use the caller's API-key permissions. Download tokens and generated download URLs are not returned.
|
|
193
234
|
|
|
194
235
|
For a completed job, call `get_job_log` with `{"id":"JOB_ID"}`. The result includes `text`, the requested byte `offset`, a byte `next_offset`, and `truncated`. The default `max_bytes` is 32768 (32 KiB). If `truncated` is `true`, call again using the returned `next_offset`:
|
|
@@ -211,6 +252,18 @@ Only direct children are returned. A nested workflow appears as a child with `ty
|
|
|
211
252
|
|
|
212
253
|
All three tools accept `max_bytes` from 4 through 262144 (256 KiB). The overall `max_result_bytes` limit still applies, including JSON escaping and metadata. If a response exceeds it, reduce `max_bytes` or the workflow page `limit`.
|
|
213
254
|
|
|
255
|
+
### Tags and notification destinations
|
|
256
|
+
|
|
257
|
+
`list_tags`, `list_web_hooks` and `list_channels` accept a case-insensitive `title` filter and return summaries in ID order. Use the returned Web Hook and Channel IDs in event or alert actions.
|
|
258
|
+
|
|
259
|
+
Use `create_tag` with `{"tag":{"title":"Needs Review"}}`. This requires `create_tags`. xyOps generates the ID when you omit it, and the result includes the ID to use on events or tickets.
|
|
260
|
+
|
|
261
|
+
`create_web_hook` takes a `web_hook` object with `title`, `url` and an uppercase `method`. It also accepts optional `headers` as `{name, value}` objects and `body` as a template string. The URL, headers and body are write-only through MCP because they can contain credentials. `get_web_hook` returns the saved method and other delivery settings, along with the revision.
|
|
262
|
+
|
|
263
|
+
`create_channel` takes a `channel` object with `title` and optional recipients or actions. Use `users` for an array of usernames, `email` for a comma-separated list of addresses, and exact resource IDs for `web_hook` and `run_event`. `get_channel` returns those saved settings and the revision. New Web Hooks and Channels default to enabled. Set `enabled` to `false` when you want to configure one before using it in an action.
|
|
264
|
+
|
|
265
|
+
The update tools accept `id`, `changes` and an optional expected `revision`. The revision check runs before the write, so a concurrent edit can still land between the check and the write. Omitted fields are preserved. Supplied arrays replace the saved arrays, and an empty string clears an optional Channel link. Delete tools take the exact ID. xyOps enforces the caller's create, edit and delete privileges for each resource.
|
|
266
|
+
|
|
214
267
|
### Tickets
|
|
215
268
|
|
|
216
269
|
Create a ticket with `{"ticket":{"subject":"Backup failed","body":"Investigating the logs.","type":"issue"}}`. xyOps generates its ID, number and initial history. Ticket types and statuses follow your xyOps configuration, including custom values. This initial tool set supports text and metadata; file attachments, automatic job/alert templates and attached event definitions are not exposed.
|
|
@@ -221,6 +274,16 @@ Use `comment_ticket` with `{"id":"TICKET_ID","body":"The backup is working again
|
|
|
221
274
|
|
|
222
275
|
### Monitoring
|
|
223
276
|
|
|
277
|
+
Use the definition `list_*` tools to find exact IDs. They return paginated summaries and accept a case-insensitive `title` filter. `list_plugins` also accepts `type`, such as `monitor`. The corresponding `get_*` tools return the full definition by ID. Use `fields` to select properties while retaining the ID and revision.
|
|
278
|
+
|
|
279
|
+
Create tools take a named object (`plugin`, `monitor`, `alert` or `group`) and return a summary with the ID and revision. Set `enabled` explicitly when creating a plugin or alert. For a Monitor Plugin, set `type` to `monitor` and supply the `command`, optional `script`, output `format` and target `groups`. The default output format is `text`. Set `groups` on the plugin, monitor and alert to scope all three to the same servers.
|
|
280
|
+
|
|
281
|
+
Update tools take `id` and `changes`. Pass the `revision` from the get tool to check for an intervening edit before submitting the changes. xyOps increments these definitions' revisions when it saves them. Another edit can still land between the check and the write. Omitted fields keep their current values, and supplied arrays replace the saved arrays. Read the definition again for the new revision. Delete tools take the exact definition ID.
|
|
282
|
+
|
|
283
|
+
For a group with selected servers, create it with `{"group":{"id":"mail","title":"Mail servers"}}`. The default hostname pattern matches no servers. Use `list_servers` to find each target's ID and current groups, then call `set_server_groups` for each target with its complete list of group IDs, including `mail`. This switches those servers to manual group assignment and requires `update_servers`. For servers using automatic assignment, you can instead set `hostname_match` on the group to an anchored regex matching the intended hostnames.
|
|
284
|
+
|
|
285
|
+
Call `test_monitor` with `server`, `source` and `data_type` to get a `value` or `fail: true` for an unresolved result. Call `test_alert` with `server`, `expression` and `message` to get a boolean `result` and the rendered `message`. These calls evaluate against the server's latest saved data without saving definitions or firing alerts. They require `edit_monitors` and `edit_alerts` respectively. All definition and membership tools use the caller's API key and xyOps applies its normal privilege and group checks.
|
|
286
|
+
|
|
224
287
|
`search_alerts` accepts queries such as `active:true`, `server:SERVER_ID` or `start:>=today`. `search_snapshots` accepts queries such as `type:group`, `groups:GROUP_ID` or `source:alert`. Both support `query`, `offset`, `limit`, `sort_by` and `sort_dir` (`1` ascending, `-1` descending), defaulting to newest IDs first. xyOps applies the API key's resource restrictions. Snapshot search omits heavy nested details unless `verbose` is `true`; use small pages with verbose results to stay within the response size limit.
|
|
225
288
|
|
|
226
289
|
`list_servers` returns connected worker summaries and IDs, excluding offline servers and conductor peers. `hostname` matches a case-insensitive substring, `group` matches an exact group ID, and `enabled` filters the enabled flag.
|
|
@@ -231,7 +294,7 @@ API requests are not automatically retried. A lost connection after a mutation m
|
|
|
231
294
|
|
|
232
295
|
## Adding a tool
|
|
233
296
|
|
|
234
|
-
Every bundled `.js` file in `lib/mcp/tools/` exports
|
|
297
|
+
Every bundled `.js` file in `lib/mcp/tools/` exports one tool or an array of related tools. Each tool provides the following functions.
|
|
235
298
|
|
|
236
299
|
| Function | Contract |
|
|
237
300
|
| --- | --- |
|
package/lib/mcp/context.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// Shared SDK boundary. No terminal formatting, cached records, or global args.
|
|
2
|
-
const READ_APIS = new Set([
|
|
3
|
-
|
|
2
|
+
const READ_APIS = new Set([
|
|
3
|
+
'get_events', 'get_event', 'get_categories', 'get_job', 'get_active_jobs', 'search_jobs', 'tail_live_job_log',
|
|
4
|
+
'search_alerts', 'search_snapshots', 'get_active_servers',
|
|
5
|
+
'get_plugins', 'get_plugin', 'get_monitors', 'get_monitor', 'get_alerts', 'get_alert', 'get_groups', 'get_group',
|
|
6
|
+
'test_monitor', 'test_alert', 'get_tags', 'get_tag', 'get_web_hooks', 'get_web_hook', 'get_channels', 'get_channel'
|
|
7
|
+
]);
|
|
8
|
+
const WRITE_APIS = new Set([
|
|
9
|
+
'create_event', 'update_event', 'delete_event', 'run_event',
|
|
10
|
+
'create_ticket', 'update_ticket', 'delete_ticket', 'add_ticket_change', 'create_snapshot', 'create_group_snapshot',
|
|
11
|
+
'create_plugin', 'update_plugin', 'delete_plugin', 'create_monitor', 'update_monitor', 'delete_monitor',
|
|
12
|
+
'create_alert', 'update_alert', 'delete_alert', 'create_group', 'update_group', 'delete_group', 'update_server',
|
|
13
|
+
'create_tag', 'update_tag', 'delete_tag', 'create_web_hook', 'update_web_hook', 'delete_web_hook',
|
|
14
|
+
'create_channel', 'update_channel', 'delete_channel'
|
|
15
|
+
]);
|
|
4
16
|
|
|
5
17
|
function checkKeys(value) {
|
|
6
18
|
// Prevent prototype-bearing keys from reaching downstream merge helpers.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const S = require('./schemas.js');
|
|
2
|
+
|
|
3
|
+
module.exports = function definitionTools({ name, label, properties, required, createOnly, defaults, summaryFields, readFields }) {
|
|
4
|
+
const getAPI = 'get_' + name;
|
|
5
|
+
// For definitions with sensitive fields, use the same allowlist for field
|
|
6
|
+
// selection and the default response. A field selector cannot bypass it.
|
|
7
|
+
const fieldSelector = readFields ? { ...S.strings, items: { type: 'string', enum: readFields } } : S.strings;
|
|
8
|
+
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
describe: () => S.describe(getAPI, `Read a ${label} by exact ID. Use fields to select which properties to return.`, { id: S.id, fields: fieldSelector }, ['id']),
|
|
12
|
+
async run({ id, fields }, context) {
|
|
13
|
+
const data = await context.callAPI(getAPI, { id });
|
|
14
|
+
const record = readFields ? S.pick(data[name], readFields) : data[name];
|
|
15
|
+
return { [name]: fields ? S.pick(record, ['id', 'revision', ...fields]) : record };
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
describe: () => S.describe('create_' + name, `Create a ${label} and return a summary.`, {
|
|
20
|
+
[name]: S.input({ id: S.id, ...properties, ...createOnly }, required)
|
|
21
|
+
}, [name], false),
|
|
22
|
+
async run(args, context) {
|
|
23
|
+
const data = await context.callAPI('create_' + name, { ...defaults?.(args[name]), ...args[name] });
|
|
24
|
+
return { [name]: S.pick(data[name], summaryFields) };
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
describe: () => S.describe('update_' + name, `Update a ${label} by exact ID. Omitted fields are preserved and supplied arrays replace their saved values. Optionally check the revision before writing.`, {
|
|
29
|
+
id: S.id,
|
|
30
|
+
revision: { type: 'integer', minimum: 1, description: 'Expected revision from the get tool. Checked before the update request.' },
|
|
31
|
+
changes: { ...S.input(properties), minProperties: 1 }
|
|
32
|
+
}, ['id', 'changes'], false),
|
|
33
|
+
async run({ id, revision, changes }, context) {
|
|
34
|
+
// xyOps increments these revisions but has no atomic revision precondition.
|
|
35
|
+
// Check the caller's revision when supplied, then send only the patch.
|
|
36
|
+
if (revision !== undefined) {
|
|
37
|
+
const data = await context.callAPI(getAPI, { id });
|
|
38
|
+
if (data[name].revision !== revision) throw new Error(`Revision mismatch for ${label} ${id}. Read the current definition before updating.`);
|
|
39
|
+
}
|
|
40
|
+
await context.callAPI('update_' + name, { ...changes, id });
|
|
41
|
+
return { id, updated: true };
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
describe: () => S.describe('delete_' + name, `Delete a ${label} by exact ID.`, { id: S.id }, ['id'], false),
|
|
46
|
+
async run({ id }, context) {
|
|
47
|
+
await context.callAPI('delete_' + name, { id });
|
|
48
|
+
return { id, deleted: true };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
};
|
package/lib/mcp/registry.js
CHANGED
|
@@ -7,21 +7,24 @@ module.exports = function loadTools(directory = Path.join(__dirname, 'tools')) {
|
|
|
7
7
|
const tools = new Map();
|
|
8
8
|
|
|
9
9
|
for (const file of fs.readdirSync(directory).filter(file => file.endsWith('.js')).sort()) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const exported = require(Path.join(directory, file));
|
|
11
|
+
// Related operations can share a module, but each still publishes its own schema.
|
|
12
|
+
for (const tool of [].concat(exported)) {
|
|
13
|
+
if (typeof tool?.describe !== 'function' || typeof tool.run !== 'function') {
|
|
14
|
+
throw new Error('Invalid MCP tool exports: ' + file);
|
|
15
|
+
}
|
|
16
|
+
const description = tool.describe();
|
|
17
|
+
if (!description || !/^[a-z][a-z0-9_]*$/.test(description.name) || !description.description ||
|
|
18
|
+
!description.inputSchema || description.inputSchema.type !== 'object' ||
|
|
19
|
+
typeof description.annotations?.readOnlyHint !== 'boolean') {
|
|
20
|
+
throw new Error('Invalid MCP tool description: ' + file);
|
|
21
|
+
}
|
|
22
|
+
if (tools.has(description.name)) throw new Error('Duplicate MCP tool: ' + description.name);
|
|
23
|
+
|
|
24
|
+
// Compile once, rather than rebuilding validators for each HTTP request.
|
|
25
|
+
const inputSchema = fromJsonSchema(description.inputSchema);
|
|
26
|
+
tools.set(description.name, { ...tool, description, inputSchema });
|
|
13
27
|
}
|
|
14
|
-
const description = tool.describe();
|
|
15
|
-
if (!description || !/^[a-z][a-z0-9_]*$/.test(description.name) || !description.description ||
|
|
16
|
-
!description.inputSchema || description.inputSchema.type !== 'object' ||
|
|
17
|
-
typeof description.annotations?.readOnlyHint !== 'boolean') {
|
|
18
|
-
throw new Error('Invalid MCP tool description: ' + file);
|
|
19
|
-
}
|
|
20
|
-
if (tools.has(description.name)) throw new Error('Duplicate MCP tool: ' + description.name);
|
|
21
|
-
|
|
22
|
-
// Compile once, rather than rebuilding validators for each HTTP request.
|
|
23
|
-
const inputSchema = fromJsonSchema(description.inputSchema);
|
|
24
|
-
tools.set(description.name, { ...tool, description, inputSchema });
|
|
25
28
|
}
|
|
26
29
|
return tools;
|
|
27
30
|
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Core definition tools use the same schemas and API boundary as events.
|
|
2
|
+
const S = require('../schemas.js');
|
|
3
|
+
const definitionTools = require('../definition-tools.js');
|
|
4
|
+
|
|
5
|
+
const nonempty = { ...S.text, pattern: '\\S' };
|
|
6
|
+
const common = { title: nonempty, icon: S.text, notes: S.text };
|
|
7
|
+
const bool = { type: 'boolean' };
|
|
8
|
+
const groups = { type: 'array', items: S.id, uniqueItems: true, description: 'Exact server group IDs. An empty list applies to all groups.' };
|
|
9
|
+
const pluginType = { type: 'string', enum: ['event', 'monitor', 'action', 'scheduler'] };
|
|
10
|
+
const dataType = { type: 'string', enum: ['integer', 'float', 'bytes', 'seconds', 'milliseconds'] };
|
|
11
|
+
const monitorExpression = {
|
|
12
|
+
source: { ...nonempty, description: 'JEXL expression evaluated against server monitoring data.' },
|
|
13
|
+
data_type: dataType,
|
|
14
|
+
data_match: { ...S.text, description: 'Optional regular expression to extract a numeric value from text.' }
|
|
15
|
+
};
|
|
16
|
+
const alertExpression = {
|
|
17
|
+
expression: { ...nonempty, description: 'JEXL expression that evaluates to true when the alert should fire.' },
|
|
18
|
+
message: { ...nonempty, description: 'Alert message template, with optional {{expression}} substitutions.' }
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function monitoringDefinitionTools({ summary, ...definition }) {
|
|
22
|
+
const { name, label } = definition;
|
|
23
|
+
const fields = ['id', 'title', 'revision', ...summary];
|
|
24
|
+
const pluginFilter = name === 'plugin' ? { type: pluginType } : {};
|
|
25
|
+
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
describe: () => S.describe('list_' + name + 's', `List ${label} summaries. Title matches a case-insensitive substring.`, {
|
|
29
|
+
...S.pagination, title: S.text, ...pluginFilter
|
|
30
|
+
}),
|
|
31
|
+
async run(args, context) {
|
|
32
|
+
// Page the collection returned for this key, keeping large definitions out of list results.
|
|
33
|
+
const data = await context.callAPI('get_' + name + 's');
|
|
34
|
+
const rows = data.rows.filter(row =>
|
|
35
|
+
(!args.title || row.title.toLowerCase().includes(args.title.toLowerCase())) &&
|
|
36
|
+
(!args.type || row.type === args.type)
|
|
37
|
+
).sort((a, b) => a.id.localeCompare(b.id));
|
|
38
|
+
const { offset, limit } = S.page(args, context);
|
|
39
|
+
return { rows: rows.slice(offset, offset + limit).map(row => S.pick(row, fields)), total: rows.length, offset, limit };
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
...definitionTools({ ...definition, summaryFields: fields })
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = [
|
|
47
|
+
...monitoringDefinitionTools({
|
|
48
|
+
name: 'plugin', label: 'plugin', summary: ['type', 'enabled', 'groups'],
|
|
49
|
+
properties: {
|
|
50
|
+
...common, enabled: bool, command: nonempty, script: S.text,
|
|
51
|
+
params: { ...S.objects, description: 'Parameter definitions for non-monitor plugins.' },
|
|
52
|
+
groups: { ...groups, description: 'Server group IDs for a monitor plugin. An empty list applies to all groups.' },
|
|
53
|
+
format: { type: 'string', enum: ['text', 'json', 'xml'], description: 'Monitor plugin output format. Defaults to text on creation.' },
|
|
54
|
+
quick: { ...bool, description: 'Also run this monitor plugin every second with QuickMon.' },
|
|
55
|
+
uid: { type: ['string', 'integer'] }, gid: { type: ['string', 'integer'] },
|
|
56
|
+
kill: { type: 'string', enum: ['none', 'parent', 'all'] }, runner: bool
|
|
57
|
+
},
|
|
58
|
+
createOnly: { type: pluginType }, required: ['title', 'type', 'command', 'enabled'],
|
|
59
|
+
defaults: plugin => plugin.type === 'monitor' ? { groups: [], format: 'text', quick: false } : { params: [] }
|
|
60
|
+
}),
|
|
61
|
+
...monitoringDefinitionTools({
|
|
62
|
+
name: 'monitor', label: 'monitor', summary: ['display', 'data_type', 'groups'],
|
|
63
|
+
properties: {
|
|
64
|
+
...common, ...monitorExpression, groups, display: bool, suffix: S.text,
|
|
65
|
+
min_vert_scale: { type: 'number', minimum: 0 }, delta: bool, divide_by_delta: bool,
|
|
66
|
+
delta_min_value: { anyOf: [{ type: 'number' }, { const: false }] }
|
|
67
|
+
},
|
|
68
|
+
required: ['title', 'source', 'data_type'], defaults: () => ({ groups: [], display: true })
|
|
69
|
+
}),
|
|
70
|
+
...monitoringDefinitionTools({
|
|
71
|
+
name: 'alert', label: 'alert definition', summary: ['enabled', 'groups', 'monitor_id'],
|
|
72
|
+
properties: {
|
|
73
|
+
...common, ...alertExpression, groups, enabled: bool, actions: S.objects,
|
|
74
|
+
monitor_id: { ...S.text, pattern: '^[a-z0-9_]*$', description: 'Exact monitor ID, or empty to clear the link.' },
|
|
75
|
+
samples: { type: 'integer', minimum: 1 }, exclusive_actions: bool, limit_jobs: bool, abort_jobs: bool
|
|
76
|
+
},
|
|
77
|
+
required: ['title', 'expression', 'message', 'enabled'], defaults: () => ({ groups: [], actions: [], samples: 1 })
|
|
78
|
+
}),
|
|
79
|
+
...monitoringDefinitionTools({
|
|
80
|
+
name: 'group', label: 'server group', summary: ['hostname_match'],
|
|
81
|
+
properties: {
|
|
82
|
+
...common, hostname_match: { ...nonempty, description: 'Regex for automatic hostname assignment. Use (?!) for manual membership only.' },
|
|
83
|
+
alert_actions: S.objects, max_jobs_per_server: { type: 'integer', minimum: 0 }
|
|
84
|
+
},
|
|
85
|
+
required: ['title'], defaults: () => ({ hostname_match: '(?!)' })
|
|
86
|
+
}),
|
|
87
|
+
{
|
|
88
|
+
describe: () => S.describe('test_monitor', 'Evaluate a monitor expression against the latest saved sample for one server. Requires edit_monitors.', {
|
|
89
|
+
server: S.id, ...monitorExpression
|
|
90
|
+
}, ['server', 'source', 'data_type']),
|
|
91
|
+
async run(args, context) {
|
|
92
|
+
return S.pick(await context.callAPI('test_monitor', args), ['value', 'fail']);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
describe: () => S.describe('test_alert', 'Evaluate an alert expression and render its message against the latest saved sample for one server. Requires edit_alerts.', {
|
|
97
|
+
server: S.id, ...alertExpression
|
|
98
|
+
}, ['server', 'expression', 'message']),
|
|
99
|
+
async run(args, context) {
|
|
100
|
+
return S.pick(await context.callAPI('test_alert', args), ['result', 'message']);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
describe: () => S.describe('set_server_groups', 'Set manual group membership for one exact server ID. Replaces all group memberships and disables automatic hostname assignment. Requires update_servers.', {
|
|
105
|
+
id: S.id, groups: { type: 'array', items: S.id, uniqueItems: true, description: 'Complete list of group IDs to assign to this server.' }
|
|
106
|
+
}, ['id', 'groups'], false),
|
|
107
|
+
async run({ id, groups }, context) {
|
|
108
|
+
await context.callAPI('update_server', { id, groups, autoGroup: false });
|
|
109
|
+
return { id, groups, autoGroup: false };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const S = require('../schemas.js');
|
|
2
|
+
|
|
3
|
+
const filters = {
|
|
4
|
+
event: S.id, category: S.id, server: S.id,
|
|
5
|
+
state: { type: 'string', enum: ['queued', 'start_delay', 'retry_delay', 'ready', 'starting', 'active', 'finishing'] }
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
exports.describe = () => S.describe('list_active_jobs', 'List active jobs, including queued and delayed jobs, newest start time first. Filter by state or exact event, category and server IDs. xyOps applies the API key\'s category and group restrictions.', {
|
|
9
|
+
...S.pagination, ...filters
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
exports.run = async function(args, context) {
|
|
13
|
+
const { offset, limit } = S.page(args, context);
|
|
14
|
+
// Let xyOps apply filters and permissions before paging. Pick summary fields
|
|
15
|
+
// because active records also hold scripts, environment variables and job data.
|
|
16
|
+
const data = await context.callAPI('get_active_jobs', { ...S.pick(args, Object.keys(filters)), offset, limit });
|
|
17
|
+
const fields = ['id', 'event', 'title', 'type', 'category', 'server', 'state', 'started', 'progress', 'position', 'until'];
|
|
18
|
+
return { rows: data.rows.map(job => S.pick(job, fields)), total: data.list.length, offset, limit };
|
|
19
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const S = require('../schemas.js');
|
|
2
|
+
const definitionTools = require('../definition-tools.js');
|
|
3
|
+
|
|
4
|
+
const tagFields = ['id', 'title', 'icon'];
|
|
5
|
+
const destinationFields = ['id', 'title', 'enabled'];
|
|
6
|
+
const common = { title: { ...S.text, pattern: '\\S' }, icon: S.text, notes: S.text };
|
|
7
|
+
const bool = { type: 'boolean' };
|
|
8
|
+
const nonnegative = { type: 'integer', minimum: 0 };
|
|
9
|
+
const optionalId = { ...S.text, pattern: '^[a-z0-9_]*$', description: 'Exact xyOps ID, or an empty string to clear the link.' };
|
|
10
|
+
|
|
11
|
+
const channelProperties = {
|
|
12
|
+
...common, enabled: bool,
|
|
13
|
+
users: { type: 'array', items: { ...S.text, pattern: '^\\S+$' }, description: 'Subscribed usernames. Replaces the entire list on update.' },
|
|
14
|
+
email: { ...S.text, description: 'Comma-separated email addresses, or an empty string to clear them.' },
|
|
15
|
+
web_hook: optionalId, run_event: optionalId,
|
|
16
|
+
sound: { ...S.text, pattern: '^(?:[a-zA-Z0-9_.-]+\\.[mM][pP]3)?$', description: 'MP3 filename, or an empty string to clear it.' },
|
|
17
|
+
max_per_day: { ...nonnegative, description: 'Daily notification limit. Use 0 for unlimited.' }
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const webHookProperties = {
|
|
21
|
+
...common, enabled: bool,
|
|
22
|
+
url: { ...S.text, pattern: '^(?:[hH][tT][tT][pP][sS]?://\\S|\\{\\{)', description: 'HTTP(S) URL or an xyOps URL template.' },
|
|
23
|
+
method: { ...S.text, pattern: '^[A-Z]+$', description: 'HTTP method in uppercase, such as GET or POST.' },
|
|
24
|
+
headers: {
|
|
25
|
+
type: 'array', description: 'HTTP request headers. Replaces the entire list on update.',
|
|
26
|
+
items: S.input({
|
|
27
|
+
name: { ...S.text, pattern: "^[A-Za-z0-9!#$%&'*+.^_`|~-]+$" },
|
|
28
|
+
value: { ...S.text, pattern: '^[\\t\\x20-\\x7E\\x80-\\xFF]*$' }
|
|
29
|
+
}, ['name', 'value'])
|
|
30
|
+
},
|
|
31
|
+
body: { ...S.text, description: 'Request body template, or an empty string to clear it.' },
|
|
32
|
+
timeout: { ...nonnegative, description: 'Request timeout in seconds.' },
|
|
33
|
+
retries: { ...nonnegative, maximum: 999 }, follow: bool, ssl_cert_bypass: bool,
|
|
34
|
+
max_per_day: { ...nonnegative, maximum: 9999999, description: 'Daily request limit. Use 0 for unlimited.' }
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function listTool(collection, description, fields) {
|
|
38
|
+
return {
|
|
39
|
+
describe: () => S.describe('list_' + collection, description + ' Title matches a case-insensitive substring.', { ...S.pagination, title: S.text }),
|
|
40
|
+
async run(args, context) {
|
|
41
|
+
const { rows } = await context.callAPI('get_' + collection);
|
|
42
|
+
const title = args.title?.toLowerCase();
|
|
43
|
+
const matches = rows.filter(row => !title || (row.title || '').toLowerCase().includes(title))
|
|
44
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
45
|
+
const { offset, limit } = S.page(args, context);
|
|
46
|
+
|
|
47
|
+
// The API returns full records. Only expose the fields needed for discovery,
|
|
48
|
+
// since destinations can contain credentials and recipient information.
|
|
49
|
+
return { rows: matches.slice(offset, offset + limit).map(row => S.pick(row, fields)), total: matches.length, offset, limit };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = [
|
|
55
|
+
listTool('tags', 'Find tag IDs for events, jobs and tickets.', tagFields),
|
|
56
|
+
listTool('web_hooks', 'Find existing Web Hook IDs for actions. Returns ID, title and enabled status.', destinationFields),
|
|
57
|
+
listTool('channels', 'Find existing notification Channel IDs for actions. Returns ID, title and enabled status.', destinationFields),
|
|
58
|
+
...definitionTools({
|
|
59
|
+
name: 'tag', label: 'tag', properties: common, required: ['title'],
|
|
60
|
+
summaryFields: tagFields, readFields: [...tagFields, 'notes', 'revision']
|
|
61
|
+
}),
|
|
62
|
+
...definitionTools({
|
|
63
|
+
name: 'web_hook', label: 'Web Hook', properties: webHookProperties,
|
|
64
|
+
required: ['title', 'url', 'method'], summaryFields: [...destinationFields, 'revision'],
|
|
65
|
+
// URLs, headers and bodies can contain credentials. Accept them on writes
|
|
66
|
+
// while keeping them out of both create responses and detail responses.
|
|
67
|
+
readFields: ['id', 'title', 'enabled', 'icon', 'notes', 'revision', 'method', 'timeout', 'retries', 'follow', 'ssl_cert_bypass', 'max_per_day']
|
|
68
|
+
}),
|
|
69
|
+
...definitionTools({
|
|
70
|
+
name: 'channel', label: 'notification Channel', properties: channelProperties,
|
|
71
|
+
required: ['title'], defaults: () => ({ enabled: true, users: [] }),
|
|
72
|
+
summaryFields: [...destinationFields, 'revision'], readFields: ['id', 'revision', ...Object.keys(channelProperties)]
|
|
73
|
+
})
|
|
74
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixlcore/xycli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "A complete command-line interface for the xyOps workflow automation system.",
|
|
5
5
|
"author": "Joseph Huckaby <jhuckaby@pixlcore.com>",
|
|
6
6
|
"homepage": "https://github.com/pixlcore/xycli",
|
|
@@ -25,7 +25,7 @@ test('HTTP advertises a static tool catalog for modern and legacy clients', asyn
|
|
|
25
25
|
}, { headers });
|
|
26
26
|
for (const reply of [modern, legacy]) assert.deepEqual(reply.result.capabilities.tools, { listChanged: false });
|
|
27
27
|
const listing = await httpRPC(url, 'tools/list', {}, { headers, modern: true });
|
|
28
|
-
assert.equal(listing.result.tools.length, read_only ?
|
|
28
|
+
assert.equal(listing.result.tools.length, read_only ? 28 : tools.size);
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -141,7 +141,7 @@ test('HTTP serves both protocol generations, validates calls and rejects unautho
|
|
|
141
141
|
|
|
142
142
|
for (const modern of [false, true]) {
|
|
143
143
|
const listing = await httpRPC(url, 'tools/list', {}, { headers, modern });
|
|
144
|
-
assert.equal(listing.result.tools.length,
|
|
144
|
+
assert.equal(listing.result.tools.length, 28);
|
|
145
145
|
assert.ok(listing.result.tools.every(tool => tool.annotations.readOnlyHint));
|
|
146
146
|
const response = await httpRPC(url, 'tools/call', { name: 'get_event', arguments: { id: 'e1' } }, { headers, modern });
|
|
147
147
|
assert.equal(response.result.structuredContent.event.id, 'e1');
|
|
@@ -291,7 +291,13 @@ test('new HTTP mutations use each client key and read-only mode rejects every wr
|
|
|
291
291
|
const readonlyURL = 'http://127.0.0.1:' + readonlyService.address.port + '/mcp';
|
|
292
292
|
const headers = { Authorization: 'Bearer readonly-key' };
|
|
293
293
|
const listing = await httpRPC(readonlyURL, 'tools/list', {}, { headers });
|
|
294
|
-
assert.deepEqual(listing.result.tools.map(tool => tool.name).sort(), [
|
|
294
|
+
assert.deepEqual(listing.result.tools.map(tool => tool.name).sort(), [
|
|
295
|
+
'get_alert', 'get_channel', 'get_event', 'get_event_options', 'get_group', 'get_job', 'get_job_log',
|
|
296
|
+
'get_monitor', 'get_plugin', 'get_tag', 'get_web_hook', 'get_workflow_job_outputs', 'list_active_jobs', 'list_alerts',
|
|
297
|
+
'list_channels', 'list_events', 'list_groups', 'list_monitors', 'list_plugins', 'list_servers',
|
|
298
|
+
'list_tags', 'list_web_hooks', 'search_alerts', 'search_jobs', 'search_snapshots',
|
|
299
|
+
'tail_job_log', 'test_alert', 'test_monitor'
|
|
300
|
+
]);
|
|
295
301
|
for (const tool of tools.values()) {
|
|
296
302
|
if (tool.description.annotations.readOnlyHint) continue;
|
|
297
303
|
const reply = await httpRPC(readonlyURL, 'tools/call', { name: tool.description.name, arguments: {} }, { headers });
|
|
@@ -37,7 +37,7 @@ test('STDIO uses the real CLI and SDK with protocol-only stdout and clean EOF',
|
|
|
37
37
|
const client = stdioClient(t, { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_RETRIES: '4' }, ['mcp', 'stdio', '--verbose', '--debug', '--read-only']);
|
|
38
38
|
assert.deepEqual((await client.initialize()).result.capabilities.tools, { listChanged: false });
|
|
39
39
|
const listing = await client.request('tools/list');
|
|
40
|
-
assert.equal(listing.result.tools.length,
|
|
40
|
+
assert.equal(listing.result.tools.length, 28);
|
|
41
41
|
assert.equal((await client.call('get_event', { id: 'fixture' })).result.structuredContent.event.revision, 2);
|
|
42
42
|
assert.equal(calls, 1);
|
|
43
43
|
const rejected = await client.call('run_event', { id: 'fixture' });
|
|
@@ -104,7 +104,7 @@ for (const { host, urlHost } of [{ host: '127.0.0.1', urlHost: '127.0.0.1' }, {
|
|
|
104
104
|
const listing = await httpRPC(url, 'tools/list', {}, {
|
|
105
105
|
modern: true, headers: { Authorization: 'Bearer fixture-token' }
|
|
106
106
|
});
|
|
107
|
-
assert.equal(listing.result.tools.length,
|
|
107
|
+
assert.equal(listing.result.tools.length, 28);
|
|
108
108
|
assert.equal((await fetch(url)).status, 401);
|
|
109
109
|
// Binding IPv6 must not weaken the Host allowlist.
|
|
110
110
|
const rejectedHost = await new Promise((resolve, reject) => {
|
|
@@ -172,7 +172,7 @@ test('ticket and monitoring tools use real SDK routes and validated STDIO inputs
|
|
|
172
172
|
const client = stdioClient(t, { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: 'fixture-key', XYOPS_MCP: '{}' });
|
|
173
173
|
await client.initialize();
|
|
174
174
|
const listing = await client.request('tools/list');
|
|
175
|
-
assert.equal(listing.result.tools.length,
|
|
175
|
+
assert.equal(listing.result.tools.length, 59);
|
|
176
176
|
const invoke = async (name, args) => {
|
|
177
177
|
const reply = await client.call(name, args);
|
|
178
178
|
assert.ok(reply.result && !reply.result.isError, JSON.stringify(reply));
|
|
@@ -212,6 +212,219 @@ test('ticket and monitoring tools use real SDK routes and validated STDIO inputs
|
|
|
212
212
|
assert.equal((await client.exit)[0], 0);
|
|
213
213
|
});
|
|
214
214
|
|
|
215
|
+
test('definition tools use exact IDs and the caller key through the real SDK', async t => {
|
|
216
|
+
const definitions = {
|
|
217
|
+
plugin: { title: 'Queue collector', type: 'monitor', enabled: false, command: '/bin/sh', script: 'echo 0', groups: ['mail'] },
|
|
218
|
+
monitor: { title: 'Queue length', source: 'commands.queue', data_type: 'integer', groups: ['mail'] },
|
|
219
|
+
alert: { title: 'Queue too long', expression: 'monitors.queue > 10', message: 'Queue is too long', enabled: false, groups: ['mail'] },
|
|
220
|
+
group: { title: 'Mail servers' },
|
|
221
|
+
tag: { title: 'Needs Review', icon: 'flag' },
|
|
222
|
+
web_hook: {
|
|
223
|
+
title: 'Operations Web Hook', enabled: false, method: 'POST', url: 'https://example.test/private-token',
|
|
224
|
+
headers: [{ name: 'Authorization', value: 'private-header' }], body: 'private-body'
|
|
225
|
+
},
|
|
226
|
+
channel: { title: 'Operations Channel', users: ['operator'], email: 'ops@example.test', web_hook: 'ops_hook' }
|
|
227
|
+
};
|
|
228
|
+
const requests = [];
|
|
229
|
+
const backend = http.createServer(async (request, response) => {
|
|
230
|
+
let body = '';
|
|
231
|
+
for await (const chunk of request) body += chunk;
|
|
232
|
+
const url = new URL(request.url, 'http://fixture');
|
|
233
|
+
const name = url.pathname.split('/')[3];
|
|
234
|
+
const params = body ? JSON.parse(body) : Object.fromEntries(url.searchParams);
|
|
235
|
+
const key = request.headers['x-api-key'];
|
|
236
|
+
requests.push({ name, params, key });
|
|
237
|
+
const split = name.indexOf('_');
|
|
238
|
+
const verb = name.slice(0, split);
|
|
239
|
+
const kind = name.slice(split + 1);
|
|
240
|
+
const record = { ...definitions[kind.replace(/s$/, '')], id: params.id || 'exact_id', revision: 2, notes: 'Full definition' };
|
|
241
|
+
let result = { code: 0 };
|
|
242
|
+
if (key === 'restricted-key' && verb !== 'get') {
|
|
243
|
+
response.statusCode = 403;
|
|
244
|
+
result = { code: 'access', description: 'Permission denied' };
|
|
245
|
+
}
|
|
246
|
+
else if (name === 'test_monitor') result.value = 0;
|
|
247
|
+
else if (name === 'test_alert') Object.assign(result, { result: false, message: params.message });
|
|
248
|
+
else if (verb === 'get' && kind.endsWith('s')) result.rows = [record, { id: 'other_id', title: 'Other' }];
|
|
249
|
+
else if (verb === 'get' || verb === 'create') result[kind] = record;
|
|
250
|
+
response.setHeader('Content-Type', 'application/json');
|
|
251
|
+
response.end(JSON.stringify(result));
|
|
252
|
+
});
|
|
253
|
+
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
254
|
+
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
255
|
+
const connect = async key => {
|
|
256
|
+
const client = stdioClient(t, { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_API_KEY: key, XYOPS_MCP: '{}' });
|
|
257
|
+
await client.initialize();
|
|
258
|
+
return client;
|
|
259
|
+
};
|
|
260
|
+
const client = await connect('editor-key');
|
|
261
|
+
const restricted = await connect('restricted-key');
|
|
262
|
+
const invoke = async (name, args) => {
|
|
263
|
+
const reply = await client.call(name, args);
|
|
264
|
+
assert.ok(reply.result && !reply.result.isError, JSON.stringify(reply));
|
|
265
|
+
assert.deepEqual(JSON.parse(reply.result.content[0].text), reply.result.structuredContent);
|
|
266
|
+
return reply.result.structuredContent;
|
|
267
|
+
};
|
|
268
|
+
const denied = async (name, args) => {
|
|
269
|
+
const { result } = await restricted.call(name, args);
|
|
270
|
+
assert.equal(result.isError, true, name);
|
|
271
|
+
assert.equal(result.content[0].text, 'Permission denied');
|
|
272
|
+
assert.equal(requests.at(-1).key, 'restricted-key');
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
for (const [kind, definition] of Object.entries(definitions)) {
|
|
276
|
+
const id = 'exact_id';
|
|
277
|
+
const listing = await invoke('list_' + kind + 's', { title: definition.title.toUpperCase(), limit: 1 });
|
|
278
|
+
assert.equal(listing.total, 1);
|
|
279
|
+
assert.equal(listing.rows[0].id, id);
|
|
280
|
+
assert.ok(!('notes' in listing.rows[0]));
|
|
281
|
+
const read = await invoke('get_' + kind, { id, fields: ['notes'] });
|
|
282
|
+
assert.deepEqual(read[kind], { id, revision: 2, notes: 'Full definition' });
|
|
283
|
+
const create = { [kind]: definition };
|
|
284
|
+
const created = await invoke('create_' + kind, create);
|
|
285
|
+
assert.equal(created[kind].id, id);
|
|
286
|
+
assert.equal(requests.at(-1).key, 'editor-key');
|
|
287
|
+
if (kind === 'plugin') assert.deepEqual(requests.at(-1).params, { format: 'text', quick: false, ...definition });
|
|
288
|
+
if (kind === 'group') assert.equal(requests.at(-1).params.hostname_match, '(?!)');
|
|
289
|
+
if (kind === 'channel') assert.deepEqual(requests.at(-1).params, { enabled: true, ...definition });
|
|
290
|
+
if (kind === 'web_hook') {
|
|
291
|
+
assert.deepEqual(requests.at(-1).params, definition);
|
|
292
|
+
assert.deepEqual(created.web_hook, { id, revision: 2, title: definition.title, enabled: false });
|
|
293
|
+
assert.deepEqual(await invoke('get_web_hook', { id }), {
|
|
294
|
+
web_hook: { id, revision: 2, title: definition.title, enabled: false, notes: 'Full definition', method: 'POST' }
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
await denied('create_' + kind, create);
|
|
298
|
+
|
|
299
|
+
const update = 'update_' + kind;
|
|
300
|
+
const remove = 'delete_' + kind;
|
|
301
|
+
let changes = { notes: '' };
|
|
302
|
+
if (kind === 'web_hook') changes = { headers: [], body: '' };
|
|
303
|
+
if (kind === 'channel') changes = { users: [], email: '', web_hook: '', run_event: '', enabled: false };
|
|
304
|
+
const stale = await client.call(update, { id, revision: 1, changes });
|
|
305
|
+
assert.equal(stale.result.isError, true);
|
|
306
|
+
assert.match(stale.result.content[0].text, /Revision mismatch/);
|
|
307
|
+
assert.equal(requests.at(-1).name, 'get_' + kind);
|
|
308
|
+
assert.deepEqual(await invoke(update, { id, revision: 2, changes }), { id, updated: true });
|
|
309
|
+
assert.deepEqual(requests.at(-1), { name: update, params: { id, ...changes }, key: 'editor-key' });
|
|
310
|
+
await denied(update, { id, revision: 2, changes });
|
|
311
|
+
assert.deepEqual(requests.at(-1).params, { id, ...changes });
|
|
312
|
+
assert.deepEqual(await invoke(remove, { id }), { id, deleted: true });
|
|
313
|
+
assert.deepEqual(requests.at(-1), { name: remove, params: { id }, key: 'editor-key' });
|
|
314
|
+
await denied(remove, { id });
|
|
315
|
+
assert.deepEqual(requests.at(-1).params, { id });
|
|
316
|
+
|
|
317
|
+
// Invalid selectors and attempts to replace the ID inside a patch never reach xyOps.
|
|
318
|
+
const count = requests.length;
|
|
319
|
+
for (const [name, args] of [[update, { id, changes: { id: 'other_id', ...changes } }], [remove, { id: 'Display Title' }]]) {
|
|
320
|
+
const reply = await client.call(name, args);
|
|
321
|
+
assert.ok(reply.error || reply.result.isError, name);
|
|
322
|
+
}
|
|
323
|
+
assert.equal(requests.length, count);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const count = requests.length;
|
|
327
|
+
for (const [name, args] of [
|
|
328
|
+
['get_web_hook', { id: 'exact_id', fields: ['url', 'headers', 'body'] }],
|
|
329
|
+
['update_web_hook', { id: 'exact_id', changes: { headers: [{ name: 'Bad Name', value: 'test' }] } }],
|
|
330
|
+
['update_web_hook', { id: 'exact_id', changes: { url: 'file:///test' } }],
|
|
331
|
+
['update_channel', { id: 'exact_id', changes: { users: 'operator' } }]
|
|
332
|
+
]) {
|
|
333
|
+
const reply = await client.call(name, args);
|
|
334
|
+
assert.ok(reply.error || reply.result.isError, name);
|
|
335
|
+
}
|
|
336
|
+
assert.equal(requests.length, count);
|
|
337
|
+
|
|
338
|
+
const assignment = { id: 'server1', groups: ['existing', 'mail'] };
|
|
339
|
+
await invoke('set_server_groups', assignment);
|
|
340
|
+
assert.deepEqual(requests.at(-1), { name: 'update_server', params: { ...assignment, autoGroup: false }, key: 'editor-key' });
|
|
341
|
+
await denied('set_server_groups', assignment);
|
|
342
|
+
for (const [name, args, expected] of [
|
|
343
|
+
['test_monitor', { server: 'server1', source: 'commands.queue', data_type: 'integer' }, { value: 0 }],
|
|
344
|
+
['test_alert', { server: 'server1', expression: 'monitors.queue > 10', message: 'Queue is too long' }, { result: false, message: 'Queue is too long' }]
|
|
345
|
+
]) {
|
|
346
|
+
assert.deepEqual(await invoke(name, args), expected);
|
|
347
|
+
assert.deepEqual(requests.at(-1), { name, params: args, key: 'editor-key' });
|
|
348
|
+
await denied(name, args);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test('lookup tools project safe summaries, page active jobs upstream and respect tag creation privileges', async t => {
|
|
353
|
+
const requests = [];
|
|
354
|
+
const job = { id: 'j1', event: 'e1', category: 'c1', state: 'queued', position: 2 };
|
|
355
|
+
const rows = {
|
|
356
|
+
get_tags: [{ id: 'urgent', title: 'Urgent', icon: 'flag', username: 'admin' }, { id: 'normal', title: 'Normal' }],
|
|
357
|
+
get_web_hooks: [{ id: 'hook1', title: 'Alerts Hook', enabled: true, url: 'https://example.test/token', headers: [{ name: 'Authorization', value: 'private' }], body: 'private body' }],
|
|
358
|
+
get_channels: [{ id: 'channel1', title: 'Ops Alerts', enabled: false, email: ['private@example.test'], users: ['private'], web_hook: 'hook1', run_event: 'e1' }],
|
|
359
|
+
get_active_jobs: [{ ...job, params: { password: 'private' }, env: { TOKEN: 'private' }, log_file: 'internal', secrets: ['private'] }]
|
|
360
|
+
};
|
|
361
|
+
const backend = http.createServer(async (request, response) => {
|
|
362
|
+
let body = '';
|
|
363
|
+
for await (const chunk of request) body += chunk;
|
|
364
|
+
const url = new URL(request.url, 'http://fixture');
|
|
365
|
+
const path = url.pathname;
|
|
366
|
+
const name = path.split('/')[3];
|
|
367
|
+
const params = body ? JSON.parse(body) : Object.fromEntries(url.searchParams);
|
|
368
|
+
const key = request.headers['x-api-key'];
|
|
369
|
+
requests.push({ path, method: request.method, params, key });
|
|
370
|
+
let result;
|
|
371
|
+
if (name === 'create_tag' && key === 'editor-key') result = { code: 0, tag: { ...params, id: params.id || 'generated_tag', username: 'admin' } };
|
|
372
|
+
else if (name === 'create_tag') {
|
|
373
|
+
response.statusCode = 403;
|
|
374
|
+
result = { code: 'access', description: 'Permission denied' };
|
|
375
|
+
}
|
|
376
|
+
else result = { code: 0, rows: rows[name], list: { length: name === 'get_active_jobs' ? 7 : rows[name].length } };
|
|
377
|
+
response.setHeader('Content-Type', 'application/json');
|
|
378
|
+
response.end(JSON.stringify(result));
|
|
379
|
+
});
|
|
380
|
+
await new Promise(resolve => backend.listen(0, '127.0.0.1', resolve));
|
|
381
|
+
t.after(() => new Promise(resolve => { backend.close(resolve); backend.closeAllConnections(); }));
|
|
382
|
+
const env = { XYOPS_BASE_URL: 'http://127.0.0.1:' + backend.address().port, XYOPS_MCP: '{"max_page_size":2}' };
|
|
383
|
+
const client = stdioClient(t, { ...env, XYOPS_API_KEY: 'editor-key' });
|
|
384
|
+
await client.initialize();
|
|
385
|
+
const invoke = async (name, args) => {
|
|
386
|
+
const { result } = await client.call(name, args);
|
|
387
|
+
assert.ok(result && !result.isError, name);
|
|
388
|
+
assert.deepEqual(JSON.parse(result.content[0].text), result.structuredContent);
|
|
389
|
+
return result.structuredContent;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
assert.deepEqual(await invoke('list_tags', { offset: 1, limit: 1 }), {
|
|
393
|
+
rows: [{ id: 'urgent', title: 'Urgent', icon: 'flag' }], total: 2, offset: 1, limit: 1
|
|
394
|
+
});
|
|
395
|
+
assert.deepEqual((await invoke('list_web_hooks', { title: 'ALERTS' })).rows, [{ id: 'hook1', title: 'Alerts Hook', enabled: true }]);
|
|
396
|
+
assert.deepEqual((await invoke('list_channels', { title: 'OPS' })).rows, [{ id: 'channel1', title: 'Ops Alerts', enabled: false }]);
|
|
397
|
+
assert.deepEqual(await invoke('list_active_jobs', { state: 'queued', event: 'e1', category: 'c1', offset: 2, limit: 10 }), {
|
|
398
|
+
rows: [job], total: 7, offset: 2, limit: 2
|
|
399
|
+
});
|
|
400
|
+
assert.deepEqual(requests.at(-1), {
|
|
401
|
+
path: '/api/app/get_active_jobs/v1', method: 'GET', key: 'editor-key',
|
|
402
|
+
params: { state: 'queued', event: 'e1', category: 'c1', offset: '2', limit: '2' }
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
const tag = { title: 'Follow up', icon: 'flag', notes: 'Check tomorrow' };
|
|
406
|
+
assert.deepEqual(await invoke('create_tag', { tag }), { tag: { id: 'generated_tag', title: tag.title, icon: tag.icon } });
|
|
407
|
+
assert.deepEqual(requests.at(-1), { path: '/api/app/create_tag/v1', method: 'POST', params: tag, key: 'editor-key' });
|
|
408
|
+
const restricted = stdioClient(t, { ...env, XYOPS_API_KEY: 'restricted-key' });
|
|
409
|
+
await restricted.initialize();
|
|
410
|
+
const denied = await restricted.call('create_tag', { tag });
|
|
411
|
+
assert.equal(denied.result.isError, true);
|
|
412
|
+
assert.match(denied.result.content[0].text, /Permission denied/);
|
|
413
|
+
assert.equal(requests.at(-1).key, 'restricted-key');
|
|
414
|
+
|
|
415
|
+
// Lookup callers cannot request extra fields or pass arbitrary job criteria.
|
|
416
|
+
const count = requests.length;
|
|
417
|
+
for (const [name, args] of [
|
|
418
|
+
['list_web_hooks', { fields: ['headers'] }], ['list_channels', { fields: ['email'] }],
|
|
419
|
+
['list_active_jobs', { state: 'complete' }], ['list_active_jobs', { env: {} }],
|
|
420
|
+
['create_tag', { tag: { title: ' ', username: 'admin' } }]
|
|
421
|
+
]) {
|
|
422
|
+
const reply = await client.call(name, args);
|
|
423
|
+
assert.ok(reply.error || reply.result.isError, name);
|
|
424
|
+
}
|
|
425
|
+
assert.equal(requests.length, count);
|
|
426
|
+
});
|
|
427
|
+
|
|
215
428
|
test('job output tools use real SDK downloads, gzip, byte pages and read-only STDIO', async t => {
|
|
216
429
|
const { gzipSync } = require('node:zlib');
|
|
217
430
|
const text = 'abc😀é\n' + 'Archived output\n'.repeat(10000);
|
|
@@ -10,7 +10,7 @@ const tools = require('../lib/mcp/registry.js')();
|
|
|
10
10
|
|
|
11
11
|
test('tool schemas reject unsafe or ambiguous mutation inputs', async () => {
|
|
12
12
|
const validate = (name, args) => tools.get(name).inputSchema['~standard'].validate(args);
|
|
13
|
-
assert.equal(tools.size,
|
|
13
|
+
assert.equal(tools.size, 59);
|
|
14
14
|
assert.ok((await validate('create_event', { event: { title: 'Test', category: 'general', enabled: false } })).issues);
|
|
15
15
|
assert.ok((await validate('update_event', { id: 'test', changes: { title: 'New' } })).issues);
|
|
16
16
|
assert.ok((await validate('update_event', { id: 'test', revision: 0, changes: {} })).issues);
|