@umbraco-cms/mcp-dev 18.1.7 → 18.1.8

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/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  availableCollections,
10
10
  setAllowFilePathUploads,
11
11
  setUmbracoVersion
12
- } from "./chunk-66TKBJQ7.js";
12
+ } from "./chunk-O6YXPPS2.js";
13
13
 
14
14
  // node_modules/ajv/dist/compile/codegen/code.js
15
15
  var require_code = __commonJS({
@@ -7262,17 +7262,33 @@ function normalizeObjectSchema(schema) {
7262
7262
  }
7263
7263
  return void 0;
7264
7264
  }
7265
+ function getDotPath(path) {
7266
+ if (path.length === 0) {
7267
+ return "object root";
7268
+ }
7269
+ return path.reduce((acc, seg, index) => {
7270
+ if (index === 0) {
7271
+ return String(seg);
7272
+ }
7273
+ if (typeof seg === "number") {
7274
+ return `${acc}[${seg}]`;
7275
+ }
7276
+ return `${acc}.${seg}`;
7277
+ }, "");
7278
+ }
7265
7279
  function getParseErrorMessage(error) {
7266
7280
  if (error && typeof error === "object") {
7281
+ if ("issues" in error && Array.isArray(error.issues) && error.issues.length > 0) {
7282
+ return error.issues.map((i) => {
7283
+ if (!i.path?.length) {
7284
+ return i.message;
7285
+ }
7286
+ return `${i.message} at ${getDotPath(i.path)}`;
7287
+ }).join("\n");
7288
+ }
7267
7289
  if ("message" in error && typeof error.message === "string") {
7268
7290
  return error.message;
7269
7291
  }
7270
- if ("issues" in error && Array.isArray(error.issues) && error.issues.length > 0) {
7271
- const firstIssue = error.issues[0];
7272
- if (firstIssue && typeof firstIssue === "object" && "message" in firstIssue) {
7273
- return String(firstIssue.message);
7274
- }
7275
- }
7276
7292
  try {
7277
7293
  return JSON.stringify(error);
7278
7294
  } catch {
@@ -10236,6 +10252,9 @@ var Protocol = class {
10236
10252
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
10237
10253
  const handleTaskResult = async () => {
10238
10254
  const taskId = request.params.taskId;
10255
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
10256
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
10257
+ }
10239
10258
  if (this._taskMessageQueue) {
10240
10259
  let queuedMessage;
10241
10260
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -10266,12 +10285,12 @@ var Protocol = class {
10266
10285
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
10267
10286
  }
10268
10287
  if (!isTerminal(task.status)) {
10269
- await this._waitForTaskUpdate(taskId, extra.signal);
10288
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
10270
10289
  return await handleTaskResult();
10271
10290
  }
10272
10291
  if (isTerminal(task.status)) {
10273
10292
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
10274
- this._clearTaskQueue(taskId);
10293
+ this._clearTaskQueue(taskId, extra.sessionId);
10275
10294
  return {
10276
10295
  ...result,
10277
10296
  _meta: {
@@ -10308,7 +10327,7 @@ var Protocol = class {
10308
10327
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
10309
10328
  }
10310
10329
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
10311
- this._clearTaskQueue(request.params.taskId);
10330
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
10312
10331
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
10313
10332
  if (!cancelledTask) {
10314
10333
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -10436,6 +10455,19 @@ var Protocol = class {
10436
10455
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
10437
10456
  const capturedTransport = this._transport;
10438
10457
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
10458
+ const sessionId = capturedTransport?.sessionId;
10459
+ const store = this._taskStore;
10460
+ let relatedTaskFound = true;
10461
+ let relatedTaskLookup;
10462
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
10463
+ relatedTaskFound = false;
10464
+ relatedTaskLookup = (async () => {
10465
+ if (!await store.getTask(relatedTaskId, sessionId)) {
10466
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
10467
+ }
10468
+ relatedTaskFound = true;
10469
+ })();
10470
+ }
10439
10471
  if (handler === void 0) {
10440
10472
  const errorResponse = {
10441
10473
  jsonrpc: "2.0",
@@ -10445,7 +10477,10 @@ var Protocol = class {
10445
10477
  message: "Method not found"
10446
10478
  }
10447
10479
  };
10448
- if (relatedTaskId && this._taskMessageQueue) {
10480
+ if (relatedTaskId && relatedTaskLookup) {
10481
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
10482
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
10483
+ } else if (relatedTaskId && this._taskMessageQueue) {
10449
10484
  this._enqueueTaskMessage(relatedTaskId, {
10450
10485
  type: "error",
10451
10486
  message: errorResponse,
@@ -10496,7 +10531,10 @@ var Protocol = class {
10496
10531
  closeSSEStream: extra?.closeSSEStream,
10497
10532
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
10498
10533
  };
10499
- Promise.resolve().then(() => {
10534
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
10535
+ if (relatedTaskLookup && abortController.signal.aborted) {
10536
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
10537
+ }
10500
10538
  if (taskCreationParams) {
10501
10539
  this.assertTaskHandlerCapability(request.method);
10502
10540
  }
@@ -10531,7 +10569,7 @@ var Protocol = class {
10531
10569
  ...error["data"] !== void 0 && { data: error["data"] }
10532
10570
  }
10533
10571
  };
10534
- if (relatedTaskId && this._taskMessageQueue) {
10572
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
10535
10573
  await this._enqueueTaskMessage(relatedTaskId, {
10536
10574
  type: "error",
10537
10575
  message: errorResponse,
@@ -11011,7 +11049,7 @@ var Protocol = class {
11011
11049
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
11012
11050
  }
11013
11051
  const maxQueueSize = this._options?.maxTaskQueueSize;
11014
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
11052
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
11015
11053
  }
11016
11054
  /**
11017
11055
  * Clears the message queue for a task and rejects any pending request resolvers.
@@ -11040,12 +11078,13 @@ var Protocol = class {
11040
11078
  * Uses polling to check for updates at the task's configured poll interval.
11041
11079
  * @param taskId The task ID to wait for
11042
11080
  * @param signal Abort signal to cancel the wait
11081
+ * @param sessionId Session of the request that waits, passed to the task store
11043
11082
  * @returns Promise that resolves when an update occurs or rejects if aborted
11044
11083
  */
11045
- async _waitForTaskUpdate(taskId, signal) {
11084
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
11046
11085
  let interval = this._options?.defaultTaskPollInterval ?? 1e3;
11047
11086
  try {
11048
- const task = await this._taskStore?.getTask(taskId);
11087
+ const task = await this._taskStore?.getTask(taskId, sessionId);
11049
11088
  if (task?.pollInterval) {
11050
11089
  interval = task.pollInterval;
11051
11090
  }
@@ -11531,16 +11570,7 @@ var Server = class extends Protocol {
11531
11570
  if (!methodSchema) {
11532
11571
  throw new Error("Schema is missing a method literal");
11533
11572
  }
11534
- let methodValue;
11535
- if (isZ4Schema(methodSchema)) {
11536
- const v4Schema = methodSchema;
11537
- const v4Def = v4Schema._zod?.def;
11538
- methodValue = v4Def?.value ?? v4Schema.value;
11539
- } else {
11540
- const v3Schema = methodSchema;
11541
- const legacyDef = v3Schema._def;
11542
- methodValue = legacyDef?.value ?? v3Schema.value;
11543
- }
11573
+ const methodValue = getLiteralValue(methodSchema);
11544
11574
  if (typeof methodValue !== "string") {
11545
11575
  throw new Error("Schema method literal must be a string");
11546
11576
  }
@@ -11934,6 +11964,42 @@ var ExperimentalMcpServerTasks = class {
11934
11964
 
11935
11965
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
11936
11966
  import { ZodOptional } from "zod";
11967
+ function toolInputElementCount(value, max) {
11968
+ let count = 0;
11969
+ const stack = [value];
11970
+ while (stack.length > 0) {
11971
+ const node = stack.pop();
11972
+ if (node === null || typeof node !== "object")
11973
+ continue;
11974
+ if (Array.isArray(node)) {
11975
+ for (const child of node) {
11976
+ if (++count > max)
11977
+ return count;
11978
+ if (child !== null && typeof child === "object")
11979
+ stack.push(child);
11980
+ }
11981
+ } else {
11982
+ for (const key in node) {
11983
+ if (!Object.prototype.hasOwnProperty.call(node, key))
11984
+ continue;
11985
+ if (++count > max)
11986
+ return count;
11987
+ const child = node[key];
11988
+ if (child !== null && typeof child === "object")
11989
+ stack.push(child);
11990
+ }
11991
+ }
11992
+ }
11993
+ return count;
11994
+ }
11995
+ function resolveMaxToolInputElements(value) {
11996
+ if (value === void 0 || value === Infinity)
11997
+ return void 0;
11998
+ if (typeof value !== "number" || Number.isNaN(value) || value < 1) {
11999
+ throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
12000
+ }
12001
+ return value;
12002
+ }
11937
12003
  var McpServer = class {
11938
12004
  constructor(serverInfo, options) {
11939
12005
  this._registeredResources = {};
@@ -11945,6 +12011,7 @@ var McpServer = class {
11945
12011
  this._resourceHandlersInitialized = false;
11946
12012
  this._promptHandlersInitialized = false;
11947
12013
  this.server = new Server(serverInfo, options);
12014
+ this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
11948
12015
  }
11949
12016
  /**
11950
12017
  * Access experimental features.
@@ -12075,12 +12142,15 @@ var McpServer = class {
12075
12142
  * Validates tool input arguments against the tool's input schema.
12076
12143
  */
12077
12144
  async validateToolInput(tool, args, toolName) {
12145
+ if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) {
12146
+ throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
12147
+ }
12078
12148
  if (!tool.inputSchema) {
12079
12149
  return void 0;
12080
12150
  }
12081
12151
  const inputObj = normalizeObjectSchema(tool.inputSchema);
12082
12152
  const schemaToParse = inputObj ?? tool.inputSchema;
12083
- const parseResult = await safeParseAsync2(schemaToParse, args);
12153
+ const parseResult = await safeParseAsync2(schemaToParse, args ?? {});
12084
12154
  if (!parseResult.success) {
12085
12155
  const error = "error" in parseResult ? parseResult.error : "Unknown error";
12086
12156
  const errorMessage = getParseErrorMessage(error);
@@ -12318,7 +12388,7 @@ var McpServer = class {
12318
12388
  }
12319
12389
  if (prompt.argsSchema) {
12320
12390
  const argsObj = normalizeObjectSchema(prompt.argsSchema);
12321
- const parseResult = await safeParseAsync2(argsObj, request.params.arguments);
12391
+ const parseResult = await safeParseAsync2(argsObj, request.params.arguments ?? {});
12322
12392
  if (!parseResult.success) {
12323
12393
  const error = "error" in parseResult ? parseResult.error : "Unknown error";
12324
12394
  const errorMessage = getParseErrorMessage(error);
@@ -12729,8 +12799,17 @@ var EMPTY_COMPLETION_RESULT = {
12729
12799
  import process2 from "process";
12730
12800
 
12731
12801
  // node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
12802
+ var STDIO_DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
12732
12803
  var ReadBuffer = class {
12804
+ constructor(options) {
12805
+ this._maxBufferSize = options?.maxBufferSize ?? STDIO_DEFAULT_MAX_BUFFER_SIZE;
12806
+ }
12733
12807
  append(chunk) {
12808
+ const newSize = (this._buffer?.length ?? 0) + chunk.length;
12809
+ if (newSize > this._maxBufferSize) {
12810
+ this.clear();
12811
+ throw new Error(`ReadBuffer exceeded maximum size of ${this._maxBufferSize} bytes`);
12812
+ }
12734
12813
  this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
12735
12814
  }
12736
12815
  readMessage() {
@@ -12758,18 +12837,24 @@ function serializeMessage(message) {
12758
12837
 
12759
12838
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
12760
12839
  var StdioServerTransport = class {
12761
- constructor(_stdin = process2.stdin, _stdout = process2.stdout) {
12840
+ constructor(_stdin = process2.stdin, _stdout = process2.stdout, options) {
12762
12841
  this._stdin = _stdin;
12763
12842
  this._stdout = _stdout;
12764
- this._readBuffer = new ReadBuffer();
12765
12843
  this._started = false;
12766
12844
  this._ondata = (chunk) => {
12767
- this._readBuffer.append(chunk);
12768
- this.processReadBuffer();
12845
+ try {
12846
+ this._readBuffer.append(chunk);
12847
+ this.processReadBuffer();
12848
+ } catch (error) {
12849
+ this.onerror?.(error);
12850
+ this.close().catch(() => {
12851
+ });
12852
+ }
12769
12853
  };
12770
12854
  this._onerror = (error) => {
12771
12855
  this.onerror?.(error);
12772
12856
  };
12857
+ this._readBuffer = new ReadBuffer({ maxBufferSize: options?.maxBufferSize });
12773
12858
  }
12774
12859
  /**
12775
12860
  * Starts listening for messages on stdin.
@@ -12820,7 +12905,7 @@ var StdioServerTransport = class {
12820
12905
  // package.json
12821
12906
  var package_default = {
12822
12907
  name: "@umbraco-cms/mcp-dev",
12823
- version: "18.1.7",
12908
+ version: "18.1.8",
12824
12909
  type: "module",
12825
12910
  description: "A model context protocol (MCP) server for Umbraco CMS",
12826
12911
  main: "dist/index.js",
@@ -12892,8 +12977,8 @@ var package_default = {
12892
12977
  "@modelcontextprotocol/sdk": "^1.28.0",
12893
12978
  "@types/uuid": "^10.0.0",
12894
12979
  "@types/yargs": "^17.0.33",
12895
- "@umbraco-cms/mcp-hosted": "^1.0.0-beta.41",
12896
- "@umbraco-cms/mcp-server-sdk": "^1.0.0-beta.41",
12980
+ "@umbraco-cms/mcp-hosted": "^1.0.0-beta.45",
12981
+ "@umbraco-cms/mcp-server-sdk": "^1.0.0-beta.45",
12897
12982
  dotenv: "^16.5.0",
12898
12983
  "form-data": "^4.0.4",
12899
12984
  "mime-types": "^3.0.1",