@ainecto/mcp 0.14.0-next.12 → 0.14.0-next.14

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/dist/bin/mcp.js CHANGED
@@ -139,7 +139,7 @@ function tokenKey(endpoint) {
139
139
  }
140
140
 
141
141
  // src/core/auth/oauth.ts
142
- import { createHash as createHash2, randomBytes } from "crypto";
142
+ import { createHash as createHash3, randomBytes } from "crypto";
143
143
  import { createServer } from "http";
144
144
  import { spawn } from "child_process";
145
145
  import { URLSearchParams } from "url";
@@ -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.14.0-next.12" : UNBUNDLED_VERSION;
224
- var CLI_BUILD = true ? "d070964" : void 0;
223
+ var CLI_VERSION = true ? "0.14.0-next.14" : UNBUNDLED_VERSION;
224
+ var CLI_BUILD = true ? "69b52f7" : void 0;
225
225
  function cliVersionLabel(version, build, release) {
226
226
  return release || build === void 0 ? version : `${version}-dev+${build}`;
227
227
  }
@@ -230,6 +230,118 @@ var CLI_VERSION_LABEL = cliVersionLabel(CLI_VERSION, CLI_BUILD, CLI_RELEASE);
230
230
  var PACKAGE_NAME = "@ainecto/mcp";
231
231
  var CLI_USER_AGENT = `${PACKAGE_NAME} ${CLI_VERSION}`;
232
232
 
233
+ // src/core/catalog/generator.ts
234
+ import { createHash as createHash2 } from "crypto";
235
+ var LEGACY_PREFIX = "mcp__ainecto__";
236
+ function bareToolName(name) {
237
+ return name.startsWith(LEGACY_PREFIX) ? name.slice(LEGACY_PREFIX.length) : name;
238
+ }
239
+
240
+ // src/core/mcp/toolPayload.ts
241
+ function unwrapMcpToolPayload(value) {
242
+ if (!isRecord3(value) || !Array.isArray(value.content)) {
243
+ return value;
244
+ }
245
+ const text = value.content.map((item) => isRecord3(item) && typeof item.text === "string" ? item.text : "").find((itemText) => itemText.trim().startsWith("{"));
246
+ if (!text) {
247
+ return value;
248
+ }
249
+ try {
250
+ return JSON.parse(text);
251
+ } catch {
252
+ return value;
253
+ }
254
+ }
255
+ function toolErrorText(value) {
256
+ if (!isRecord3(value) || !Array.isArray(value.content)) {
257
+ return "The tool returned an error.";
258
+ }
259
+ const text = value.content.map((item) => isRecord3(item) && typeof item.text === "string" ? item.text : "").filter(Boolean).join("\n");
260
+ return text || "The tool returned an error.";
261
+ }
262
+ function isRecord3(value) {
263
+ return typeof value === "object" && value !== null && !Array.isArray(value);
264
+ }
265
+
266
+ // src/core/mcp/operations.ts
267
+ var SEARCH_TOOL = "search";
268
+ var OperationError = class extends Error {
269
+ constructor(message, code, operation, details) {
270
+ super(message);
271
+ this.code = code;
272
+ this.operation = operation;
273
+ this.details = details;
274
+ this.name = "OperationError";
275
+ }
276
+ code;
277
+ operation;
278
+ details;
279
+ };
280
+ function searchPayload(asked, operation, result) {
281
+ if (isRecord4(result) && result.isError === true) throw toolRefusal(asked, operation, result);
282
+ return unwrapMcpToolPayload(result);
283
+ }
284
+ function parseOperationDetail(operation, result) {
285
+ const payload = searchPayload(`the detail of ${operation}`, operation, result);
286
+ if (!isRecord4(payload) || payload.operation !== operation) {
287
+ throw new OperationError(`search did not return the detail of ${operation}.`, "MCP_PROTOCOL_ERROR", operation);
288
+ }
289
+ const executor = payload.executor;
290
+ if (typeof executor !== "string" || executor.trim() === "") {
291
+ throw new OperationError(
292
+ `search detail of ${operation} has no valid executor (${JSON.stringify(executor)}).`,
293
+ "MCP_PROTOCOL_ERROR",
294
+ operation
295
+ );
296
+ }
297
+ const hints = isRecord4(payload.annotations) ? payload.annotations : {};
298
+ return {
299
+ operation,
300
+ summary: typeof payload.summary === "string" ? payload.summary : "",
301
+ executor,
302
+ annotations: {
303
+ ...typeof hints.readOnlyHint === "boolean" ? { readOnlyHint: hints.readOnlyHint } : {},
304
+ ...typeof hints.destructiveHint === "boolean" ? { destructiveHint: hints.destructiveHint } : {},
305
+ ...typeof hints.idempotentHint === "boolean" ? { idempotentHint: hints.idempotentHint } : {},
306
+ ...typeof hints.openWorldHint === "boolean" ? { openWorldHint: hints.openWorldHint } : {}
307
+ },
308
+ inputSchema: isRecord4(payload.inputSchema) ? payload.inputSchema : { type: "object", properties: {} }
309
+ };
310
+ }
311
+ var OperationCaller = class {
312
+ constructor(callPublic) {
313
+ this.callPublic = callPublic;
314
+ }
315
+ callPublic;
316
+ details = /* @__PURE__ */ new Map();
317
+ detail(operation) {
318
+ let found = this.details.get(operation);
319
+ if (!found) {
320
+ found = this.callPublic(SEARCH_TOOL, { operation }).then((result) => parseOperationDetail(operation, result));
321
+ found.catch(() => this.details.delete(operation));
322
+ this.details.set(operation, found);
323
+ }
324
+ return found;
325
+ }
326
+ async call(operation, args) {
327
+ const detail = await this.detail(operation);
328
+ return this.callPublic(detail.executor, { operation, args });
329
+ }
330
+ };
331
+ function toolRefusal(asked, operation, result) {
332
+ const text = toolErrorText(result);
333
+ let code = "MCP_TOOL_ERROR";
334
+ try {
335
+ const parsed = JSON.parse(text);
336
+ if (isRecord4(parsed) && typeof parsed.code === "string" && parsed.code) code = parsed.code;
337
+ } catch {
338
+ }
339
+ return new OperationError(`search refused ${asked}: ${text}`, code, operation, result);
340
+ }
341
+ function isRecord4(value) {
342
+ return typeof value === "object" && value !== null && !Array.isArray(value);
343
+ }
344
+
233
345
  // src/core/mcp/rpcClient.ts
