@engini/cli 0.17.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.
Files changed (3) hide show
  1. package/README.md +11 -0
  2. package/dist/cli.js +556 -109
  3. package/package.json +2 -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
@@ -384,6 +384,7 @@ import {
384
384
  ENV_TOKEN_VAR,
385
385
  EnginiAuthError,
386
386
  EnginiError,
387
+ EnginiMcpServerNotFoundError,
387
388
  EnginiNotFoundError,
388
389
  EnginiTimeoutError,
389
390
  EnginiToolsetNotFoundError,
@@ -438,7 +439,7 @@ function saveConfig(config, path = configPath()) {
438
439
  }
439
440
 
440
441
  // src/version.ts
441
- var VERSION = true ? "0.17.0" : "0.0.0";
442
+ var VERSION = true ? "0.18.0" : "0.0.0";
442
443
 
443
444
  // src/http.ts
444
445
  var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
@@ -463,6 +464,7 @@ function buildClient(overrides = {}) {
463
464
  function exitForError(err) {
464
465
  if (err instanceof EnginiAuthError) return 3 /* AUTH */;
465
466
  if (err instanceof EnginiToolsetNotFoundError) return 4 /* NOT_FOUND */;
467
+ if (err instanceof EnginiMcpServerNotFoundError) return 4 /* NOT_FOUND */;
466
468
  if (err instanceof EnginiNotFoundError) return 4 /* NOT_FOUND */;
467
469
  if (err instanceof EnginiValidationError) return 5 /* VALIDATION */;
468
470
  if (err instanceof EnginiTimeoutError) return 124 /* TIMEOUT */;
@@ -1565,6 +1567,29 @@ TOOLSETS
1565
1567
  unchanged. --dry-run previews the diff before you commit to it.
1566
1568
  toolsets delete <id> [--force] Remove a toolset.
1567
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
+
1568
1593
  OUTPUT & EXIT CODES
1569
1594
  Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
1570
1595
  JSON with --json. Universal flags on every command:
@@ -1836,8 +1861,517 @@ function registerLogout(program) {
1836
1861
  });
1837
1862
  }
1838
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
+
1839
2373
  // src/tools/call.ts
1840
- import { readFileSync as readFileSync3 } from "fs";
2374
+ import { readFileSync as readFileSync4 } from "fs";
1841
2375
  import {
1842
2376
  AnthropicProvider,
1843
2377
  File,
@@ -1849,7 +2383,7 @@ import { randomBytes } from "crypto";
1849
2383
  import {
1850
2384
  existsSync as existsSync2,
1851
2385
  mkdirSync as mkdirSync2,
1852
- readFileSync as readFileSync2,
2386
+ readFileSync as readFileSync3,
1853
2387
  readdirSync,
1854
2388
  rmSync,
1855
2389
  statSync,
@@ -1893,7 +2427,7 @@ function loadResult(handle) {
1893
2427
  const path = join2(cacheDir(), `${handle}.json`);
1894
2428
  if (!existsSync2(path)) return null;
1895
2429
  try {
1896
- const data = JSON.parse(readFileSync2(path, "utf8"));
2430
+ const data = JSON.parse(readFileSync3(path, "utf8"));
1897
2431
  return data && typeof data === "object" ? data : null;
1898
2432
  } catch {
1899
2433
  return null;
@@ -2081,10 +2615,10 @@ function paginate(value, offset, limit) {
2081
2615
  function loadArgs(spec) {
2082
2616
  let text;
2083
2617
  if (spec === "-") {
2084
- text = readFileSync3(0, "utf8");
2618
+ text = readFileSync4(0, "utf8");
2085
2619
  } else if (spec.startsWith("@")) {
2086
2620
  try {
2087
- text = readFileSync3(spec.slice(1), "utf8");
2621
+ text = readFileSync4(spec.slice(1), "utf8");
2088
2622
  } catch (err) {
2089
2623
  return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
2090
2624
  }
@@ -2258,7 +2792,7 @@ function detail3(schema) {
2258
2792
  max_sorts: clean(schema.maxSorts)
2259
2793
  };
2260
2794
  }
2261
- async function getBody3(toolId) {
2795
+ async function getBody4(toolId) {
2262
2796
  if (!toolId) {
2263
2797
  fail(2 /* USAGE */, "Missing required argument 'tool_id'.");
2264
2798
  }
@@ -2272,7 +2806,7 @@ function registerToolsGet(tools) {
2272
2806
  const cmd = tools.command("get").description("Show full canonical detail for one tool.").argument("[tool_id]", "Tool slug");
2273
2807
  addUniversalOptions(cmd);
2274
2808
  cmd.action(async (toolId, opts, command) => {
2275
- await runCommand(command, opts, false, () => getBody3(toolId));
2809
+ await runCommand(command, opts, false, () => getBody4(toolId));
2276
2810
  });
2277
2811
  }
2278
2812
 
@@ -2295,7 +2829,7 @@ function parseLimit2(value) {
2295
2829
  }
2296
2830
  return limit;
2297
2831
  }
2298
- async function listBody4(opts) {
2832
+ async function listBody6(opts) {
2299
2833
  if (opts.application && opts.toolset) {
2300
2834
  fail(2 /* USAGE */, "Pass only one of --application / --toolset.");
2301
2835
  }
@@ -2318,7 +2852,7 @@ function registerToolsList(tools) {
2318
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");
2319
2853
  addUniversalOptions(cmd);
2320
2854
  cmd.action(async (opts, command) => {
2321
- await runCommand(command, opts, false, () => listBody4(opts));
2855
+ await runCommand(command, opts, false, () => listBody6(opts));
2322
2856
  });
2323
2857
  }
2324
2858
 
@@ -2402,21 +2936,10 @@ function registerTools(program) {
2402
2936
  }
2403
2937
 
2404
2938
  // src/toolsets/shared.ts
2405
- import { readFileSync as readFileSync4 } from "fs";
2406
- function collect2(value, previous = []) {
2407
- return [...previous, value];
2408
- }
2409
2939
  function parseToolsetId(value) {
2410
2940
  if (!value) fail(2 /* USAGE */, "Missing required argument 'toolset_id'.");
2411
2941
  return value;
2412
2942
  }
2413
- function splitSlugs(spec) {
2414
- const colon = spec.indexOf(":");
2415
- if (colon < 0) return [spec, void 0];
2416
- const head = spec.slice(0, colon);
2417
- const slugs = spec.slice(colon + 1).split(",").map((s) => s.trim()).filter(Boolean);
2418
- return [head, slugs.length > 0 ? slugs : void 0];
2419
- }
2420
2943
  function parseConnectionFlags(specs) {
2421
2944
  return (specs ?? []).map((spec) => {
2422
2945
  const [idPart, toolSlugs] = splitSlugs(spec);
@@ -2447,30 +2970,6 @@ function connectionsFromFlagsOrUndefined(opts) {
2447
2970
  function workflowsFromFlagsOrUndefined(specs) {
2448
2971
  return specs && specs.length > 0 ? specs : void 0;
2449
2972
  }
2450
- function loadFromFile(spec) {
2451
- let text;
2452
- if (spec === "-") {
2453
- text = readFileSync4(0, "utf8");
2454
- } else if (spec.startsWith("@")) {
2455
- try {
2456
- text = readFileSync4(spec.slice(1), "utf8");
2457
- } catch (err) {
2458
- return fail(2 /* USAGE */, `Cannot read ${spec.slice(1)}: ${err.message}`);
2459
- }
2460
- } else {
2461
- text = spec;
2462
- }
2463
- let data;
2464
- try {
2465
- data = JSON.parse(text);
2466
- } catch (err) {
2467
- return fail(2 /* USAGE */, `--from-file is not valid JSON: ${err.message}`);
2468
- }
2469
- if (data === null || typeof data !== "object" || Array.isArray(data)) {
2470
- return fail(2 /* USAGE */, "--from-file must be a JSON object.");
2471
- }
2472
- return data;
2473
- }
2474
2973
  var CONNECTION_ENTRY_ALIASES = {
2475
2974
  connection_id: "connectionId",
2476
2975
  application_slug: "applicationSlug",
@@ -2502,12 +3001,7 @@ function rejectFromFileCombo(fromFile, opts) {
2502
3001
  }
2503
3002
  }
2504
3003
  function summarizeConnection(c) {
2505
- return {
2506
- connection_id: c.connectionId,
2507
- application_slug: c.applicationSlug,
2508
- application_name: clean(c.applicationName),
2509
- tool_slugs: c.toolSlugs
2510
- };
3004
+ return summarizeConnectionDto(c);
2511
3005
  }
2512
3006
  function summarizeToolset(t) {
2513
3007
  return {
@@ -2518,59 +3012,11 @@ function summarizeToolset(t) {
2518
3012
  created_date: t.createdDate
2519
3013
  };
2520
3014
  }
2521
- function summarizeConnectionRequest(c) {
2522
- return {
2523
- connection_id: c.connectionId ?? null,
2524
- application_slug: c.applicationSlug ?? null,
2525
- tool_slugs: c.toolSlugs ?? []
2526
- };
2527
- }
2528
- function connectionKey(c) {
2529
- return c.connectionId != null ? `id:${c.connectionId}` : `app:${c.applicationSlug}`;
2530
- }
2531
- function scopeKey(c) {
2532
- const slugs = c.toolSlugs ?? [];
2533
- return slugs.length === 0 ? "*" : [...slugs].sort().join(",");
2534
- }
2535
- function diffConnections(current, next) {
2536
- const currentKeys = new Set(current.map((c) => connectionKey(c)));
2537
- const nextByKey = new Map(next.map((c) => [connectionKey(c), c]));
2538
- const nextKeys = new Set(nextByKey.keys());
2539
- const changed = current.filter((c) => nextKeys.has(connectionKey(c))).filter((c) => scopeKey(c) !== scopeKey(nextByKey.get(connectionKey(c)))).map((c) => {
2540
- const nextEntry = nextByKey.get(connectionKey(c));
2541
- return {
2542
- connection_id: c.connectionId,
2543
- application_slug: c.applicationSlug,
2544
- from: summarizeConnection(c),
2545
- // A bare `--connection <id>` next-side entry carries no
2546
- // `applicationSlug` (it's resolved server-side from the id), but it's
2547
- // still the *same* connection as `c` - falling back to `c`'s known
2548
- // slug avoids a `to.application_slug: null` sitting next to a `from`
2549
- // that shows the real slug, which reads as "the slug is being
2550
- // cleared" when nothing about the app binding actually changed.
2551
- to: {
2552
- ...summarizeConnectionRequest(nextEntry),
2553
- application_slug: nextEntry.applicationSlug ?? c.applicationSlug
2554
- }
2555
- };
2556
- });
2557
- return {
2558
- current: current.map(summarizeConnection),
2559
- resulting: next.map(summarizeConnectionRequest),
2560
- added: next.filter((c) => !currentKeys.has(connectionKey(c))).map(summarizeConnectionRequest),
2561
- removed: current.filter((c) => !nextKeys.has(connectionKey(c))).map(summarizeConnection),
2562
- changed
2563
- };
3015
+ function summarizeConnectionRequest2(c) {
3016
+ return summarizeConnectionRequest(c);
2564
3017
  }
2565
- function diffWorkflows(current, next) {
2566
- const currentSet = new Set(current);
2567
- const nextSet = new Set(next);
2568
- return {
2569
- current,
2570
- resulting: next,
2571
- added: next.filter((id) => !currentSet.has(id)),
2572
- removed: current.filter((id) => !nextSet.has(id))
2573
- };
3018
+ function diffConnections2(current, next) {
3019
+ return diffConnections(current, next);
2574
3020
  }
2575
3021
 
2576
3022
  // src/toolsets/create.ts
@@ -2603,7 +3049,7 @@ async function createBody2(opts) {
2603
3049
  printOutput({
2604
3050
  would_create: {
2605
3051
  name: body.name,
2606
- connections: body.connections.map(summarizeConnectionRequest),
3052
+ connections: body.connections.map(summarizeConnectionRequest2),
2607
3053
  workflows: body.workflows ?? []
2608
3054
  }
2609
3055
  });
@@ -2659,7 +3105,7 @@ function registerToolsetsDelete(toolsets) {
2659
3105
  }
2660
3106
 
2661
3107
  // src/toolsets/get.ts
2662
- async function getBody4(toolsetId) {
3108
+ async function getBody5(toolsetId) {
2663
3109
  const id = parseToolsetId(toolsetId);
2664
3110
  const toolset = await apiErrors(async () => {
2665
3111
  const client = buildClient();
@@ -2677,12 +3123,12 @@ function registerToolsetsGet(toolsets) {
2677
3123
  cmd.addHelpText("after", "\nExamples:\n engini toolsets get <toolset_id> --json");
2678
3124
  addUniversalOptions(cmd);
2679
3125
  cmd.action(async (id, opts, command) => {
2680
- await runCommand(command, opts, false, () => getBody4(id));
3126
+ await runCommand(command, opts, false, () => getBody5(id));
2681
3127
  });
2682
3128
  }
2683
3129
 
2684
3130
  // src/toolsets/list.ts
2685
- async function listBody5() {
3131
+ async function listBody7() {
2686
3132
  const toolsets = await apiErrors(async () => {
2687
3133
  const client = buildClient();
2688
3134
  return client.toolsets.list();
@@ -2697,7 +3143,7 @@ function registerToolsetsList(toolsets) {
2697
3143
  );
2698
3144
  addUniversalOptions(cmd);
2699
3145
  cmd.action(async (opts, command) => {
2700
- await runCommand(command, opts, false, () => listBody5());
3146
+ await runCommand(command, opts, false, () => listBody7());
2701
3147
  });
2702
3148
  }
2703
3149
 
@@ -2727,7 +3173,7 @@ async function previewDryRun(toolsetId, body) {
2727
3173
  would_update: {
2728
3174
  toolset_id: toolsetId,
2729
3175
  name: body.name === void 0 ? null : { from: current.name, to: body.name },
2730
- connections: body.connections === void 0 ? null : diffConnections(current.connections, body.connections),
3176
+ connections: body.connections === void 0 ? null : diffConnections2(current.connections, body.connections),
2731
3177
  workflows: body.workflows === void 0 ? null : diffWorkflows(current.workflows, body.workflows)
2732
3178
  }
2733
3179
  });
@@ -2821,6 +3267,7 @@ function buildProgram() {
2821
3267
  registerApplications(program);
2822
3268
  registerConnections(program);
2823
3269
  registerToolsets(program);
3270
+ registerMcp(program);
2824
3271
  installHelp(program);
2825
3272
  return program;
2826
3273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/cli",
3
- "version": "0.17.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",
@@ -26,7 +26,7 @@
26
26
  "test": "vitest run"
27
27
  },
28
28
  "dependencies": {
29
- "@engini/sdk": "^0.17.0",
29
+ "@engini/sdk": "^0.18.0",
30
30
  "commander": "^12.1.0",
31
31
  "smol-toml": "^1.3.0"
32
32
  },