agentinit 1.2.1 → 1.4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ # [1.4.0](https://github.com/agentinit/agentinit/compare/v1.3.0...v1.4.0) (2025-09-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * address comments ([b4a63e7](https://github.com/agentinit/agentinit/commit/b4a63e79b376d059e2403ad396b779912e8ca50e))
7
+ * dirty fix with token calcs ([e7d3ef9](https://github.com/agentinit/agentinit/commit/e7d3ef98ea700937f2ccbd448ff18da02e65d1cd))
8
+ * **mcp:** improve token calculation accuracy for different schema types ([6f85f8b](https://github.com/agentinit/agentinit/commit/6f85f8b8448e8a391029f7bd50f975be5818ff7e))
9
+ * **mcp:** use minified JSON to prevent token inflation ([c5885c2](https://github.com/agentinit/agentinit/commit/c5885c277ac920781919178786386130b04b7633))
10
+
11
+
12
+ ### Features
13
+
14
+ * improve token calc ([107a8d7](https://github.com/agentinit/agentinit/commit/107a8d7b5b849a7dfc4dd776474c7d0bcd11c179))
15
+ * **mcp:** significantly improve token calculation accuracy ([c7c5137](https://github.com/agentinit/agentinit/commit/c7c51377565e2ab110262c859d05a988a39a80ee))
16
+
17
+ # [1.3.0](https://github.com/agentinit/agentinit/compare/v1.2.1...v1.3.0) (2025-09-24)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * address review comments ([e337f07](https://github.com/agentinit/agentinit/commit/e337f072bd41794756c72a3cdba96ebaff033e5f))
23
+ * address review comments ([6be5b93](https://github.com/agentinit/agentinit/commit/6be5b937ec6fcbf924ea93f378156ba44a46b9d5))
24
+
25
+
26
+ ### Features
27
+
28
+ * centralize constants and add timeout support to apply command ([d35a6fc](https://github.com/agentinit/agentinit/commit/d35a6fc2dd76923c82ca7f26b4503260f25e944f))
29
+
1
30
  ## [1.2.1](https://github.com/agentinit/agentinit/compare/v1.2.0...v1.2.1) (2025-09-20)
2
31
 
3
32
 
package/README.md CHANGED
@@ -94,25 +94,16 @@ agentinit mcp --install <name> # Install specific MCP
94
94
 
95
95
  ### `agentinit verify_mcp`
96
96
 
97
- Verify MCP server installations and list their capabilities.
98
-
99
- ```bash
100
- agentinit verify_mcp --all # Verify all configured MCP servers
101
- agentinit verify_mcp --mcp-name <name> # Verify specific MCP server
102
- ```
97
+ Verify MCP server installations and get their tools with token usage.
103
98
 
104
99
  **Examples:**
105
100
  ```bash
106
101
  # Verify all MCPs in project
107
102
  agentinit verify_mcp --all
108
-
109
- # Verify specific server
110
- agentinit verify_mcp --mcp-name everything
111
-
112
- # Test MCP configuration directly
103
+ # Verify STDIO server
113
104
  agentinit verify_mcp --mcp-stdio everything "npx -y @modelcontextprotocol/server-everything"
114
-
115
- agentinit verify_mcp --mcp-http
105
+ # Verify HTTP server
106
+ agentinit verify_mcp --mcp-http notion_api "https://mcp.notion.com/mcp" --timeout 30000
116
107
  ```
117
108
 
118
109
  Shows connection status, response time, and available tools/resources/prompts for each MCP server.
@@ -181,7 +172,13 @@ This generates `.agentinit/agentinit.toml` with your MCP configurations.
181
172
  - `--header "KEY:VALUE"` - Adds custom headers in KEY:VALUE format (can be used multiple times)
182
173
  - Both flags can be combined for APIs requiring multiple authentication methods
183
174
 
184
- **MCP Verification**: Use the `--verify-mcp` flag to test MCP servers immediately after configuration. This ensures servers are reachable and shows their available tools, resources, and prompts.
175
+ **MCP Verification**: Use the `--verify-mcp` flag to test MCP servers immediately after configuration. This ensures servers are reachable and shows their available tools, resources, and prompts. Use `--timeout <ms>` to set a custom connection timeout (default: 30000ms).
176
+
177
+ ```bash
178
+ # Verify with custom timeout
179
+ npx agentinit apply --verify-mcp --timeout 30000 \
180
+ --mcp-stdio chrome-mcp "bunx -y chrome-devtools-mcp@latest"
181
+ ```
185
182
 
186
183
  #### Rules Configuration
187
184
 
Binary file
package/dist/index.js CHANGED
@@ -22985,16 +22985,48 @@ class MCPParser {
22985
22985
  }
22986
22986
  }
22987
22987
 
22988
+ // src/constants/mcp.ts
22989
+ import {readFileSync} from "fs";
22990
+ import {fileURLToPath} from "url";
22991
+ import {dirname as dirname3, join as join2} from "path";
22992
+ var getPackageVersion = function() {
22993
+ try {
22994
+ const __filename2 = fileURLToPath(import.meta.url);
22995
+ const __dirname2 = dirname3(__filename2);
22996
+ const packageJsonPath = join2(__dirname2, "../../package.json");
22997
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
22998
+ return packageJson.version || "1.0.0";
22999
+ } catch {
23000
+ return "1.0.0";
23001
+ }
23002
+ };
23003
+ var DEFAULT_CONNECTION_TIMEOUT_MS = 30000;
23004
+ var MCP_VERIFIER_CONFIG = {
23005
+ name: "agentinit-verifier",
23006
+ version: getPackageVersion()
23007
+ };
23008
+
23009
+ class TimeoutError extends Error {
23010
+ constructor(message) {
23011
+ super(message);
23012
+ this.name = "TimeoutError";
23013
+ }
23014
+ }
23015
+ // src/constants/tokens.ts
23016
+ var TOKEN_COUNT_THRESHOLDS = {
23017
+ LOW: 5000,
23018
+ MEDIUM: 15000
23019
+ };
22988
23020
  // src/core/rulesParser.ts
22989
- import {readFileSync as readFileSync2} from "fs";
23021
+ import {readFileSync as readFileSync3} from "fs";
22990
23022
 
22991
23023
  // src/core/rulesTemplateLoader.ts
22992
23024
  var toml = __toESM(require_toml(), 1);
22993
- import {resolve as resolve5, dirname as dirname3} from "path";
22994
- import {fileURLToPath} from "url";
22995
- import {readFileSync, readdirSync, existsSync} from "fs";
22996
- var __filename2 = fileURLToPath(import.meta.url);
22997
- var __dirname2 = dirname3(__filename2);
23025
+ import {resolve as resolve5, dirname as dirname4} from "path";
23026
+ import {fileURLToPath as fileURLToPath2} from "url";
23027
+ import {readFileSync as readFileSync2, readdirSync, existsSync} from "fs";
23028
+ var __filename2 = fileURLToPath2(import.meta.url);
23029
+ var __dirname2 = dirname4(__filename2);
22998
23030
 
22999
23031
  class RulesTemplateLoader {
23000
23032
  templatesPath;
@@ -23011,7 +23043,7 @@ class RulesTemplateLoader {
23011
23043
  for (const file of files) {
23012
23044
  try {
23013
23045
  const filePath = resolve5(this.templatesPath, file);
23014
- const content = readFileSync(filePath, "utf-8");
23046
+ const content = readFileSync2(filePath, "utf-8");
23015
23047
  const parsed = toml.default.parse(content);
23016
23048
  const template = {
23017
23049
  id: parsed.template.id,
@@ -23159,7 +23191,7 @@ class RulesParser {
23159
23191
  throw new RulesParseError(`Rules file not found: ${filePath}`);
23160
23192
  }
23161
23193
  try {
23162
- const content = readFileSync2(filePath, "utf-8");
23194
+ const content = readFileSync3(filePath, "utf-8");
23163
23195
  if (filePath.endsWith(".json")) {
23164
23196
  const parsed = JSON.parse(content);
23165
23197
  return this.extractRulesFromObject(parsed);
@@ -23185,12 +23217,17 @@ class RulesParser {
23185
23217
  }
23186
23218
  }
23187
23219
  const controller = new AbortController;
23188
- const timeoutId = setTimeout(() => controller.abort(), options2.timeout || 1e4);
23189
- const response = await fetch(options2.url, {
23190
- headers,
23191
- signal: controller.signal
23192
- });
23193
- clearTimeout(timeoutId);
23220
+ const timeoutMs = options2.timeout ?? DEFAULT_CONNECTION_TIMEOUT_MS;
23221
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
23222
+ let response;
23223
+ try {
23224
+ response = await fetch(options2.url, {
23225
+ headers,
23226
+ signal: controller.signal
23227
+ });
23228
+ } finally {
23229
+ clearTimeout(timeoutId);
23230
+ }
23194
23231
  if (!response.ok) {
23195
23232
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
23196
23233
  }
@@ -23395,7 +23432,7 @@ class TOMLGenerator {
23395
23432
  import {resolve as resolve8} from "path";
23396
23433
 
23397
23434
  // src/utils/paths.ts
23398
- import {resolve as resolve6, join as join2} from "path";
23435
+ import {resolve as resolve6, join as join3} from "path";
23399
23436
  import {homedir} from "os";
23400
23437
  function getHomeDirectory() {
23401
23438
  return homedir();
@@ -23414,7 +23451,7 @@ function getPlatform() {
23414
23451
  }
23415
23452
  function expandTilde(path) {
23416
23453
  if (path.startsWith("~/")) {
23417
- return join2(getHomeDirectory(), path.slice(2));
23454
+ return join3(getHomeDirectory(), path.slice(2));
23418
23455
  }
23419
23456
  if (path === "~") {
23420
23457
  return getHomeDirectory();
@@ -32236,37 +32273,50 @@ class MCPVerificationError extends Error {
32236
32273
  }
32237
32274
  }
32238
32275
 
32239
- class TimeoutError extends Error {
32240
- constructor(message) {
32241
- super(message);
32242
- this.name = "TimeoutError";
32243
- }
32244
- }
32245
-
32246
32276
  class MCPVerifier {
32247
32277
  defaultTimeout;
32248
- constructor(defaultTimeout = 1e4) {
32278
+ constructor(defaultTimeout = DEFAULT_CONNECTION_TIMEOUT_MS) {
32249
32279
  this.defaultTimeout = defaultTimeout;
32250
32280
  }
32251
32281
  colorizeTokenCount(tokenCount) {
32252
- if (tokenCount <= 5000)
32282
+ if (tokenCount <= TOKEN_COUNT_THRESHOLDS.LOW)
32253
32283
  return green(tokenCount.toString());
32254
- if (tokenCount <= 15000)
32284
+ if (tokenCount <= TOKEN_COUNT_THRESHOLDS.MEDIUM)
32255
32285
  return yellow(tokenCount.toString());
32256
32286
  return red(tokenCount.toString());
32257
32287
  }
32258
- calculateToolTokens(tools) {
32288
+ calculateToolTokens(tools, serverName) {
32259
32289
  const toolTokenCounts = new Map;
32260
32290
  let totalToolTokens = 0;
32261
32291
  for (const tool of tools) {
32262
32292
  try {
32293
+ const rawSchema = tool.inputSchema && typeof tool.inputSchema === "object" ? tool.inputSchema : undefined;
32294
+ const schemaType = rawSchema?.type;
32295
+ const parameters = {
32296
+ $schema: "http://json-schema.org/draft-07/schema#",
32297
+ ...rawSchema ?? {}
32298
+ };
32299
+ const hasObjectHints = rawSchema !== undefined && ["properties", "required", "additionalProperties", "patternProperties"].some((key) => (key in rawSchema));
32300
+ const isObjectSchema = rawSchema === undefined || schemaType === "object" || Array.isArray(schemaType) && schemaType.includes("object") || hasObjectHints;
32301
+ if (isObjectSchema) {
32302
+ if (!("type" in parameters))
32303
+ parameters.type = "object";
32304
+ if (!("properties" in parameters))
32305
+ parameters.properties = {};
32306
+ if (!("required" in parameters))
32307
+ parameters.required = [];
32308
+ if (!("additionalProperties" in parameters))
32309
+ parameters.additionalProperties = false;
32310
+ }
32311
+ const prefixedToolName = `mcp__${serverName}__${tool.name}`;
32263
32312
  const toolForCounting = {
32264
- name: tool.name,
32265
- description: tool.description || "",
32266
- inputSchema: tool.inputSchema || {}
32313
+ name: prefixedToolName,
32314
+ ...tool.description !== undefined ? { description: tool.description } : {},
32315
+ parameters
32267
32316
  };
32268
- const toolText = JSON.stringify(toolForCounting, null, 2);
32269
- const tokenCount = countTokens(toolText);
32317
+ const functionDefinition = JSON.stringify(toolForCounting);
32318
+ const claudeToolRepresentation = `<function>${functionDefinition}</function>`;
32319
+ const tokenCount = countTokens(claudeToolRepresentation) * 3;
32270
32320
  toolTokenCounts.set(tool.name, tokenCount);
32271
32321
  totalToolTokens += tokenCount;
32272
32322
  } catch (error) {
@@ -32285,8 +32335,8 @@ class MCPVerifier {
32285
32335
  try {
32286
32336
  transport = await this.createTransport(server);
32287
32337
  client2 = new Client({
32288
- name: "agentinit-verifier",
32289
- version: "1.0.0"
32338
+ name: MCP_VERIFIER_CONFIG.name,
32339
+ version: MCP_VERIFIER_CONFIG.version
32290
32340
  });
32291
32341
  const timeoutPromise = new Promise((_, reject) => {
32292
32342
  const timeoutId = setTimeout(async () => {
@@ -32459,7 +32509,7 @@ class MCPVerifier {
32459
32509
  }));
32460
32510
  } catch (error) {
32461
32511
  }
32462
- const { toolTokenCounts, totalToolTokens } = this.calculateToolTokens(tools);
32512
+ const { toolTokenCounts, totalToolTokens } = this.calculateToolTokens(tools, server.name);
32463
32513
  return {
32464
32514
  tools,
32465
32515
  resources,
@@ -32542,12 +32592,10 @@ class MCPVerifier {
32542
32592
 
32543
32593
  // src/commands/apply.ts
32544
32594
  var colorizeTokenCount = function(tokenCount) {
32545
- if (tokenCount <= 5000)
32595
+ if (tokenCount <= TOKEN_COUNT_THRESHOLDS.LOW)
32546
32596
  return green(tokenCount.toString());
32547
- if (tokenCount <= 15000)
32597
+ if (tokenCount <= TOKEN_COUNT_THRESHOLDS.MEDIUM)
32548
32598
  return yellow(tokenCount.toString());
32549
- if (tokenCount <= 30000)
32550
- return red(tokenCount.toString());
32551
32599
  return red(tokenCount.toString());
32552
32600
  };
32553
32601
  var colorizeTokenDiff = function(diff) {
@@ -32566,6 +32614,10 @@ async function applyCommand(args) {
32566
32614
  const specifiedClient = clientArgIndex >= 0 && clientArgIndex + 1 < args.length ? args[clientArgIndex + 1] : null;
32567
32615
  const isGlobal = args.includes("--global");
32568
32616
  const verifyMcp = args.includes("--verify-mcp");
32617
+ const timeoutIndex = args.findIndex((arg) => arg === "--timeout");
32618
+ const timeoutArg = timeoutIndex >= 0 && timeoutIndex + 1 < args.length ? args[timeoutIndex + 1] : null;
32619
+ const parsedTimeout = timeoutArg ? parseInt(timeoutArg, 10) : NaN;
32620
+ const timeout = timeoutArg && Number.isFinite(parsedTimeout) && parsedTimeout > 0 ? parsedTimeout : undefined;
32569
32621
  if (!hasMcpArgs && !hasRulesArgs) {
32570
32622
  logger.info("Usage: agentinit apply [options]");
32571
32623
  logger.info("");
@@ -32575,6 +32627,7 @@ async function applyCommand(args) {
32575
32627
  logger.info(" --global Apply configuration globally (requires --agent)");
32576
32628
  logger.info(" If not specified, auto-detects agents in the project");
32577
32629
  logger.info(" --verify-mcp Verify MCP servers after configuration");
32630
+ logger.info(` --timeout <ms> Connection timeout in milliseconds for MCP verification (default: ${DEFAULT_CONNECTION_TIMEOUT_MS})`);
32578
32631
  logger.info("");
32579
32632
  logger.info("Rules Configuration Options:");
32580
32633
  logger.info(" --rules <templates> Apply rule templates (comma-separated)");
@@ -32631,11 +32684,11 @@ async function applyCommand(args) {
32631
32684
  const spinner = ora("Parsing configurations...").start();
32632
32685
  try {
32633
32686
  const mcpArgs = args.filter((arg, index) => {
32634
- if (arg === "--client" || arg === "--agent" || arg === "--global" || arg === "--verify-mcp")
32687
+ if (arg === "--client" || arg === "--agent" || arg === "--global" || arg === "--verify-mcp" || arg === "--timeout")
32635
32688
  return false;
32636
32689
  if (arg === "--rules" || arg === "--rule-raw" || arg === "--rules-file" || arg === "--rules-remote")
32637
32690
  return false;
32638
- if (index > 0 && (args[index - 1] === "--client" || args[index - 1] === "--agent"))
32691
+ if (index > 0 && (args[index - 1] === "--client" || args[index - 1] === "--agent" || args[index - 1] === "--timeout"))
32639
32692
  return false;
32640
32693
  if (index > 0 && (args[index - 1] === "--rules" || args[index - 1] === "--rule-raw" || args[index - 1] === "--rules-file" || args[index - 1] === "--rules-remote"))
32641
32694
  return false;
@@ -32786,8 +32839,8 @@ async function applyCommand(args) {
32786
32839
  logger.info("");
32787
32840
  const verifySpinner = ora(`Verifying ${mcpParsed.servers.length} MCP server(s)...`).start();
32788
32841
  try {
32789
- const verifier = new MCPVerifier;
32790
- const verificationResults = await verifier.verifyServers(mcpParsed.servers);
32842
+ const verifier = new MCPVerifier(timeout);
32843
+ const verificationResults = await verifier.verifyServers(mcpParsed.servers, timeout);
32791
32844
  const successCount = verificationResults.filter((r) => r.status === "success").length;
32792
32845
  const errorCount = verificationResults.filter((r) => r.status === "error").length;
32793
32846
  const timeoutCount = verificationResults.filter((r) => r.status === "timeout").length;
@@ -32821,7 +32874,17 @@ async function applyCommand(args) {
32821
32874
  if (server.type === "stdio" && server.command) {
32822
32875
  logger.info(` Command: ${server.command} ${server.args?.join(" ") || ""}`);
32823
32876
  } else if (server.url) {
32824
- logger.info(` URL: ${server.url}`);
32877
+ let sanitizedUrl;
32878
+ try {
32879
+ const parsedUrl = new URL(server.url);
32880
+ parsedUrl.username = "";
32881
+ parsedUrl.password = "";
32882
+ parsedUrl.search = "";
32883
+ sanitizedUrl = parsedUrl.toString();
32884
+ } catch {
32885
+ sanitizedUrl = server.url.split("?")[0] || "invalid-url";
32886
+ }
32887
+ logger.info(` URL: ${sanitizedUrl}`);
32825
32888
  }
32826
32889
  });
32827
32890
  }
@@ -32937,7 +33000,7 @@ async function verifyMcpCommand(args) {
32937
33000
  const timeoutIndex = args.findIndex((arg) => arg === "--timeout");
32938
33001
  const timeoutArg = timeoutIndex >= 0 && timeoutIndex + 1 < args.length ? args[timeoutIndex + 1] : null;
32939
33002
  const parsedTimeout = timeoutArg ? parseInt(timeoutArg, 10) : NaN;
32940
- const timeout = timeoutArg && !Number.isNaN(parsedTimeout) && Number.isFinite(parsedTimeout) ? parsedTimeout : undefined;
33003
+ const timeout = timeoutArg && Number.isFinite(parsedTimeout) && parsedTimeout > 0 ? parsedTimeout : undefined;
32941
33004
  const hasMcpArgs = args.some((arg) => arg.startsWith("--mcp-"));
32942
33005
  if (mcpName && hasAll) {
32943
33006
  logger.error("Cannot use --mcp-name and --all together. Choose one option.");
@@ -32953,7 +33016,7 @@ async function verifyMcpCommand(args) {
32953
33016
  logger.info("Verify existing configurations:");
32954
33017
  logger.info(" --mcp-name <name> Verify specific MCP server by name");
32955
33018
  logger.info(" --all Verify all configured MCP servers");
32956
- logger.info(" --timeout <ms> Connection timeout in milliseconds (default: 10000)");
33019
+ logger.info(` --timeout <ms> Connection timeout in milliseconds (default: ${DEFAULT_CONNECTION_TIMEOUT_MS})`);
32957
33020
  logger.info("");
32958
33021
  logger.info("Verify direct MCP configuration:");
32959
33022
  logger.info(" --mcp-stdio <name> <command> Verify STDIO MCP server");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentinit",
3
- "version": "1.2.1",
3
+ "version": "1.4.0",
4
4
  "description": "A CLI tool for managing and configuring AI coding agents",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
Binary file