234
346
  var CHANNEL_HEADER = "X-AiNecto-Channel";
235
347
  var AGENT_HEADER = "X-AiNecto-Agent";
@@ -256,11 +368,16 @@ var McpRpcClient = class {
256
368
  constructor(options) {
257
369
  this.options = options;
258
370
  this.fetchImpl = options.fetchImpl ?? fetch;
371
+ this.operations = new OperationCaller((tool, args) => this.request("tools/call", { name: tool, arguments: args }));
259
372
  }
260
373
  options;
261
374
  fetchImpl;
262
375
  nextId = 1;
263
376
  agent;
377
+ /** operation → 실행 도구 — 상세(executor)는 이 연결에서 한 번만 묻는다. */
378
+ operations;
379
+ /** 서버가 공개한 도구 이름 — 진실원은 tools/list. 연결당 한 번(실패는 기억하지 않는다). */
380
+ publicTools;
264
381
  /**
265
382
  * 브리지 전용 — 호스트 에이전트가 보낸 {@code initialize} 의 {@code clientInfo.name}(프로그램 고정 이름).
266
383
  * 이후 모든 요청의 {@code X-AiNecto-Agent} 헤더로 싣는다. 직접 명령은 부르지 않는다(누가 셸을 돌렸는지 모른다).
@@ -277,13 +394,41 @@ var McpRpcClient = class {
277
394
  }
278
395
  async toolsList() {
279
396
  const result = await this.request("tools/list", {});
280
- if (!isRecord3(result) || !Array.isArray(result.tools)) {
397
+ if (!isRecord5(result) || !Array.isArray(result.tools)) {
281
398
  throw new McpRpcError("tools/list response did not include a tools array.", "MCP_PROTOCOL_ERROR", result);
282
399
  }
400
+ this.publicTools = Promise.resolve(toolNames(result.tools));
283
401
  return result.tools;
284
402
  }
403
+ /** 공개 도구 이름 — 이 연결에서 아직 모르면 tools/list 를 한 번 부른다. */
404
+ publicToolNames() {
405
+ if (!this.publicTools) {
406
+ const pending = this.toolsList().then(toolNames);
407
+ pending.catch(() => {
408
+ if (this.publicTools === pending) this.publicTools = void 0;
409
+ });
410
+ this.publicTools = pending;
411
+ }
412
+ return this.publicTools;
413
+ }
414
+ /**
415
+ * ★CLI 안의 모든 도구 호출이 지나는 한 입구. 서버 tools/list 에 있는 공개 도구(search·execute_*·open_ainecto_panel)는
416
+ * 자기 이름으로 한 번만, 그 밖의 이름은 operation 으로 보고 {@code <executor> {operation, args}} 로 바꿔 부른다(operations.ts)
417
+ * — 서버는 옛 108개 이름을 거절한다. 공개 이름의 사본은 두지 않는다(리뷰 r1 P1-3).
418
+ * 옛 {@code mcp__ainecto__} 앞머리는 뗀다. 브리지(sendRaw)는 이 길을 지나지 않는다 — 호스트가 고른 도구 그대로 간다.
419
+ */
285
420
  async toolsCall(name, args) {
286
- return this.request("tools/call", { name, arguments: args ?? {} });
421
+ const bare = bareToolName(name);
422
+ const payload = isRecord5(args) ? args : {};
423
+ return (await this.publicToolNames()).has(bare) ? this.request("tools/call", { name: bare, arguments: payload }) : this.operations.call(bare, payload);
424
+ }
425
+ /**
426
+ * {@link toolsCall} 가 이 이름을 부를 때 쓸 상세 — 공개 도구 이름이면 undefined(자기 이름으로 바로 간다).
427
+ * 같은 연결의 상세라 뒤이은 toolsCall 이 똑같은 것을 쓴다(실행 전 판단과 실행이 같은 사실을 본다).
428
+ */
429
+ async operationDetailFor(name) {
430
+ const bare = bareToolName(name);
431
+ return (await this.publicToolNames()).has(bare) ? void 0 : this.operations.detail(bare);
287
432
  }
288
433
  async request(method, params) {
289
434
  const response = await this.sendRaw({
@@ -370,7 +515,7 @@ var McpRpcClient = class {
370
515
  function rateLimitedResponse(text, retryAfter) {
371
516
  const envelope = rpcErrorEnvelope(text);
372
517
  if (envelope) {
373
- const data = isRecord3(envelope.error.data) ? envelope.error.data : {};
518
+ const data = isRecord5(envelope.error.data) ? envelope.error.data : {};
374
519
  const seconds = parseRetryAfter(retryAfter);
375
520
  if (data.retryAfterSeconds === void 0 && seconds !== void 0) {
376
521
  envelope.error.data = { ...data, retryAfterSeconds: seconds };
@@ -382,7 +527,7 @@ function rateLimitedResponse(text, retryAfter) {
382
527
  }
383
528
  function rpcErrorEnvelope(text) {
384
529
  const parsed = parseJsonOrUndefined(text);
385
- return isJsonRpcResponse(parsed) && "error" in parsed && isRecord3(parsed.error) ? parsed : void 0;
530
+ return isJsonRpcResponse(parsed) && "error" in parsed && isRecord5(parsed.error) ? parsed : void 0;
386
531
  }
387
532
  function parseJsonOrUndefined(text) {
388
533
  try {
@@ -392,8 +537,8 @@ function parseJsonOrUndefined(text) {
392
537
  }
393
538
  }
394
539
  function describeRpcError(error) {
395
- const data = isRecord3(error.data) ? error.data : {};
396
- const messages = isRecord3(data.messages) ? data.messages : {};
540
+ const data = isRecord5(error.data) ? error.data : {};
541
+ const messages = isRecord5(data.messages) ? data.messages : {};
397
542
  const sentence = [error.message, data.message, messages.en, messages.ko].find((value) => typeof value === "string" && value.trim() !== "");
398
543
  const code = typeof data.code === "string" && data.code.trim() ? data.code.trim() : void 0;
399
544
  if (!code) {
@@ -418,7 +563,7 @@ function parseServerError(body) {
418
563
  } catch {
419
564
  return void 0;
420
565
  }
421
- if (!isRecord3(parsed) || typeof parsed.error !== "string" || !parsed.error.trim()) {
566
+ if (!isRecord5(parsed) || typeof parsed.error !== "string" || !parsed.error.trim()) {
422
567
  return void 0;
423
568
  }
424
569
  return {
@@ -431,9 +576,12 @@ function describeServerError(serverError) {
431
576
  return line.replace(/\s+/g, " ").trim();
432
577
  }
433
578
  function isJsonRpcResponse(value) {
434
- return isRecord3(value) && value.jsonrpc === "2.0" && ("result" in value || "error" in value);
579
+ return isRecord5(value) && value.jsonrpc === "2.0" && ("result" in value || "error" in value);
435
580
  }
436
- function isRecord3(value) {
581
+ function toolNames(tools) {
582
+ return new Set(tools.flatMap((tool) => isRecord5(tool) && typeof tool.name === "string" ? [tool.name] : []));
583
+ }
584
+ function isRecord5(value) {
437
585
  return typeof value === "object" && value !== null && !Array.isArray(value);
438
586
  }
439
587
  function httpErrorDetails(status, body, envVars) {
@@ -564,7 +712,7 @@ var OAuthClient = class {
564
712
  };
565
713
  function generatePkcePair() {
566
714
  const codeVerifier = randomBytes(32).toString("base64url");
567
- const codeChallenge = createHash2("sha256").update(codeVerifier).digest("base64url");
715
+ const codeChallenge = createHash3("sha256").update(codeVerifier).digest("base64url");
568
716
  return { codeVerifier, codeChallenge };
569
717
  }
570
718
  function generateOAuthState() {
@@ -864,7 +1012,7 @@ var INVALID_REQUEST = -32600;
864
1012
  var INTERNAL_ERROR = -32603;
865
1013
  var RATE_LIMITED_CODE = 429;
866
1014
  function failure(id, code, error) {
867
- const data = error instanceof McpRpcError ? { code: error.code, ...isRecord4(error.details) ? error.details : {} } : void 0;
1015
+ const data = error instanceof McpRpcError ? { code: error.code, ...isRecord6(error.details) ? error.details : {} } : void 0;
868
1016
  return {
869
1017
  jsonrpc: "2.0",
870
1018
  id,
@@ -880,7 +1028,7 @@ function writeLine(output, message) {
880
1028
  }
881
1029
  function parseJsonRpcRequest(line) {
882
1030
  const parsed = JSON.parse(line);
883
- if (!isRecord4(parsed) || parsed.jsonrpc !== "2.0" || typeof parsed.method !== "string") {
1031
+ if (!isRecord6(parsed) || parsed.jsonrpc !== "2.0" || typeof parsed.method !== "string") {
884
1032
  throw new Error("Invalid JSON-RPC request.");
885
1033
  }
886
1034
  return {
@@ -891,9 +1039,9 @@ function parseJsonRpcRequest(line) {
891
1039
  };
892
1040
  }
893
1041
  function clientInfoName(params) {
894
- return isRecord4(params) && isRecord4(params.clientInfo) ? params.clientInfo.name : void 0;
1042
+ return isRecord6(params) && isRecord6(params.clientInfo) ? params.clientInfo.name : void 0;
895
1043
  }
896
- function isRecord4(value) {
1044
+ function isRecord6(value) {
897
1045
  return typeof value === "object" && value !== null && !Array.isArray(value);
898
1046
  }
899
1047
 
@@ -903,7 +1051,8 @@ var SERVER_NAME = "ainecto";
903
1051
  var REMOTE_SIGN_IN = {
904
1052
  "claude-code": `Claude Code \u2014 in a session, run /mcp, pick "${SERVER_NAME}" and sign in`,
905
1053
  cursor: `Cursor \u2014 sign in when "${SERVER_NAME}" asks for it in Cursor's MCP settings`,
906
- codex: `Codex \u2014 signs in while setup connects it (its sign-in link is printed above); if that did not finish, run \`codex mcp login ${SERVER_NAME}\``
1054
+ codex: `Codex \u2014 signs in while setup connects it (its sign-in link is printed above); if that did not finish, run \`codex mcp login ${SERVER_NAME}\``,
1055
+ antigravity: `Antigravity \u2014 open Customizations \u203A Installed \u203A MCP Servers, choose Authenticate for "${SERVER_NAME}" and sign in`
907
1056
  };
908
1057
 
909
1058
  // src/core/harness/harnessDoc.ts