toolnexus 0.27.0 → 0.29.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/src/index.ts CHANGED
@@ -8,6 +8,7 @@ export * from "./native.js"
8
8
  export * from "./http.js"
9
9
  export * from "./a2a.js"
10
10
  export * from "./acp.js"
11
+ export * from "./transcript_search.js"
11
12
  export * from "./serve.js"
12
13
  export * from "./mcpserve.js"
13
14
  export * from "./mcphandler.js"
package/src/mcp.ts CHANGED
@@ -6,6 +6,8 @@
6
6
  import { readFileSync } from "node:fs"
7
7
  import { Client } from "@modelcontextprotocol/sdk/client/index.js"
8
8
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
9
+ import { AjvJsonSchemaValidator } from "@modelcontextprotocol/sdk/validation/ajv"
10
+ import type { jsonSchemaValidator } from "@modelcontextprotocol/sdk/validation"
9
11
  import { AdoptedStdioTransport } from "./mcp2026/stdio.js"
10
12
  import type { Tool as McpToolDef, ElicitRequest, ElicitResult } from "@modelcontextprotocol/sdk/types.js"
11
13
  import { ElicitRequestSchema } from "@modelcontextprotocol/sdk/types.js"
@@ -464,8 +466,23 @@ function resourceTools(servers: Map<string, ServerConn>): Tool[] {
464
466
  * exists. Separated from connect so the caller ALWAYS holds a closeable reference — even if the
465
467
  * connect is later abandoned by a timeout/abort, `client.close()` still terminates any spawned
466
468
  * stdio child (no orphaned processes on cancellation). */
469
+ /**
470
+ * The SDK's default validator, built on first use instead of per Client. Building an Ajv instance
471
+ * (meta-schemas + formats) costs ~2-3 ms on every connect, yet it is only consulted when a tool
472
+ * declares an `outputSchema`. Same validator, same results — just not paid for up front.
473
+ */
474
+ class LazyAjvValidator implements jsonSchemaValidator {
475
+ private inner?: AjvJsonSchemaValidator
476
+ getValidator<T>(schema: Parameters<jsonSchemaValidator["getValidator"]>[0]) {
477
+ return (this.inner ??= new AjvJsonSchemaValidator()).getValidator<T>(schema)
478
+ }
479
+ }
480
+
467
481
  function newMcpClient(waitFor?: (request: Request) => Promise<Answer>): Client {
468
- const client = new Client({ name: "toolnexus", version: "0.1.0" }, { capabilities: waitFor ? { elicitation: {} } : {} })
482
+ const client = new Client(
483
+ { name: "toolnexus", version: "0.1.0" },
484
+ { capabilities: waitFor ? { elicitation: {} } : {}, jsonSchemaValidator: new LazyAjvValidator() },
485
+ )
469
486
  if (waitFor) {
470
487
  client.setRequestHandler(ElicitRequestSchema, async (request) =>
471
488
  answerToElicitResult(await waitFor(elicitationToRequest(request.params))),