@engini/cli 0.16.0 → 0.18.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 +11 -0
- package/dist/cli.js +705 -119
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -31,12 +31,23 @@ engini login | logout | whoami # auth
|
|
|
31
31
|
engini tools list | get | call | result # discover, execute & drill into results
|
|
32
32
|
engini applications list | get # browse connector apps
|
|
33
33
|
engini toolsets list | get | create | update | delete # scope an agent's tools/connections/workflows
|
|
34
|
+
engini mcp list | get | activate | deactivate # the account's MCP servers
|
|
35
|
+
engini mcp connections add|rm | tools list|set | workflows add|rm # configure one
|
|
34
36
|
engini connect [<app>] # create a connection (interactive / agent-resumable)
|
|
35
37
|
engini connections list | get # inspect connections
|
|
36
38
|
engini connections create | delete | check | refresh | objects | select-objects # primitives
|
|
37
39
|
engini connections sign-in-url | oauth-complete # OAuth2 start / finish primitives
|
|
38
40
|
```
|
|
39
41
|
|
|
42
|
+
The `mcp` group maintains the MCP endpoints Engini **exposes** (not the
|
|
43
|
+
`MCPClient` connection kind, which is Engini *consuming* someone else's server).
|
|
44
|
+
Servers are account-wide and are created/deleted in the engini.io UI, so the group
|
|
45
|
+
deliberately has no `create` and no `delete`. `connections add|rm`, `tools set` and
|
|
46
|
+
`workflows add|rm` are read-modify-write: the API replaces the whole set, so they
|
|
47
|
+
fetch the server first and send the complete result — `--dry-run` previews exactly
|
|
48
|
+
which bindings would change. The server token is part of the server's SSE URL, so
|
|
49
|
+
treat it as a secret.
|
|
50
|
+
|
|
40
51
|
`toolsets create`/`update` take either `--from-file <path|@path|->` (the whole
|
|
41
52
|
request body as JSON, matching `tools call --args`) or repeatable
|
|
42
53
|
`--connection <id>[:slug,slug]` / `--application <slug>[:slug,slug]` /
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { realpathSync } from "fs";
|
|
5
|
+
import { pathToFileURL } from "url";
|
|
6
|
+
|
|
3
7
|
// src/prompt.ts
|
|
4
8
|
import { spawn } from "child_process";
|
|
5
9
|
import { createInterface } from "readline";
|
|
@@ -243,6 +247,9 @@ function setOutputContext(ctx) {
|
|
|
243
247
|
function dryRun() {
|
|
244
248
|
return context.dryRun;
|
|
245
249
|
}
|
|
250
|
+
function outputFlags() {
|
|
251
|
+
return { forceJson: context.forceJson, quiet: context.quiet };
|
|
252
|
+
}
|
|
246
253
|
function formatValue(value) {
|
|
247
254
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
248
255
|
}
|
|
@@ -377,6 +384,7 @@ import {
|
|
|
377
384
|
ENV_TOKEN_VAR,
|
|
378
385
|
EnginiAuthError,
|
|
379
386
|
EnginiError,
|
|
387
|
+
EnginiMcpServerNotFoundError,
|
|
380
388
|
EnginiNotFoundError,
|
|
381
389
|
EnginiTimeoutError,
|
|
382
390
|
EnginiToolsetNotFoundError,
|
|
@@ -430,23 +438,33 @@ function saveConfig(config, path = configPath()) {
|
|
|
430
438
|
if (process.platform !== "win32") chmodSync(path, 384);
|
|
431
439
|
}
|
|
432
440
|
|
|
441
|
+
// src/version.ts
|
|
442
|
+
var VERSION = true ? "0.18.0" : "0.0.0";
|
|
443
|
+
|
|
433
444
|
// src/http.ts
|
|
445
|
+
var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
|
|
434
446
|
function buildClient(overrides = {}) {
|
|
435
447
|
const config = loadConfig();
|
|
436
448
|
const key = overrides.apiKey ?? process.env[ENV_API_KEY_VAR] ?? config.api_key;
|
|
437
449
|
if (key) {
|
|
438
|
-
return new Engini({ apiKey: key, baseUrl: config.api_url });
|
|
450
|
+
return new Engini({ apiKey: key, baseUrl: config.api_url, userAgentPrefix: USER_AGENT_PREFIX });
|
|
439
451
|
}
|
|
440
452
|
const token = overrides.apiToken ?? process.env[ENV_TOKEN_VAR] ?? config.api_token;
|
|
441
453
|
const company = overrides.companyToken ?? process.env[ENV_COMPANY_TOKEN_VAR] ?? config.company_token;
|
|
442
454
|
if (!token) {
|
|
443
455
|
fail(3 /* AUTH */, "No credentials found. Run `engini login`.");
|
|
444
456
|
}
|
|
445
|
-
return new Engini({
|
|
457
|
+
return new Engini({
|
|
458
|
+
token,
|
|
459
|
+
companyToken: company,
|
|
460
|
+
baseUrl: config.api_url,
|
|
461
|
+
userAgentPrefix: USER_AGENT_PREFIX
|
|
462
|
+
});
|
|
446
463
|
}
|
|
447
464
|
function exitForError(err) {
|
|
448
465
|
if (err instanceof EnginiAuthError) return 3 /* AUTH */;
|
|
449
466
|
if (err instanceof EnginiToolsetNotFoundError) return 4 /* NOT_FOUND */;
|
|
467
|
+
if (err instanceof EnginiMcpServerNotFoundError) return 4 /* NOT_FOUND */;
|
|
450
468
|
if (err instanceof EnginiNotFoundError) return 4 /* NOT_FOUND */;
|
|
451
469
|
if (err instanceof EnginiValidationError) return 5 /* VALIDATION */;
|
|
452
470
|
if (err instanceof EnginiTimeoutError) return 124 /* TIMEOUT */;
|
|
@@ -1549,6 +1567,29 @@ TOOLSETS
|
|
|
1549
1567
|
unchanged. --dry-run previews the diff before you commit to it.
|
|
1550
1568
|
toolsets delete <id> [--force] Remove a toolset.
|
|
1551
1569
|
|
|
1570
|
+
MCP SERVERS
|
|
1571
|
+
The MCP endpoints Engini *exposes*, carrying a chosen set of tools and workflows.
|
|
1572
|
+
Not the MCPClient connection kind, which is Engini *consuming* someone else's MCP
|
|
1573
|
+
server. Servers are account-wide, and are created/deleted in the engini.io UI \u2014
|
|
1574
|
+
this group inspects and configures them.
|
|
1575
|
+
mcp list List the account's MCP servers.
|
|
1576
|
+
mcp get <token> Show full detail for one MCP server.
|
|
1577
|
+
mcp activate <token> Turn a server on.
|
|
1578
|
+
mcp deactivate <token> Turn a server off (reversible; it stays listed).
|
|
1579
|
+
mcp connections add <token> --connection <id>[:slugs]
|
|
1580
|
+
Expose a connection (existing ones are kept).
|
|
1581
|
+
mcp connections rm <token> --connection-id <id>
|
|
1582
|
+
Stop exposing a connection.
|
|
1583
|
+
mcp tools list <token> --connection-id <id> List a connection's available tools.
|
|
1584
|
+
mcp tools set <token> --connection-id <id> (--tool <slug> ... | --all)
|
|
1585
|
+
Replace one connection's tool allow-list.
|
|
1586
|
+
mcp workflows add <token> --workflow <workflow_token> [--tool-name <n>] [--tool-description <t>]
|
|
1587
|
+
Expose a workflow as a tool.
|
|
1588
|
+
mcp workflows rm <token> --workflow <workflow_token>
|
|
1589
|
+
Stop exposing a workflow.
|
|
1590
|
+
Note: the server token is part of the server's SSE URL \u2014 treat it as a secret.
|
|
1591
|
+
--dry-run previews every mutating command's resulting set before you commit to it.
|
|
1592
|
+
|
|
1552
1593
|
OUTPUT & EXIT CODES
|
|
1553
1594
|
Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
|
|
1554
1595
|
JSON with --json. Universal flags on every command:
|
|
@@ -1565,6 +1606,7 @@ FILES & ENVIRONMENT
|
|
|
1565
1606
|
Re-run \`engini login\` to change it.
|
|
1566
1607
|
Env: ENGINI_API_KEY (preferred) or ENGINI_API_TOKEN, plus ENGINI_COMPANY_TOKEN.
|
|
1567
1608
|
Resolution order: flags > environment > config.
|
|
1609
|
+
ENGINI_NO_UPDATE_CHECK=1 skips the "update available" check on a TTY.
|
|
1568
1610
|
|
|
1569
1611
|
EXAMPLES
|
|
1570
1612
|
# Authenticate (or set ENGINI_API_KEY)
|
|
@@ -1819,8 +1861,517 @@ function registerLogout(program) {
|
|
|
1819
1861
|
});
|
|
1820
1862
|
}
|
|
1821
1863
|
|
|
1864
|
+
// src/shared/connections.ts
|
|
1865
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
1866
|
+
function collect2(value, previous = []) {
|
|
1867
|
+
return [...previous, value];
|
|
1868
|
+
}
|
|
1869
|
+
function splitSlugs(spec) {
|
|
1870
|
+
const colon = spec.indexOf(":");
|
|
1871
|
+
if (colon < 0) return [spec, void 0];
|
|
1872
|
+
const head = spec.slice(0, colon);
|
|
1873
|
+
const slugs = spec.slice(colon + 1).split(",").map((s) => s.trim()).filter(Boolean);
|
|
1874
|
+
return [head, slugs.length > 0 ? slugs : void 0];
|
|
1875
|
+
}
|
|
1876
|
+
function loadFromFile(spec) {
|
|
1877
|
+
let text;
|
|
1878
|
+
if (spec === "-") {
|
|
1879
|
+
text = readFileSync2(0, "utf8");
|
|
1880
|
+
} else if (spec.startsWith("@")) {
|
|
1881
|
+
try {
|
|
1882
|
+
text = readFileSync2(spec.slice(1), "utf8");
|
|
1883
|
+
} catch (err) {
|
|
1884
|
+
return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
|
|
1885
|
+
}
|
|
1886
|
+
} else {
|
|
1887
|
+
text = spec;
|
|
1888
|
+
}
|
|
1889
|
+
let data;
|
|
1890
|
+
try {
|
|
1891
|
+
data = JSON.parse(text);
|
|
1892
|
+
} catch (err) {
|
|
1893
|
+
return fail(2 /* USAGE */, `--from-file is not valid JSON: ${err.message}`);
|
|
1894
|
+
}
|
|
1895
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
1896
|
+
return fail(2 /* USAGE */, "--from-file must be a JSON object.");
|
|
1897
|
+
}
|
|
1898
|
+
return data;
|
|
1899
|
+
}
|
|
1900
|
+
function summarizeConnectionDto(c) {
|
|
1901
|
+
return {
|
|
1902
|
+
connection_id: c.connectionId,
|
|
1903
|
+
application_slug: c.applicationSlug,
|
|
1904
|
+
application_name: clean(c.applicationName),
|
|
1905
|
+
tool_slugs: c.toolSlugs
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
function summarizeConnectionRequest(c) {
|
|
1909
|
+
return {
|
|
1910
|
+
connection_id: c.connectionId ?? null,
|
|
1911
|
+
application_slug: c.applicationSlug ?? null,
|
|
1912
|
+
tool_slugs: c.toolSlugs ?? []
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
function connectionKey(c) {
|
|
1916
|
+
return c.connectionId != null ? `id:${c.connectionId}` : `app:${c.applicationSlug}`;
|
|
1917
|
+
}
|
|
1918
|
+
function scopeKey(c) {
|
|
1919
|
+
const slugs = c.toolSlugs ?? [];
|
|
1920
|
+
return slugs.length === 0 ? "*" : [...slugs].sort().join(",");
|
|
1921
|
+
}
|
|
1922
|
+
function diffConnections(current, next) {
|
|
1923
|
+
const currentKeys = new Set(current.map((c) => connectionKey(c)));
|
|
1924
|
+
const nextByKey = new Map(next.map((c) => [connectionKey(c), c]));
|
|
1925
|
+
const nextKeys = new Set(nextByKey.keys());
|
|
1926
|
+
const changed = current.filter((c) => nextKeys.has(connectionKey(c))).filter((c) => scopeKey(c) !== scopeKey(nextByKey.get(connectionKey(c)))).map((c) => {
|
|
1927
|
+
const nextEntry = nextByKey.get(connectionKey(c));
|
|
1928
|
+
return {
|
|
1929
|
+
connection_id: c.connectionId,
|
|
1930
|
+
application_slug: c.applicationSlug,
|
|
1931
|
+
from: summarizeConnectionDto(c),
|
|
1932
|
+
// A bare next-side entry carries no applicationSlug (it is resolved from
|
|
1933
|
+
// the id), but it is still the same connection — falling back to the
|
|
1934
|
+
// known slug avoids a null that reads as "the slug is being cleared".
|
|
1935
|
+
to: {
|
|
1936
|
+
...summarizeConnectionRequest(nextEntry),
|
|
1937
|
+
application_slug: nextEntry.applicationSlug ?? c.applicationSlug
|
|
1938
|
+
}
|
|
1939
|
+
};
|
|
1940
|
+
});
|
|
1941
|
+
return {
|
|
1942
|
+
current: current.map(summarizeConnectionDto),
|
|
1943
|
+
resulting: next.map(summarizeConnectionRequest),
|
|
1944
|
+
added: next.filter((c) => !currentKeys.has(connectionKey(c))).map(summarizeConnectionRequest),
|
|
1945
|
+
removed: current.filter((c) => !nextKeys.has(connectionKey(c))).map(summarizeConnectionDto),
|
|
1946
|
+
changed
|
|
1947
|
+
};
|
|
1948
|
+
}
|
|
1949
|
+
function diffWorkflows(current, next) {
|
|
1950
|
+
const currentSet = new Set(current);
|
|
1951
|
+
const nextSet = new Set(next);
|
|
1952
|
+
return {
|
|
1953
|
+
current,
|
|
1954
|
+
resulting: next,
|
|
1955
|
+
added: next.filter((id) => !currentSet.has(id)),
|
|
1956
|
+
removed: current.filter((id) => !nextSet.has(id))
|
|
1957
|
+
};
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
// src/mcp/shared.ts
|
|
1961
|
+
function parseMcpServerToken(value) {
|
|
1962
|
+
if (!value) fail(2 /* USAGE */, "Missing required argument 'mcp_server_token'.");
|
|
1963
|
+
return value;
|
|
1964
|
+
}
|
|
1965
|
+
function parseMcpConnectionFlags(specs) {
|
|
1966
|
+
return (specs ?? []).map((spec) => {
|
|
1967
|
+
const [idPart, toolSlugs] = splitSlugs(spec);
|
|
1968
|
+
if (!/^\d+$/.test(idPart)) {
|
|
1969
|
+
fail(2 /* USAGE */, `--connection must be <id> or <id>:slug,slug, got '${spec}'.`);
|
|
1970
|
+
}
|
|
1971
|
+
return { connectionId: Number(idPart), toolSlugs };
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
function parseConnectionIds(specs) {
|
|
1975
|
+
return (specs ?? []).map((spec) => {
|
|
1976
|
+
if (!/^\d+$/.test(spec)) {
|
|
1977
|
+
fail(2 /* USAGE */, `--connection-id must be a positive integer, got '${spec}'.`);
|
|
1978
|
+
}
|
|
1979
|
+
return Number(spec);
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
function connectionsToRequests(current) {
|
|
1983
|
+
return current.map((c) => ({
|
|
1984
|
+
connectionId: c.connectionId,
|
|
1985
|
+
toolSlugs: c.toolSlugs.length > 0 ? c.toolSlugs : void 0
|
|
1986
|
+
}));
|
|
1987
|
+
}
|
|
1988
|
+
function workflowsToRequests(current) {
|
|
1989
|
+
return current.map((w) => ({
|
|
1990
|
+
workflowToken: w.workflowToken,
|
|
1991
|
+
toolName: w.toolName ?? void 0,
|
|
1992
|
+
toolDescription: w.toolDescription ?? void 0
|
|
1993
|
+
}));
|
|
1994
|
+
}
|
|
1995
|
+
function upsertConnections(existing, incoming) {
|
|
1996
|
+
const byId = new Map(existing.map((c) => [c.connectionId, c]));
|
|
1997
|
+
for (const entry of incoming) byId.set(entry.connectionId, entry);
|
|
1998
|
+
return [...byId.values()];
|
|
1999
|
+
}
|
|
2000
|
+
function upsertWorkflows(existing, incoming) {
|
|
2001
|
+
const byToken = new Map(existing.map((w) => [w.workflowToken, w]));
|
|
2002
|
+
for (const entry of incoming) byToken.set(entry.workflowToken, entry);
|
|
2003
|
+
return [...byToken.values()];
|
|
2004
|
+
}
|
|
2005
|
+
function summarizeWorkflow(w) {
|
|
2006
|
+
return {
|
|
2007
|
+
workflow_token: w.workflowToken,
|
|
2008
|
+
workflow_name: clean(w.workflowName),
|
|
2009
|
+
tool_name: clean(w.toolName),
|
|
2010
|
+
tool_description: clean(w.toolDescription)
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
function summarizeMcpConnection(c) {
|
|
2014
|
+
return {
|
|
2015
|
+
...summarizeConnectionDto(c),
|
|
2016
|
+
available_tools_count: c.availableToolsCount,
|
|
2017
|
+
selected_tools_count: c.selectedToolsCount
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
function summarizeMcpServer(s) {
|
|
2021
|
+
return {
|
|
2022
|
+
mcp_server_token: s.mcpServerToken,
|
|
2023
|
+
name: s.name,
|
|
2024
|
+
is_active: s.isActive,
|
|
2025
|
+
is_anonymous_allowed: s.isAnonymousAllowed,
|
|
2026
|
+
connections: s.connections.map(summarizeMcpConnection),
|
|
2027
|
+
workflows: s.workflows.map(summarizeWorkflow),
|
|
2028
|
+
created_date: s.createdDate
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
// src/mcp/connections.ts
|
|
2033
|
+
async function applyConnections(mcpServerToken, next) {
|
|
2034
|
+
const client = buildClient();
|
|
2035
|
+
const current = await apiErrors(async () => client.mcp.get(mcpServerToken));
|
|
2036
|
+
const connections = next(current);
|
|
2037
|
+
if (dryRun()) {
|
|
2038
|
+
printOutput({
|
|
2039
|
+
would_update: {
|
|
2040
|
+
mcp_server_token: mcpServerToken,
|
|
2041
|
+
connections: diffConnections(current.connections, connections)
|
|
2042
|
+
}
|
|
2043
|
+
});
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
const updated = await apiErrors(async () => client.mcp.update(mcpServerToken, { connections }));
|
|
2047
|
+
printOutput(summarizeMcpServer(updated));
|
|
2048
|
+
}
|
|
2049
|
+
function registerAdd(connections) {
|
|
2050
|
+
const cmd = connections.command("add").description(
|
|
2051
|
+
"Add or re-scope connections on an MCP server. Existing connections are preserved; an entry with the same connection id is replaced."
|
|
2052
|
+
).argument("[mcp_server_token]", "MCP server token").option(
|
|
2053
|
+
"--connection <id[:slug,slug]>",
|
|
2054
|
+
"Connection to expose (repeatable); bare id = all its tools",
|
|
2055
|
+
collect2
|
|
2056
|
+
);
|
|
2057
|
+
cmd.addHelpText(
|
|
2058
|
+
"after",
|
|
2059
|
+
"\nExamples:\n engini mcp connections add <token> --connection 2139\n engini mcp connections add <token> --connection 2139:gmail_send_mail --dry-run"
|
|
2060
|
+
);
|
|
2061
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2062
|
+
cmd.action(
|
|
2063
|
+
async (token, opts, command) => {
|
|
2064
|
+
await runCommand(command, opts, true, async () => {
|
|
2065
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2066
|
+
if (!opts.connection?.length) {
|
|
2067
|
+
fail(2 /* USAGE */, "Nothing to add \u2014 pass at least one --connection.");
|
|
2068
|
+
}
|
|
2069
|
+
const incoming = parseMcpConnectionFlags(opts.connection);
|
|
2070
|
+
await applyConnections(
|
|
2071
|
+
mcpServerToken,
|
|
2072
|
+
(current) => upsertConnections(connectionsToRequests(current.connections), incoming)
|
|
2073
|
+
);
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
);
|
|
2077
|
+
}
|
|
2078
|
+
function registerRm(connections) {
|
|
2079
|
+
const cmd = connections.command("rm").description("Remove connections from an MCP server, leaving the rest in place.").argument("[mcp_server_token]", "MCP server token").option("--connection-id <id>", "Connection id to remove (repeatable)", collect2);
|
|
2080
|
+
cmd.addHelpText(
|
|
2081
|
+
"after",
|
|
2082
|
+
"\nExamples:\n engini mcp connections rm <token> --connection-id 2139\n engini mcp connections rm <token> --connection-id 2139 --dry-run"
|
|
2083
|
+
);
|
|
2084
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2085
|
+
cmd.action(
|
|
2086
|
+
async (token, opts, command) => {
|
|
2087
|
+
await runCommand(command, opts, true, async () => {
|
|
2088
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2089
|
+
if (!opts.connectionId?.length) {
|
|
2090
|
+
fail(2 /* USAGE */, "Nothing to remove \u2014 pass at least one --connection-id.");
|
|
2091
|
+
}
|
|
2092
|
+
const removing = new Set(parseConnectionIds(opts.connectionId));
|
|
2093
|
+
await applyConnections(mcpServerToken, (current) => {
|
|
2094
|
+
const present = new Set(current.connections.map((c) => c.connectionId));
|
|
2095
|
+
for (const id of removing) {
|
|
2096
|
+
if (!present.has(id)) {
|
|
2097
|
+
fail(4 /* NOT_FOUND */, `Connection ${id} is not on this MCP server.`);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
return connectionsToRequests(
|
|
2101
|
+
current.connections.filter((c) => !removing.has(c.connectionId))
|
|
2102
|
+
);
|
|
2103
|
+
});
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
);
|
|
2107
|
+
}
|
|
2108
|
+
function registerMcpConnections(mcp) {
|
|
2109
|
+
const connections = mcp.command("connections").description("Add or remove the connections an MCP server exposes.");
|
|
2110
|
+
registerAdd(connections);
|
|
2111
|
+
registerRm(connections);
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
// src/mcp/get.ts
|
|
2115
|
+
async function getBody3(token) {
|
|
2116
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2117
|
+
const server = await apiErrors(async () => {
|
|
2118
|
+
const client = buildClient();
|
|
2119
|
+
return client.mcp.get(mcpServerToken);
|
|
2120
|
+
});
|
|
2121
|
+
printOutput({
|
|
2122
|
+
...summarizeMcpServer(server),
|
|
2123
|
+
url: clean(server.url),
|
|
2124
|
+
updated_date: clean(server.updatedDate),
|
|
2125
|
+
created_by_account_user_id: clean(server.createdByAccountUserId),
|
|
2126
|
+
updated_by_account_user_id: clean(server.updatedByAccountUserId)
|
|
2127
|
+
});
|
|
2128
|
+
}
|
|
2129
|
+
function registerMcpGet(mcp) {
|
|
2130
|
+
const cmd = mcp.command("get").description("Show full detail for one MCP server.").argument("[mcp_server_token]", "MCP server token");
|
|
2131
|
+
cmd.addHelpText("after", "\nExamples:\n engini mcp get <mcp_server_token> --json");
|
|
2132
|
+
addUniversalOptions(cmd);
|
|
2133
|
+
cmd.action(async (token, opts, command) => {
|
|
2134
|
+
await runCommand(command, opts, false, () => getBody3(token));
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
// src/mcp/list.ts
|
|
2139
|
+
async function listBody4() {
|
|
2140
|
+
const servers = await apiErrors(async () => {
|
|
2141
|
+
const client = buildClient();
|
|
2142
|
+
return client.mcp.list();
|
|
2143
|
+
});
|
|
2144
|
+
printOutput(servers.map(summarizeMcpServer));
|
|
2145
|
+
}
|
|
2146
|
+
function registerMcpList(mcp) {
|
|
2147
|
+
const cmd = mcp.command("list").description("List the account's MCP servers.");
|
|
2148
|
+
cmd.addHelpText(
|
|
2149
|
+
"after",
|
|
2150
|
+
"\nExamples:\n engini mcp list --json\n engini mcp list --json | jq -r '.[] | select(.is_active == false) | .name'"
|
|
2151
|
+
);
|
|
2152
|
+
addUniversalOptions(cmd);
|
|
2153
|
+
cmd.action(async (opts, command) => {
|
|
2154
|
+
await runCommand(command, opts, false, () => listBody4());
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
// src/mcp/status.ts
|
|
2159
|
+
async function setActiveBody(token, isActive) {
|
|
2160
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2161
|
+
if (dryRun()) {
|
|
2162
|
+
printOutput({ would_update: { mcp_server_token: mcpServerToken, is_active: isActive } });
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
const server = await apiErrors(async () => {
|
|
2166
|
+
const client = buildClient();
|
|
2167
|
+
return isActive ? client.mcp.activate(mcpServerToken) : client.mcp.deactivate(mcpServerToken);
|
|
2168
|
+
});
|
|
2169
|
+
printOutput(summarizeMcpServer(server));
|
|
2170
|
+
}
|
|
2171
|
+
function register(mcp, name, description, isActive) {
|
|
2172
|
+
const cmd = mcp.command(name).description(description).argument("[mcp_server_token]", "MCP server token");
|
|
2173
|
+
cmd.addHelpText("after", `
|
|
2174
|
+
Examples:
|
|
2175
|
+
engini mcp ${name} <mcp_server_token>`);
|
|
2176
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2177
|
+
cmd.action(async (token, opts, command) => {
|
|
2178
|
+
await runCommand(command, opts, true, () => setActiveBody(token, isActive));
|
|
2179
|
+
});
|
|
2180
|
+
}
|
|
2181
|
+
function registerMcpStatus(mcp) {
|
|
2182
|
+
register(mcp, "activate", "Turn an MCP server on.", true);
|
|
2183
|
+
register(
|
|
2184
|
+
mcp,
|
|
2185
|
+
"deactivate",
|
|
2186
|
+
"Turn an MCP server off. Reversible \u2014 the server stays listed and can be reactivated.",
|
|
2187
|
+
false
|
|
2188
|
+
);
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
// src/mcp/tools.ts
|
|
2192
|
+
async function listBody5(token, connectionIdRaw) {
|
|
2193
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2194
|
+
if (!connectionIdRaw) fail(2 /* USAGE */, "Missing required option '--connection-id'.");
|
|
2195
|
+
const [connectionId] = parseConnectionIds([connectionIdRaw]);
|
|
2196
|
+
const tools = await apiErrors(async () => {
|
|
2197
|
+
const client = buildClient();
|
|
2198
|
+
return client.mcp.availableTools(mcpServerToken, connectionId);
|
|
2199
|
+
});
|
|
2200
|
+
printOutput(
|
|
2201
|
+
tools.map((t) => ({
|
|
2202
|
+
tool_name: t.toolName,
|
|
2203
|
+
description: t.description ?? null,
|
|
2204
|
+
is_mandatory: t.isMandatory
|
|
2205
|
+
}))
|
|
2206
|
+
);
|
|
2207
|
+
}
|
|
2208
|
+
async function setBody2(token, opts) {
|
|
2209
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2210
|
+
if (!opts.connectionId) fail(2 /* USAGE */, "Missing required option '--connection-id'.");
|
|
2211
|
+
const [connectionId] = parseConnectionIds([opts.connectionId]);
|
|
2212
|
+
const selected = opts.tool ?? [];
|
|
2213
|
+
if (opts.all && selected.length > 0) {
|
|
2214
|
+
fail(2 /* USAGE */, "--all cannot be combined with --tool.");
|
|
2215
|
+
}
|
|
2216
|
+
if (!opts.all && selected.length === 0) {
|
|
2217
|
+
fail(2 /* USAGE */, "Pass --tool <slug> (repeatable) to select tools, or --all to expose them all.");
|
|
2218
|
+
}
|
|
2219
|
+
const client = buildClient();
|
|
2220
|
+
const current = await apiErrors(async () => client.mcp.get(mcpServerToken));
|
|
2221
|
+
if (!current.connections.some((c) => c.connectionId === connectionId)) {
|
|
2222
|
+
fail(
|
|
2223
|
+
4 /* NOT_FOUND */,
|
|
2224
|
+
`Connection ${connectionId} is not on this MCP server \u2014 add it first with \`engini mcp connections add\`.`
|
|
2225
|
+
);
|
|
2226
|
+
}
|
|
2227
|
+
const connections = upsertConnections(connectionsToRequests(current.connections), [
|
|
2228
|
+
{ connectionId, toolSlugs: opts.all ? void 0 : selected }
|
|
2229
|
+
]);
|
|
2230
|
+
if (dryRun()) {
|
|
2231
|
+
printOutput({
|
|
2232
|
+
would_update: {
|
|
2233
|
+
mcp_server_token: mcpServerToken,
|
|
2234
|
+
connections: diffConnections(current.connections, connections)
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2237
|
+
return;
|
|
2238
|
+
}
|
|
2239
|
+
const updated = await apiErrors(async () => client.mcp.update(mcpServerToken, { connections }));
|
|
2240
|
+
printOutput(summarizeMcpServer(updated));
|
|
2241
|
+
}
|
|
2242
|
+
function registerMcpTools(mcp) {
|
|
2243
|
+
const tools = mcp.command("tools").description("Inspect and choose the tools an MCP server's connections expose.");
|
|
2244
|
+
const list = tools.command("list").description("List the tools a connection makes available to this MCP server.").argument("[mcp_server_token]", "MCP server token").option("--connection-id <id>", "Connection whose available tools to list");
|
|
2245
|
+
list.addHelpText(
|
|
2246
|
+
"after",
|
|
2247
|
+
"\nExamples:\n engini mcp tools list <token> --connection-id 2139 --json"
|
|
2248
|
+
);
|
|
2249
|
+
addUniversalOptions(list);
|
|
2250
|
+
list.action(
|
|
2251
|
+
async (token, opts, command) => {
|
|
2252
|
+
await runCommand(
|
|
2253
|
+
command,
|
|
2254
|
+
opts,
|
|
2255
|
+
false,
|
|
2256
|
+
() => listBody5(token, opts.connectionId)
|
|
2257
|
+
);
|
|
2258
|
+
}
|
|
2259
|
+
);
|
|
2260
|
+
const set = tools.command("set").description(
|
|
2261
|
+
"Replace the tool allow-list for one connection on an MCP server. Other connections are left untouched."
|
|
2262
|
+
).argument("[mcp_server_token]", "MCP server token").option("--connection-id <id>", "Connection to re-scope").option("--tool <slug>", "Tool slug to expose (repeatable)", collect2).option("--all", "Expose every tool of the connection's application");
|
|
2263
|
+
set.addHelpText(
|
|
2264
|
+
"after",
|
|
2265
|
+
"\nExamples:\n engini mcp tools set <token> --connection-id 2139 --tool gmail_send_mail\n engini mcp tools set <token> --connection-id 2139 --all\n engini mcp tools set <token> --connection-id 2139 --tool gmail_send_mail --dry-run"
|
|
2266
|
+
);
|
|
2267
|
+
addUniversalOptions(set, { mutating: true });
|
|
2268
|
+
set.action(async (token, opts, command) => {
|
|
2269
|
+
await runCommand(command, opts, true, () => setBody2(token, opts));
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
// src/mcp/workflows.ts
|
|
2274
|
+
async function applyWorkflows(mcpServerToken, next) {
|
|
2275
|
+
const client = buildClient();
|
|
2276
|
+
const current = await apiErrors(async () => client.mcp.get(mcpServerToken));
|
|
2277
|
+
const workflows = next(current);
|
|
2278
|
+
if (dryRun()) {
|
|
2279
|
+
printOutput({
|
|
2280
|
+
would_update: {
|
|
2281
|
+
mcp_server_token: mcpServerToken,
|
|
2282
|
+
workflows: diffWorkflows(
|
|
2283
|
+
current.workflows.map((w) => w.workflowToken),
|
|
2284
|
+
workflows.map((w) => w.workflowToken)
|
|
2285
|
+
)
|
|
2286
|
+
}
|
|
2287
|
+
});
|
|
2288
|
+
return;
|
|
2289
|
+
}
|
|
2290
|
+
const updated = await apiErrors(async () => client.mcp.update(mcpServerToken, { workflows }));
|
|
2291
|
+
printOutput(summarizeMcpServer(updated));
|
|
2292
|
+
}
|
|
2293
|
+
function registerAdd2(workflows) {
|
|
2294
|
+
const cmd = workflows.command("add").description(
|
|
2295
|
+
"Expose workflows as tools on an MCP server. Existing workflows are preserved; an entry with the same workflow token is replaced."
|
|
2296
|
+
).argument("[mcp_server_token]", "MCP server token").option("--workflow <workflow_token>", "Workflow to expose (repeatable)", collect2).option("--tool-name <name>", "Override the tool name (single --workflow only)").option("--tool-description <text>", "Override the tool description (single --workflow only)");
|
|
2297
|
+
cmd.addHelpText(
|
|
2298
|
+
"after",
|
|
2299
|
+
"\nExamples:\n engini mcp workflows add <token> --workflow <workflow_token>\n engini mcp workflows add <token> --workflow <workflow_token> --tool-name send_report\n engini mcp workflows add <token> --workflow <workflow_token> --dry-run"
|
|
2300
|
+
);
|
|
2301
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2302
|
+
cmd.action(async (token, opts, command) => {
|
|
2303
|
+
await runCommand(command, opts, true, async () => {
|
|
2304
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2305
|
+
const requested = opts.workflow ?? [];
|
|
2306
|
+
if (requested.length === 0) {
|
|
2307
|
+
fail(2 /* USAGE */, "Nothing to add \u2014 pass at least one --workflow.");
|
|
2308
|
+
}
|
|
2309
|
+
const hasOverride = opts.toolName !== void 0 || opts.toolDescription !== void 0;
|
|
2310
|
+
if (hasOverride && requested.length > 1) {
|
|
2311
|
+
fail(
|
|
2312
|
+
2 /* USAGE */,
|
|
2313
|
+
"--tool-name/--tool-description apply to a single --workflow; pass them one workflow at a time."
|
|
2314
|
+
);
|
|
2315
|
+
}
|
|
2316
|
+
const incoming = requested.map((workflowToken) => ({
|
|
2317
|
+
workflowToken,
|
|
2318
|
+
toolName: opts.toolName,
|
|
2319
|
+
toolDescription: opts.toolDescription
|
|
2320
|
+
}));
|
|
2321
|
+
await applyWorkflows(
|
|
2322
|
+
mcpServerToken,
|
|
2323
|
+
(current) => upsertWorkflows(workflowsToRequests(current.workflows), incoming)
|
|
2324
|
+
);
|
|
2325
|
+
});
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
function registerRm2(workflows) {
|
|
2329
|
+
const cmd = workflows.command("rm").description("Stop exposing workflows on an MCP server, leaving the rest in place.").argument("[mcp_server_token]", "MCP server token").option("--workflow <workflow_token>", "Workflow to remove (repeatable)", collect2);
|
|
2330
|
+
cmd.addHelpText(
|
|
2331
|
+
"after",
|
|
2332
|
+
"\nExamples:\n engini mcp workflows rm <token> --workflow <workflow_token>"
|
|
2333
|
+
);
|
|
2334
|
+
addUniversalOptions(cmd, { mutating: true });
|
|
2335
|
+
cmd.action(async (token, opts, command) => {
|
|
2336
|
+
await runCommand(command, opts, true, async () => {
|
|
2337
|
+
const mcpServerToken = parseMcpServerToken(token);
|
|
2338
|
+
if (!opts.workflow?.length) {
|
|
2339
|
+
fail(2 /* USAGE */, "Nothing to remove \u2014 pass at least one --workflow.");
|
|
2340
|
+
}
|
|
2341
|
+
const removing = new Set(opts.workflow);
|
|
2342
|
+
await applyWorkflows(mcpServerToken, (current) => {
|
|
2343
|
+
const present = new Set(current.workflows.map((w) => w.workflowToken));
|
|
2344
|
+
for (const wf of removing) {
|
|
2345
|
+
if (!present.has(wf)) {
|
|
2346
|
+
fail(4 /* NOT_FOUND */, "That workflow is not exposed on this MCP server.");
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
return workflowsToRequests(
|
|
2350
|
+
current.workflows.filter((w) => !removing.has(w.workflowToken))
|
|
2351
|
+
);
|
|
2352
|
+
});
|
|
2353
|
+
});
|
|
2354
|
+
});
|
|
2355
|
+
}
|
|
2356
|
+
function registerMcpWorkflows(mcp) {
|
|
2357
|
+
const workflows = mcp.command("workflows").description("Add or remove the workflows an MCP server exposes as tools.");
|
|
2358
|
+
registerAdd2(workflows);
|
|
2359
|
+
registerRm2(workflows);
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// src/mcp/index.ts
|
|
2363
|
+
function registerMcp(program) {
|
|
2364
|
+
const mcp = program.command("mcp").description("List, inspect, activate, and configure the account's MCP servers.");
|
|
2365
|
+
registerMcpList(mcp);
|
|
2366
|
+
registerMcpGet(mcp);
|
|
2367
|
+
registerMcpStatus(mcp);
|
|
2368
|
+
registerMcpConnections(mcp);
|
|
2369
|
+
registerMcpTools(mcp);
|
|
2370
|
+
registerMcpWorkflows(mcp);
|
|
2371
|
+
}
|
|
2372
|
+
|
|
1822
2373
|
// src/tools/call.ts
|
|
1823
|
-
import { readFileSync as
|
|
2374
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
1824
2375
|
import {
|
|
1825
2376
|
AnthropicProvider,
|
|
1826
2377
|
File,
|
|
@@ -1832,7 +2383,7 @@ import { randomBytes } from "crypto";
|
|
|
1832
2383
|
import {
|
|
1833
2384
|
existsSync as existsSync2,
|
|
1834
2385
|
mkdirSync as mkdirSync2,
|
|
1835
|
-
readFileSync as
|
|
2386
|
+
readFileSync as readFileSync3,
|
|
1836
2387
|
readdirSync,
|
|
1837
2388
|
rmSync,
|
|
1838
2389
|
statSync,
|
|
@@ -1876,7 +2427,7 @@ function loadResult(handle) {
|
|
|
1876
2427
|
const path = join2(cacheDir(), `${handle}.json`);
|
|
1877
2428
|
if (!existsSync2(path)) return null;
|
|
1878
2429
|
try {
|
|
1879
|
-
const data = JSON.parse(
|
|
2430
|
+
const data = JSON.parse(readFileSync3(path, "utf8"));
|
|
1880
2431
|
return data && typeof data === "object" ? data : null;
|
|
1881
2432
|
} catch {
|
|
1882
2433
|
return null;
|
|
@@ -2064,10 +2615,10 @@ function paginate(value, offset, limit) {
|
|
|
2064
2615
|
function loadArgs(spec) {
|
|
2065
2616
|
let text;
|
|
2066
2617
|
if (spec === "-") {
|
|
2067
|
-
text =
|
|
2618
|
+
text = readFileSync4(0, "utf8");
|
|
2068
2619
|
} else if (spec.startsWith("@")) {
|
|
2069
2620
|
try {
|
|
2070
|
-
text =
|
|
2621
|
+
text = readFileSync4(spec.slice(1), "utf8");
|
|
2071
2622
|
} catch (err) {
|
|
2072
2623
|
return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
|
|
2073
2624
|
}
|
|
@@ -2241,7 +2792,7 @@ function detail3(schema) {
|
|
|
2241
2792
|
max_sorts: clean(schema.maxSorts)
|
|
2242
2793
|
};
|
|
2243
2794
|
}
|
|
2244
|
-
async function
|
|
2795
|
+
async function getBody4(toolId) {
|
|
2245
2796
|
if (!toolId) {
|
|
2246
2797
|
fail(2 /* USAGE */, "Missing required argument 'tool_id'.");
|
|
2247
2798
|
}
|
|
@@ -2255,7 +2806,7 @@ function registerToolsGet(tools) {
|
|
|
2255
2806
|
const cmd = tools.command("get").description("Show full canonical detail for one tool.").argument("[tool_id]", "Tool slug");
|
|
2256
2807
|
addUniversalOptions(cmd);
|
|
2257
2808
|
cmd.action(async (toolId, opts, command) => {
|
|
2258
|
-
await runCommand(command, opts, false, () =>
|
|
2809
|
+
await runCommand(command, opts, false, () => getBody4(toolId));
|
|
2259
2810
|
});
|
|
2260
2811
|
}
|
|
2261
2812
|
|
|
@@ -2278,7 +2829,7 @@ function parseLimit2(value) {
|
|
|
2278
2829
|
}
|
|
2279
2830
|
return limit;
|
|
2280
2831
|
}
|
|
2281
|
-
async function
|
|
2832
|
+
async function listBody6(opts) {
|
|
2282
2833
|
if (opts.application && opts.toolset) {
|
|
2283
2834
|
fail(2 /* USAGE */, "Pass only one of --application / --toolset.");
|
|
2284
2835
|
}
|
|
@@ -2301,7 +2852,7 @@ function registerToolsList(tools) {
|
|
|
2301
2852
|
const cmd = tools.command("list").description("List available tools, optionally filtered.").option("--application <slug>", "Filter by application slug (e.g. monday)").option("--toolset <id>", "List the tools of a server toolset (by id)").option("--limit <n>", "Cap the number of tools returned");
|
|
2302
2853
|
addUniversalOptions(cmd);
|
|
2303
2854
|
cmd.action(async (opts, command) => {
|
|
2304
|
-
await runCommand(command, opts, false, () =>
|
|
2855
|
+
await runCommand(command, opts, false, () => listBody6(opts));
|
|
2305
2856
|
});
|
|
2306
2857
|
}
|
|
2307
2858
|
|
|
@@ -2385,21 +2936,10 @@ function registerTools(program) {
|
|
|
2385
2936
|
}
|
|
2386
2937
|
|
|
2387
2938
|
// src/toolsets/shared.ts
|
|
2388
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
2389
|
-
function collect2(value, previous = []) {
|
|
2390
|
-
return [...previous, value];
|
|
2391
|
-
}
|
|
2392
2939
|
function parseToolsetId(value) {
|
|
2393
2940
|
if (!value) fail(2 /* USAGE */, "Missing required argument 'toolset_id'.");
|
|
2394
2941
|
return value;
|
|
2395
2942
|
}
|
|
2396
|
-
function splitSlugs(spec) {
|
|
2397
|
-
const colon = spec.indexOf(":");
|
|
2398
|
-
if (colon < 0) return [spec, void 0];
|
|
2399
|
-
const head = spec.slice(0, colon);
|
|
2400
|
-
const slugs = spec.slice(colon + 1).split(",").map((s) => s.trim()).filter(Boolean);
|
|
2401
|
-
return [head, slugs.length > 0 ? slugs : void 0];
|
|
2402
|
-
}
|
|
2403
2943
|
function parseConnectionFlags(specs) {
|
|
2404
2944
|
return (specs ?? []).map((spec) => {
|
|
2405
2945
|
const [idPart, toolSlugs] = splitSlugs(spec);
|
|
@@ -2430,30 +2970,6 @@ function connectionsFromFlagsOrUndefined(opts) {
|
|
|
2430
2970
|
function workflowsFromFlagsOrUndefined(specs) {
|
|
2431
2971
|
return specs && specs.length > 0 ? specs : void 0;
|
|
2432
2972
|
}
|
|
2433
|
-
function loadFromFile(spec) {
|
|
2434
|
-
let text;
|
|
2435
|
-
if (spec === "-") {
|
|
2436
|
-
text = readFileSync4(0, "utf8");
|
|
2437
|
-
} else if (spec.startsWith("@")) {
|
|
2438
|
-
try {
|
|
2439
|
-
text = readFileSync4(spec.slice(1), "utf8");
|
|
2440
|
-
} catch (err) {
|
|
2441
|
-
return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
|
|
2442
|
-
}
|
|
2443
|
-
} else {
|
|
2444
|
-
text = spec;
|
|
2445
|
-
}
|
|
2446
|
-
let data;
|
|
2447
|
-
try {
|
|
2448
|
-
data = JSON.parse(text);
|
|
2449
|
-
} catch (err) {
|
|
2450
|
-
return fail(2 /* USAGE */, `--from-file is not valid JSON: ${err.message}`);
|
|
2451
|
-
}
|
|
2452
|
-
if (data === null || typeof data !== "object" || Array.isArray(data)) {
|
|
2453
|
-
return fail(2 /* USAGE */, "--from-file must be a JSON object.");
|
|
2454
|
-
}
|
|
2455
|
-
return data;
|
|
2456
|
-
}
|
|
2457
2973
|
var CONNECTION_ENTRY_ALIASES = {
|
|
2458
2974
|
connection_id: "connectionId",
|
|
2459
2975
|
application_slug: "applicationSlug",
|
|
@@ -2485,12 +3001,7 @@ function rejectFromFileCombo(fromFile, opts) {
|
|
|
2485
3001
|
}
|
|
2486
3002
|
}
|
|
2487
3003
|
function summarizeConnection(c) {
|
|
2488
|
-
return
|
|
2489
|
-
connection_id: c.connectionId,
|
|
2490
|
-
application_slug: c.applicationSlug,
|
|
2491
|
-
application_name: clean(c.applicationName),
|
|
2492
|
-
tool_slugs: c.toolSlugs
|
|
2493
|
-
};
|
|
3004
|
+
return summarizeConnectionDto(c);
|
|
2494
3005
|
}
|
|
2495
3006
|
function summarizeToolset(t) {
|
|
2496
3007
|
return {
|
|
@@ -2501,59 +3012,11 @@ function summarizeToolset(t) {
|
|
|
2501
3012
|
created_date: t.createdDate
|
|
2502
3013
|
};
|
|
2503
3014
|
}
|
|
2504
|
-
function
|
|
2505
|
-
return
|
|
2506
|
-
connection_id: c.connectionId ?? null,
|
|
2507
|
-
application_slug: c.applicationSlug ?? null,
|
|
2508
|
-
tool_slugs: c.toolSlugs ?? []
|
|
2509
|
-
};
|
|
2510
|
-
}
|
|
2511
|
-
function connectionKey(c) {
|
|
2512
|
-
return c.connectionId != null ? `id:${c.connectionId}` : `app:${c.applicationSlug}`;
|
|
2513
|
-
}
|
|
2514
|
-
function scopeKey(c) {
|
|
2515
|
-
const slugs = c.toolSlugs ?? [];
|
|
2516
|
-
return slugs.length === 0 ? "*" : [...slugs].sort().join(",");
|
|
2517
|
-
}
|
|
2518
|
-
function diffConnections(current, next) {
|
|
2519
|
-
const currentKeys = new Set(current.map((c) => connectionKey(c)));
|
|
2520
|
-
const nextByKey = new Map(next.map((c) => [connectionKey(c), c]));
|
|
2521
|
-
const nextKeys = new Set(nextByKey.keys());
|
|
2522
|
-
const changed = current.filter((c) => nextKeys.has(connectionKey(c))).filter((c) => scopeKey(c) !== scopeKey(nextByKey.get(connectionKey(c)))).map((c) => {
|
|
2523
|
-
const nextEntry = nextByKey.get(connectionKey(c));
|
|
2524
|
-
return {
|
|
2525
|
-
connection_id: c.connectionId,
|
|
2526
|
-
application_slug: c.applicationSlug,
|
|
2527
|
-
from: summarizeConnection(c),
|
|
2528
|
-
// A bare `--connection <id>` next-side entry carries no
|
|
2529
|
-
// `applicationSlug` (it's resolved server-side from the id), but it's
|
|
2530
|
-
// still the *same* connection as `c` - falling back to `c`'s known
|
|
2531
|
-
// slug avoids a `to.application_slug: null` sitting next to a `from`
|
|
2532
|
-
// that shows the real slug, which reads as "the slug is being
|
|
2533
|
-
// cleared" when nothing about the app binding actually changed.
|
|
2534
|
-
to: {
|
|
2535
|
-
...summarizeConnectionRequest(nextEntry),
|
|
2536
|
-
application_slug: nextEntry.applicationSlug ?? c.applicationSlug
|
|
2537
|
-
}
|
|
2538
|
-
};
|
|
2539
|
-
});
|
|
2540
|
-
return {
|
|
2541
|
-
current: current.map(summarizeConnection),
|
|
2542
|
-
resulting: next.map(summarizeConnectionRequest),
|
|
2543
|
-
added: next.filter((c) => !currentKeys.has(connectionKey(c))).map(summarizeConnectionRequest),
|
|
2544
|
-
removed: current.filter((c) => !nextKeys.has(connectionKey(c))).map(summarizeConnection),
|
|
2545
|
-
changed
|
|
2546
|
-
};
|
|
3015
|
+
function summarizeConnectionRequest2(c) {
|
|
3016
|
+
return summarizeConnectionRequest(c);
|
|
2547
3017
|
}
|
|
2548
|
-
function
|
|
2549
|
-
|
|
2550
|
-
const nextSet = new Set(next);
|
|
2551
|
-
return {
|
|
2552
|
-
current,
|
|
2553
|
-
resulting: next,
|
|
2554
|
-
added: next.filter((id) => !currentSet.has(id)),
|
|
2555
|
-
removed: current.filter((id) => !nextSet.has(id))
|
|
2556
|
-
};
|
|
3018
|
+
function diffConnections2(current, next) {
|
|
3019
|
+
return diffConnections(current, next);
|
|
2557
3020
|
}
|
|
2558
3021
|
|
|
2559
3022
|
// src/toolsets/create.ts
|
|
@@ -2586,7 +3049,7 @@ async function createBody2(opts) {
|
|
|
2586
3049
|
printOutput({
|
|
2587
3050
|
would_create: {
|
|
2588
3051
|
name: body.name,
|
|
2589
|
-
connections: body.connections.map(
|
|
3052
|
+
connections: body.connections.map(summarizeConnectionRequest2),
|
|
2590
3053
|
workflows: body.workflows ?? []
|
|
2591
3054
|
}
|
|
2592
3055
|
});
|
|
@@ -2642,7 +3105,7 @@ function registerToolsetsDelete(toolsets) {
|
|
|
2642
3105
|
}
|
|
2643
3106
|
|
|
2644
3107
|
// src/toolsets/get.ts
|
|
2645
|
-
async function
|
|
3108
|
+
async function getBody5(toolsetId) {
|
|
2646
3109
|
const id = parseToolsetId(toolsetId);
|
|
2647
3110
|
const toolset = await apiErrors(async () => {
|
|
2648
3111
|
const client = buildClient();
|
|
@@ -2660,12 +3123,12 @@ function registerToolsetsGet(toolsets) {
|
|
|
2660
3123
|
cmd.addHelpText("after", "\nExamples:\n engini toolsets get <toolset_id> --json");
|
|
2661
3124
|
addUniversalOptions(cmd);
|
|
2662
3125
|
cmd.action(async (id, opts, command) => {
|
|
2663
|
-
await runCommand(command, opts, false, () =>
|
|
3126
|
+
await runCommand(command, opts, false, () => getBody5(id));
|
|
2664
3127
|
});
|
|
2665
3128
|
}
|
|
2666
3129
|
|
|
2667
3130
|
// src/toolsets/list.ts
|
|
2668
|
-
async function
|
|
3131
|
+
async function listBody7() {
|
|
2669
3132
|
const toolsets = await apiErrors(async () => {
|
|
2670
3133
|
const client = buildClient();
|
|
2671
3134
|
return client.toolsets.list();
|
|
@@ -2680,7 +3143,7 @@ function registerToolsetsList(toolsets) {
|
|
|
2680
3143
|
);
|
|
2681
3144
|
addUniversalOptions(cmd);
|
|
2682
3145
|
cmd.action(async (opts, command) => {
|
|
2683
|
-
await runCommand(command, opts, false, () =>
|
|
3146
|
+
await runCommand(command, opts, false, () => listBody7());
|
|
2684
3147
|
});
|
|
2685
3148
|
}
|
|
2686
3149
|
|
|
@@ -2710,7 +3173,7 @@ async function previewDryRun(toolsetId, body) {
|
|
|
2710
3173
|
would_update: {
|
|
2711
3174
|
toolset_id: toolsetId,
|
|
2712
3175
|
name: body.name === void 0 ? null : { from: current.name, to: body.name },
|
|
2713
|
-
connections: body.connections === void 0 ? null :
|
|
3176
|
+
connections: body.connections === void 0 ? null : diffConnections2(current.connections, body.connections),
|
|
2714
3177
|
workflows: body.workflows === void 0 ? null : diffWorkflows(current.workflows, body.workflows)
|
|
2715
3178
|
}
|
|
2716
3179
|
});
|
|
@@ -2792,9 +3255,6 @@ function registerWhoami(program) {
|
|
|
2792
3255
|
});
|
|
2793
3256
|
}
|
|
2794
3257
|
|
|
2795
|
-
// src/version.ts
|
|
2796
|
-
var VERSION = true ? "0.16.0" : "0.0.0";
|
|
2797
|
-
|
|
2798
3258
|
// src/main.ts
|
|
2799
3259
|
function buildProgram() {
|
|
2800
3260
|
const program = new Command();
|
|
@@ -2807,10 +3267,119 @@ function buildProgram() {
|
|
|
2807
3267
|
registerApplications(program);
|
|
2808
3268
|
registerConnections(program);
|
|
2809
3269
|
registerToolsets(program);
|
|
3270
|
+
registerMcp(program);
|
|
2810
3271
|
installHelp(program);
|
|
2811
3272
|
return program;
|
|
2812
3273
|
}
|
|
2813
3274
|
|
|
3275
|
+
// src/update-notice.ts
|
|
3276
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
3277
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
3278
|
+
var REGISTRY_DIST_TAGS_URL = "https://registry.npmjs.org/-/package/%40engini%2Fcli/dist-tags";
|
|
3279
|
+
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
3280
|
+
var FETCH_TIMEOUT_MS = 1500;
|
|
3281
|
+
var SEMVER_RE = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
3282
|
+
function defaultCachePath() {
|
|
3283
|
+
return join3(dirname2(configPath()), "update-check.json");
|
|
3284
|
+
}
|
|
3285
|
+
function readCache(path) {
|
|
3286
|
+
try {
|
|
3287
|
+
const data = JSON.parse(readFileSync5(path, "utf8"));
|
|
3288
|
+
if (typeof data.checked_at === "number" && typeof data.channel === "string" && (data.latest_version === null || typeof data.latest_version === "string")) {
|
|
3289
|
+
return data;
|
|
3290
|
+
}
|
|
3291
|
+
} catch {
|
|
3292
|
+
}
|
|
3293
|
+
return null;
|
|
3294
|
+
}
|
|
3295
|
+
function writeCache(path, cache) {
|
|
3296
|
+
mkdirSync3(dirname2(path), { recursive: true });
|
|
3297
|
+
writeFileSync3(path, JSON.stringify(cache));
|
|
3298
|
+
}
|
|
3299
|
+
async function fetchLatest(fetchImpl, channel) {
|
|
3300
|
+
try {
|
|
3301
|
+
const res = await fetchImpl(REGISTRY_DIST_TAGS_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
3302
|
+
if (!res.ok) return null;
|
|
3303
|
+
const tags = await res.json();
|
|
3304
|
+
const tag = tags[channel];
|
|
3305
|
+
return typeof tag === "string" && SEMVER_RE.test(tag) ? tag : null;
|
|
3306
|
+
} catch {
|
|
3307
|
+
return null;
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
function parseVersion(v) {
|
|
3311
|
+
const m = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(v);
|
|
3312
|
+
if (!m) return null;
|
|
3313
|
+
return {
|
|
3314
|
+
core: [Number(m[1]), Number(m[2]), Number(m[3])],
|
|
3315
|
+
prerelease: m[4] ? m[4].split(".") : null
|
|
3316
|
+
};
|
|
3317
|
+
}
|
|
3318
|
+
function compareCore(a, b) {
|
|
3319
|
+
for (let i = 0; i < 3; i++) {
|
|
3320
|
+
if (a[i] !== b[i]) return a[i] - b[i];
|
|
3321
|
+
}
|
|
3322
|
+
return 0;
|
|
3323
|
+
}
|
|
3324
|
+
function comparePrerelease(a, b) {
|
|
3325
|
+
const len = Math.max(a.length, b.length);
|
|
3326
|
+
for (let i = 0; i < len; i++) {
|
|
3327
|
+
if (i >= a.length) return -1;
|
|
3328
|
+
if (i >= b.length) return 1;
|
|
3329
|
+
const [ai, bi] = [a[i], b[i]];
|
|
3330
|
+
const [aNum, bNum] = [/^\d+$/.test(ai), /^\d+$/.test(bi)];
|
|
3331
|
+
if (aNum && bNum) {
|
|
3332
|
+
const diff = Number(ai) - Number(bi);
|
|
3333
|
+
if (diff !== 0) return diff;
|
|
3334
|
+
} else if (aNum !== bNum) {
|
|
3335
|
+
return aNum ? -1 : 1;
|
|
3336
|
+
} else if (ai !== bi) {
|
|
3337
|
+
return ai < bi ? -1 : 1;
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
return 0;
|
|
3341
|
+
}
|
|
3342
|
+
function isNewer(current, latest) {
|
|
3343
|
+
const a = parseVersion(current);
|
|
3344
|
+
const b = parseVersion(latest);
|
|
3345
|
+
if (!a || !b) return false;
|
|
3346
|
+
const coreCmp = compareCore(a.core, b.core);
|
|
3347
|
+
if (coreCmp !== 0) return coreCmp < 0;
|
|
3348
|
+
if (a.prerelease === null) return false;
|
|
3349
|
+
if (b.prerelease === null) return true;
|
|
3350
|
+
return comparePrerelease(a.prerelease, b.prerelease) < 0;
|
|
3351
|
+
}
|
|
3352
|
+
async function maybePrintUpdateNotice(deps = {}) {
|
|
3353
|
+
const version = deps.version ?? VERSION;
|
|
3354
|
+
const now = deps.now ?? (() => Date.now());
|
|
3355
|
+
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
3356
|
+
const cachePath = deps.cachePath ?? defaultCachePath();
|
|
3357
|
+
if (version === "0.0.0") return;
|
|
3358
|
+
if (!(process.stdout.isTTY && process.stderr.isTTY)) return;
|
|
3359
|
+
const { forceJson, quiet } = outputFlags();
|
|
3360
|
+
if (forceJson || quiet) return;
|
|
3361
|
+
if (process.env.CI) return;
|
|
3362
|
+
if (process.env.ENGINI_NO_UPDATE_CHECK) return;
|
|
3363
|
+
if (process.env.NO_UPDATE_NOTIFIER) return;
|
|
3364
|
+
try {
|
|
3365
|
+
const channel = version.includes("-") ? "beta" : "latest";
|
|
3366
|
+
const cached = readCache(cachePath);
|
|
3367
|
+
let latestVersion;
|
|
3368
|
+
if (cached && cached.channel === channel && now() - cached.checked_at < CACHE_TTL_MS) {
|
|
3369
|
+
latestVersion = cached.latest_version;
|
|
3370
|
+
} else {
|
|
3371
|
+
latestVersion = await fetchLatest(fetchImpl, channel);
|
|
3372
|
+
writeCache(cachePath, { checked_at: now(), channel, latest_version: latestVersion });
|
|
3373
|
+
}
|
|
3374
|
+
if (latestVersion !== null && isNewer(version, latestVersion)) {
|
|
3375
|
+
console.error(
|
|
3376
|
+
`Update available: ${version} -> ${latestVersion} Run: npm install -g @engini/cli@${channel}`
|
|
3377
|
+
);
|
|
3378
|
+
}
|
|
3379
|
+
} catch {
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
|
|
2814
3383
|
// src/index.ts
|
|
2815
3384
|
function applyExitOverride(command) {
|
|
2816
3385
|
command.exitOverride();
|
|
@@ -2819,24 +3388,41 @@ function applyExitOverride(command) {
|
|
|
2819
3388
|
async function main(argv = process.argv.slice(2)) {
|
|
2820
3389
|
const program = buildProgram();
|
|
2821
3390
|
applyExitOverride(program);
|
|
3391
|
+
if (argv.length === 0) {
|
|
3392
|
+
program.outputHelp();
|
|
3393
|
+
await maybePrintUpdateNotice();
|
|
3394
|
+
process.exit(0);
|
|
3395
|
+
}
|
|
2822
3396
|
try {
|
|
2823
|
-
if (argv.length === 0) {
|
|
2824
|
-
program.outputHelp();
|
|
2825
|
-
process.exit(0);
|
|
2826
|
-
}
|
|
2827
3397
|
await program.parseAsync(argv, { from: "user" });
|
|
3398
|
+
await maybePrintUpdateNotice();
|
|
2828
3399
|
} catch (err) {
|
|
2829
3400
|
if (err instanceof CliError) {
|
|
2830
3401
|
process.exit(err.code);
|
|
2831
3402
|
}
|
|
2832
3403
|
if (err && typeof err === "object" && "exitCode" in err) {
|
|
2833
|
-
|
|
3404
|
+
const code = mapCommanderExitCode(err.exitCode);
|
|
3405
|
+
if (code === 0 /* OK */) {
|
|
3406
|
+
await maybePrintUpdateNotice();
|
|
3407
|
+
}
|
|
3408
|
+
process.exit(code);
|
|
2834
3409
|
}
|
|
2835
3410
|
console.error(err instanceof Error ? err.message : String(err));
|
|
2836
3411
|
process.exit(1);
|
|
2837
3412
|
}
|
|
2838
3413
|
}
|
|
2839
|
-
|
|
3414
|
+
function isMainModule(metaUrl, argv1) {
|
|
3415
|
+
if (argv1 === void 0) return false;
|
|
3416
|
+
try {
|
|
3417
|
+
return metaUrl === pathToFileURL(realpathSync(argv1)).href;
|
|
3418
|
+
} catch {
|
|
3419
|
+
return false;
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
if (isMainModule(import.meta.url, process.argv[1])) {
|
|
3423
|
+
main();
|
|
3424
|
+
}
|
|
2840
3425
|
export {
|
|
3426
|
+
isMainModule,
|
|
2841
3427
|
main
|
|
2842
3428
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@engini/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Engini CLI — machine-first command line over the Engini Public API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,12 +19,14 @@
|
|
|
19
19
|
"directory": "ts/packages/cli"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
+
"pretypecheck": "pnpm --filter @engini/sdk run generate-version",
|
|
23
|
+
"pretest": "pnpm --filter @engini/sdk run generate-version",
|
|
22
24
|
"typecheck": "tsc --noEmit",
|
|
23
25
|
"build": "tsup",
|
|
24
26
|
"test": "vitest run"
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@engini/sdk": "^0.
|
|
29
|
+
"@engini/sdk": "^0.18.0",
|
|
28
30
|
"commander": "^12.1.0",
|
|
29
31
|
"smol-toml": "^1.3.0"
|
|
30
32
|
},
|