@ainecto/cli 0.16.6 → 0.16.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/README.md +1 -1
- package/dist/bin/ainecto.js +315 -143
- package/dist/bin/ainecto.js.map +1 -1
- package/dist/bin/mcp.js +64 -10
- package/dist/bin/mcp.js.map +1 -1
- package/package.json +2 -2
package/dist/bin/mcp.js
CHANGED
|
@@ -220,8 +220,8 @@ function legacyRoleInput(flag, envVars = process.env) {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
// src/core/version.ts
|
|
223
|
-
var CLI_VERSION = true ? "0.16.
|
|
224
|
-
var CLI_BUILD = true ? "
|
|
223
|
+
var CLI_VERSION = true ? "0.16.7" : UNBUNDLED_VERSION;
|
|
224
|
+
var CLI_BUILD = true ? "d033663" : void 0;
|
|
225
225
|
function cliVersionLabel(version, build, release) {
|
|
226
226
|
return release || build === void 0 ? version : `${version}-dev+${build}`;
|
|
227
227
|
}
|
|
@@ -979,6 +979,35 @@ function assertEnvTokenEndpointAllowed(endpoint, envVars) {
|
|
|
979
979
|
|
|
980
980
|
// src/core/mcp/stdioBridge.ts
|
|
981
981
|
import { createInterface } from "readline";
|
|
982
|
+
|
|
983
|
+
// src/core/mcp/readOnlyTools.ts
|
|
984
|
+
function isReadOnlyTool(tool) {
|
|
985
|
+
if (!isRecord6(tool) || !isRecord6(tool.annotations)) return false;
|
|
986
|
+
return tool.annotations.readOnlyHint === true;
|
|
987
|
+
}
|
|
988
|
+
function readOnlyToolsResult(result) {
|
|
989
|
+
const base = isRecord6(result) ? result : {};
|
|
990
|
+
return { ...base, tools: Array.isArray(base.tools) ? base.tools.filter(isReadOnlyTool) : [] };
|
|
991
|
+
}
|
|
992
|
+
async function isReadOnlyToolNow(page, name) {
|
|
993
|
+
const seen = /* @__PURE__ */ new Set();
|
|
994
|
+
let cursor;
|
|
995
|
+
for (; ; ) {
|
|
996
|
+
const result = await page(cursor);
|
|
997
|
+
if (!isRecord6(result) || !Array.isArray(result.tools)) throw new McpRpcError("tools/list response did not include a tools array.", "MCP_PROTOCOL_ERROR", result);
|
|
998
|
+
const found = result.tools.find((tool) => isRecord6(tool) && tool.name === name);
|
|
999
|
+
if (found !== void 0) return isReadOnlyTool(found);
|
|
1000
|
+
const next = typeof result.nextCursor === "string" && result.nextCursor !== "" ? result.nextCursor : void 0;
|
|
1001
|
+
if (next === void 0 || seen.has(next)) return false;
|
|
1002
|
+
seen.add(next);
|
|
1003
|
+
cursor = next;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
function isRecord6(value) {
|
|
1007
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// src/core/mcp/stdioBridge.ts
|
|
982
1011
|
async function runStdioBridge(options) {
|
|
983
1012
|
const lines = createInterface({ input: options.input, crlfDelay: Infinity });
|
|
984
1013
|
for await (const line of lines) {
|
|
@@ -996,9 +1025,19 @@ async function runStdioBridge(options) {
|
|
|
996
1025
|
if (request.method === "initialize") {
|
|
997
1026
|
options.client.useAgent(clientInfoName(request.params));
|
|
998
1027
|
}
|
|
1028
|
+
if (options.readOnly && request.method === "tools/call") {
|
|
1029
|
+
const name = toolNameOf(request.params);
|
|
1030
|
+
const listPage = (cursor) => options.client.request("tools/list", cursor === void 0 ? {} : { cursor });
|
|
1031
|
+
if (!await isReadOnlyToolNow(listPage, name)) {
|
|
1032
|
+
options.errorOutput.write(`read-only session refused tools/call ${JSON.stringify(name)}
|
|
1033
|
+
`);
|
|
1034
|
+
if (request.id !== void 0) writeLine(options.output, readOnlyRefusal(request.id, name));
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
999
1038
|
const response = await options.client.sendRaw(request);
|
|
1000
1039
|
if (response && request.id !== void 0) {
|
|
1001
|
-
writeLine(options.output, response);
|
|
1040
|
+
writeLine(options.output, options.readOnly && request.method === "tools/list" && "result" in response ? { ...response, result: readOnlyToolsResult(response.result) } : response);
|
|
1002
1041
|
}
|
|
1003
1042
|
} catch (error) {
|
|
1004
1043
|
if (request.id === void 0) {
|
|
@@ -1012,16 +1051,27 @@ async function runStdioBridge(options) {
|
|
|
1012
1051
|
}
|
|
1013
1052
|
var PARSE_ERROR = -32700;
|
|
1014
1053
|
var INVALID_REQUEST = -32600;
|
|
1054
|
+
var INVALID_PARAMS = -32602;
|
|
1015
1055
|
var INTERNAL_ERROR = -32603;
|
|
1016
1056
|
var RATE_LIMITED_CODE = 429;
|
|
1017
1057
|
function failure(id, code, error) {
|
|
1018
|
-
const data = error instanceof McpRpcError ? { code: error.code, ...
|
|
1058
|
+
const data = error instanceof McpRpcError ? { code: error.code, ...isRecord7(error.details) ? error.details : {} } : void 0;
|
|
1019
1059
|
return {
|
|
1020
1060
|
jsonrpc: "2.0",
|
|
1021
1061
|
id,
|
|
1022
1062
|
error: { code, message: errorMessage(error), ...data ? { data } : {} }
|
|
1023
1063
|
};
|
|
1024
1064
|
}
|
|
1065
|
+
function readOnlyRefusal(id, name) {
|
|
1066
|
+
return {
|
|
1067
|
+
jsonrpc: "2.0",
|
|
1068
|
+
id,
|
|
1069
|
+
error: { code: INVALID_PARAMS, message: `Tool ${JSON.stringify(name)} is not available here: this session can only read AiNecto (project room), and AiNecto does not mark this tool as read-only. Say what should be changed instead.` }
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
function toolNameOf(params) {
|
|
1073
|
+
return isRecord7(params) && typeof params.name === "string" ? params.name : "";
|
|
1074
|
+
}
|
|
1025
1075
|
function errorMessage(error) {
|
|
1026
1076
|
return error instanceof Error ? error.message : String(error);
|
|
1027
1077
|
}
|
|
@@ -1031,7 +1081,7 @@ function writeLine(output, message) {
|
|
|
1031
1081
|
}
|
|
1032
1082
|
function parseJsonRpcRequest(line) {
|
|
1033
1083
|
const parsed = JSON.parse(line);
|
|
1034
|
-
if (!
|
|
1084
|
+
if (!isRecord7(parsed) || parsed.jsonrpc !== "2.0" || typeof parsed.method !== "string") {
|
|
1035
1085
|
throw new Error("Invalid JSON-RPC request.");
|
|
1036
1086
|
}
|
|
1037
1087
|
return {
|
|
@@ -1042,9 +1092,9 @@ function parseJsonRpcRequest(line) {
|
|
|
1042
1092
|
};
|
|
1043
1093
|
}
|
|
1044
1094
|
function clientInfoName(params) {
|
|
1045
|
-
return
|
|
1095
|
+
return isRecord7(params) && isRecord7(params.clientInfo) ? params.clientInfo.name : void 0;
|
|
1046
1096
|
}
|
|
1047
|
-
function
|
|
1097
|
+
function isRecord7(value) {
|
|
1048
1098
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1049
1099
|
}
|
|
1050
1100
|
|
|
@@ -1172,7 +1222,8 @@ async function runConnector(options) {
|
|
|
1172
1222
|
input: options.input,
|
|
1173
1223
|
output: options.output,
|
|
1174
1224
|
errorOutput: options.errorOutput,
|
|
1175
|
-
client
|
|
1225
|
+
client,
|
|
1226
|
+
...options.readOnly ? { readOnly: true } : {}
|
|
1176
1227
|
});
|
|
1177
1228
|
}
|
|
1178
1229
|
|
|
@@ -1234,7 +1285,7 @@ function redactSecretString(value) {
|
|
|
1234
1285
|
|
|
1235
1286
|
// src/adapters/mcp/args.ts
|
|
1236
1287
|
function parseMcpArgs(argv) {
|
|
1237
|
-
const result = { help: false };
|
|
1288
|
+
const result = { readOnly: false, help: false };
|
|
1238
1289
|
for (let index = 0; index < argv.length; index += 1) {
|
|
1239
1290
|
const arg = argv[index];
|
|
1240
1291
|
if (!arg) {
|
|
@@ -1250,6 +1301,8 @@ function parseMcpArgs(argv) {
|
|
|
1250
1301
|
throw new Error(`${arg} requires a value.`);
|
|
1251
1302
|
}
|
|
1252
1303
|
result.agent = name;
|
|
1304
|
+
} else if (arg === "--read-only") {
|
|
1305
|
+
result.readOnly = true;
|
|
1253
1306
|
} else if (arg === "--role") {
|
|
1254
1307
|
const value = argv[index + 1];
|
|
1255
1308
|
if (value !== void 0 && !value.startsWith("--")) {
|
|
@@ -1275,7 +1328,7 @@ function requireFlagValue(flag, value) {
|
|
|
1275
1328
|
try {
|
|
1276
1329
|
const args = parseMcpArgs(process.argv.slice(2));
|
|
1277
1330
|
if (args.help) {
|
|
1278
|
-
process.stdout.write("Usage: mcp [--env prod|dev] [--endpoint URL] [--agent NAME]\n");
|
|
1331
|
+
process.stdout.write("Usage: mcp [--env prod|dev] [--endpoint URL] [--agent NAME] [--read-only]\n");
|
|
1279
1332
|
process.exit(0);
|
|
1280
1333
|
}
|
|
1281
1334
|
const resolved = resolveEndpoint({ env: args.env, endpoint: args.endpoint });
|
|
@@ -1283,6 +1336,7 @@ try {
|
|
|
1283
1336
|
endpoint: resolved.endpoint,
|
|
1284
1337
|
legacyRoleFlag: args.legacyRole,
|
|
1285
1338
|
agentFlag: args.agent,
|
|
1339
|
+
readOnly: args.readOnly,
|
|
1286
1340
|
input: process.stdin,
|
|
1287
1341
|
output: process.stdout,
|
|
1288
1342
|
errorOutput: process.stderr
|