@umbraco-cms/mcp-dev 18.1.7 → 18.1.9

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-OF7HVRKR.js";
13
13
 
14
14
  // node_modules/ajv/dist/compile/codegen/code.js
15
15
  var require_code = __commonJS({
@@ -4126,13 +4126,14 @@ var require_fast_uri = __commonJS({
4126
4126
  if (!malformedIPLiteral) {
4127
4127
  malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP);
4128
4128
  }
4129
- if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4130
- if (uri.indexOf("%") !== -1) {
4131
- if (parsed.host !== void 0 && !malformedIPLiteral) {
4132
- const host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true);
4133
- parsed.host = reescapeHostDelimiters(host, isIP);
4134
- }
4129
+ if (uri.indexOf("%") !== -1 && parsed.host !== void 0 && !malformedIPLiteral) {
4130
+ let host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true);
4131
+ if (!isIP) {
4132
+ host = normalizePercentEncoding(host.toLowerCase());
4135
4133
  }
4134
+ parsed.host = reescapeHostDelimiters(host, isIP);
4135
+ }
4136
+ if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
4136
4137
  if (parsed.path) {
4137
4138
  parsed.path = normalizePathEncoding(parsed.path);
4138
4139
  }
@@ -7262,17 +7263,33 @@ function normalizeObjectSchema(schema) {
7262
7263
  }
7263
7264
  return void 0;
7264
7265
  }
7266
+ function getDotPath(path) {
7267
+ if (path.length === 0) {
7268
+ return "object root";
7269
+ }
7270
+ return path.reduce((acc, seg, index) => {
7271
+ if (index === 0) {
7272
+ return String(seg);
7273
+ }
7274
+ if (typeof seg === "number") {
7275
+ return `${acc}[${seg}]`;
7276
+ }
7277
+ return `${acc}.${seg}`;
7278
+ }, "");
7279
+ }
7265
7280
  function getParseErrorMessage(error) {
7266
7281
  if (error && typeof error === "object") {
7282
+ if ("issues" in error && Array.isArray(error.issues) && error.issues.length > 0) {
7283
+ return error.issues.map((i) => {
7284
+ if (!i.path?.length) {
7285
+ return i.message;
7286
+ }
7287
+ return `${i.message} at ${getDotPath(i.path)}`;
7288
+ }).join("\n");
7289
+ }
7267
7290
  if ("message" in error && typeof error.message === "string") {
7268
7291
  return error.message;
7269
7292
  }
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
7293
  try {
7277
7294
  return JSON.stringify(error);
7278
7295
  } catch {
@@ -10236,6 +10253,9 @@ var Protocol = class {
10236
10253
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
10237
10254
  const handleTaskResult = async () => {
10238
10255
  const taskId = request.params.taskId;
10256
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
10257
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
10258
+ }
10239
10259
  if (this._taskMessageQueue) {
10240
10260
  let queuedMessage;
10241
10261
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -10266,12 +10286,12 @@ var Protocol = class {
10266
10286
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
10267
10287
  }
10268
10288
  if (!isTerminal(task.status)) {
10269
- await this._waitForTaskUpdate(taskId, extra.signal);
10289
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
10270
10290
  return await handleTaskResult();
10271
10291
  }
10272
10292
  if (isTerminal(task.status)) {
10273
10293
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
10274
- this._clearTaskQueue(taskId);
10294
+ this._clearTaskQueue(taskId, extra.sessionId);
10275
10295
  return {
10276
10296
  ...result,
10277
10297
  _meta: {
@@ -10308,7 +10328,7 @@ var Protocol = class {
10308
10328
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
10309
10329
  }
10310
10330
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
10311
- this._clearTaskQueue(request.params.taskId);
10331
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
10312
10332
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
10313
10333
  if (!cancelledTask) {
10314
10334
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -10436,6 +10456,19 @@ var Protocol = class {
10436
10456
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
10437
10457
  const capturedTransport = this._transport;
10438
10458
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
10459
+ const sessionId = capturedTransport?.sessionId;
10460
+ const store = this._taskStore;
10461
+ let relatedTaskFound = true;
10462
+ let relatedTaskLookup;
10463
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
10464
+ relatedTaskFound = false;
10465
+ relatedTaskLookup = (async () => {
10466
+ if (!await store.getTask(relatedTaskId, sessionId)) {
10467
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
10468
+ }
10469
+ relatedTaskFound = true;
10470
+ })();
10471
+ }
10439
10472
  if (handler === void 0) {
10440
10473
  const errorResponse = {
10441
10474
  jsonrpc: "2.0",
@@ -10445,7 +10478,10 @@ var Protocol = class {
10445
10478
  message: "Method not found"
10446
10479
  }
10447
10480
  };
10448
- if (relatedTaskId && this._taskMessageQueue) {
10481
+ if (relatedTaskId && relatedTaskLookup) {
10482
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
10483
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
10484
+ } else if (relatedTaskId && this._taskMessageQueue) {
10449
10485
  this._enqueueTaskMessage(relatedTaskId, {
10450
10486
  type: "error",
10451
10487
  message: errorResponse,
@@ -10496,7 +10532,10 @@ var Protocol = class {
10496
10532
  closeSSEStream: extra?.closeSSEStream,
10497
10533
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
10498
10534
  };
10499
- Promise.resolve().then(() => {
10535
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
10536
+ if (relatedTaskLookup && abortController.signal.aborted) {
10537
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
10538
+ }
10500
10539
  if (taskCreationParams) {
10501
10540
  this.assertTaskHandlerCapability(request.method);
10502
10541
  }
@@ -10531,7 +10570,7 @@ var Protocol = class {
10531
10570
  ...error["data"] !== void 0 && { data: error["data"] }
10532
10571
  }
10533
10572
  };
10534
- if (relatedTaskId && this._taskMessageQueue) {
10573
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
10535
10574
  await this._enqueueTaskMessage(relatedTaskId, {
10536
10575
  type: "error",
10537
10576
  message: errorResponse,
@@ -11011,7 +11050,7 @@ var Protocol = class {
11011
11050
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
11012
11051
  }
11013
11052
  const maxQueueSize = this._options?.maxTaskQueueSize;
11014
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
11053
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
11015
11054
  }
11016
11055
  /**
11017
11056
  * Clears the message queue for a task and rejects any pending request resolvers.
@@ -11040,12 +11079,13 @@ var Protocol = class {
11040
11079
  * Uses polling to check for updates at the task's configured poll interval.
11041
11080
  * @param taskId The task ID to wait for
11042
11081
  * @param signal Abort signal to cancel the wait
11082
+ * @param sessionId Session of the request that waits, passed to the task store
11043
11083
  * @returns Promise that resolves when an update occurs or rejects if aborted
11044
11084
  */
11045
- async _waitForTaskUpdate(taskId, signal) {
11085
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
11046
11086
  let interval = this._options?.defaultTaskPollInterval ?? 1e3;
11047
11087
  try {
11048
- const task = await this._taskStore?.getTask(taskId);
11088
+ const task = await this._taskStore?.getTask(taskId, sessionId);
11049
11089
  if (task?.pollInterval) {
11050
11090
  interval = task.pollInterval;
11051
11091
  }
@@ -11531,16 +11571,7 @@ var Server = class extends Protocol {
11531
11571
  if (!methodSchema) {
11532
11572
  throw new Error("Schema is missing a method literal");
11533
11573
  }
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
- }
11574
+ const methodValue = getLiteralValue(methodSchema);
11544
11575
  if (typeof methodValue !== "string") {
11545
11576
  throw new Error("Schema method literal must be a string");
11546
11577
  }
@@ -11934,6 +11965,42 @@ var ExperimentalMcpServerTasks = class {
11934
11965
 
11935
11966
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
11936
11967
  import { ZodOptional } from "zod";
11968
+ function toolInputElementCount(value, max) {
11969
+ let count = 0;
11970
+ const stack = [value];
11971
+ while (stack.length > 0) {
11972
+ const node = stack.pop();
11973
+ if (node === null || typeof node !== "object")
11974
+ continue;
11975
+ if (Array.isArray(node)) {
11976
+ for (const child of node) {
11977
+ if (++count > max)
11978
+ return count;
11979
+ if (child !== null && typeof child === "object")
11980
+ stack.push(child);
11981
+ }
11982
+ } else {
11983
+ for (const key in node) {
11984
+ if (!Object.prototype.hasOwnProperty.call(node, key))
11985
+ continue;
11986
+ if (++count > max)
11987
+ return count;
11988
+ const child = node[key];
11989
+ if (child !== null && typeof child === "object")
11990
+ stack.push(child);
11991
+ }
11992
+ }
11993
+ }
11994
+ return count;
11995
+ }
11996
+ function resolveMaxToolInputElements(value) {
11997
+ if (value === void 0 || value === Infinity)
11998
+ return void 0;
11999
+ if (typeof value !== "number" || Number.isNaN(value) || value < 1) {
12000
+ throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
12001
+ }
12002
+ return value;
12003
+ }
11937
12004
  var McpServer = class {
11938
12005
  constructor(serverInfo, options) {
11939
12006
  this._registeredResources = {};
@@ -11945,6 +12012,7 @@ var McpServer = class {
11945
12012
  this._resourceHandlersInitialized = false;
11946
12013
  this._promptHandlersInitialized = false;
11947
12014
  this.server = new Server(serverInfo, options);
12015
+ this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
11948
12016
  }
11949
12017
  /**
11950
12018
  * Access experimental features.
@@ -12075,12 +12143,15 @@ var McpServer = class {
12075
12143
  * Validates tool input arguments against the tool's input schema.
12076
12144
  */
12077
12145
  async validateToolInput(tool, args, toolName) {
12146
+ if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) {
12147
+ throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
12148
+ }
12078
12149
  if (!tool.inputSchema) {
12079
12150
  return void 0;
12080
12151
  }
12081
12152
  const inputObj = normalizeObjectSchema(tool.inputSchema);
12082
12153
  const schemaToParse = inputObj ?? tool.inputSchema;
12083
- const parseResult = await safeParseAsync2(schemaToParse, args);
12154
+ const parseResult = await safeParseAsync2(schemaToParse, args ?? {});
12084
12155
  if (!parseResult.success) {
12085
12156
  const error = "error" in parseResult ? parseResult.error : "Unknown error";
12086
12157
  const errorMessage = getParseErrorMessage(error);
@@ -12318,7 +12389,7 @@ var McpServer = class {
12318
12389
  }
12319
12390
  if (prompt.argsSchema) {
12320
12391
  const argsObj = normalizeObjectSchema(prompt.argsSchema);
12321
- const parseResult = await safeParseAsync2(argsObj, request.params.arguments);
12392
+ const parseResult = await safeParseAsync2(argsObj, request.params.arguments ?? {});
12322
12393
  if (!parseResult.success) {
12323
12394
  const error = "error" in parseResult ? parseResult.error : "Unknown error";
12324
12395
  const errorMessage = getParseErrorMessage(error);
@@ -12729,8 +12800,17 @@ var EMPTY_COMPLETION_RESULT = {
12729
12800
  import process2 from "process";
12730
12801
 
12731
12802
  // node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
12803
+ var STDIO_DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
12732
12804
  var ReadBuffer = class {
12805
+ constructor(options) {
12806
+ this._maxBufferSize = options?.maxBufferSize ?? STDIO_DEFAULT_MAX_BUFFER_SIZE;
12807
+ }
12733
12808
  append(chunk) {
12809
+ const newSize = (this._buffer?.length ?? 0) + chunk.length;
12810
+ if (newSize > this._maxBufferSize) {
12811
+ this.clear();
12812
+ throw new Error(`ReadBuffer exceeded maximum size of ${this._maxBufferSize} bytes`);
12813
+ }
12734
12814
  this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
12735
12815
  }
12736
12816
  readMessage() {
@@ -12758,18 +12838,24 @@ function serializeMessage(message) {
12758
12838
 
12759
12839
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
12760
12840
  var StdioServerTransport = class {
12761
- constructor(_stdin = process2.stdin, _stdout = process2.stdout) {
12841
+ constructor(_stdin = process2.stdin, _stdout = process2.stdout, options) {
12762
12842
  this._stdin = _stdin;
12763
12843
  this._stdout = _stdout;
12764
- this._readBuffer = new ReadBuffer();
12765
12844
  this._started = false;
12766
12845
  this._ondata = (chunk) => {
12767
- this._readBuffer.append(chunk);
12768
- this.processReadBuffer();
12846
+ try {
12847
+ this._readBuffer.append(chunk);
12848
+ this.processReadBuffer();
12849
+ } catch (error) {
12850
+ this.onerror?.(error);
12851
+ this.close().catch(() => {
12852
+ });
12853
+ }
12769
12854
  };
12770
12855
  this._onerror = (error) => {
12771
12856
  this.onerror?.(error);
12772
12857
  };
12858
+ this._readBuffer = new ReadBuffer({ maxBufferSize: options?.maxBufferSize });
12773
12859
  }
12774
12860
  /**
12775
12861
  * Starts listening for messages on stdin.
@@ -12820,7 +12906,7 @@ var StdioServerTransport = class {
12820
12906
  // package.json
12821
12907
  var package_default = {
12822
12908
  name: "@umbraco-cms/mcp-dev",
12823
- version: "18.1.7",
12909
+ version: "18.1.9",
12824
12910
  type: "module",
12825
12911
  description: "A model context protocol (MCP) server for Umbraco CMS",
12826
12912
  main: "dist/index.js",
@@ -12864,7 +12950,7 @@ var package_default = {
12864
12950
  "dev:hosted": "wrangler dev"
12865
12951
  },
12866
12952
  engines: {
12867
- node: ">=22.0.0"
12953
+ node: ">=22.3.0"
12868
12954
  },
12869
12955
  files: [
12870
12956
  "dist",
@@ -12892,8 +12978,8 @@ var package_default = {
12892
12978
  "@modelcontextprotocol/sdk": "^1.28.0",
12893
12979
  "@types/uuid": "^10.0.0",
12894
12980
  "@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",
12981
+ "@umbraco-cms/mcp-hosted": "^1.0.0-beta.46",
12982
+ "@umbraco-cms/mcp-server-sdk": "^1.0.0-beta.46",
12897
12983
  dotenv: "^16.5.0",
12898
12984
  "form-data": "^4.0.4",
12899
12985
  "mime-types": "^3.0.1",
@@ -13108,6 +13194,31 @@ var main = async () => {
13108
13194
  configureApiClient(() => UmbracoManagementClient.getClient());
13109
13195
  const client = UmbracoManagementClient.getClient();
13110
13196
  const user = await client.getUserCurrent();
13197
+ let serverInfo;
13198
+ let serverInfoError;
13199
+ try {
13200
+ serverInfo = await client.getServerInformation();
13201
+ } catch (error) {
13202
+ serverInfoError = error;
13203
+ }
13204
+ if (serverInfo) {
13205
+ setUmbracoVersion(serverInfo.version);
13206
+ }
13207
+ await checkUmbracoVersion({
13208
+ mcpVersion: package_default.version,
13209
+ // UMBRACO_TARGET_MAJOR is stamped into src/config/umbraco-target.generated.ts
13210
+ // by the orval target-major transformer, from the Umbraco instance the API
13211
+ // client was generated against. Override to point at a different major.
13212
+ // (`?.trim() ||`, not `??`: an env var set to an empty string must still
13213
+ // fall back, or the check silently no-ops with no log output at all.)
13214
+ expectedUmbracoMajor: process.env.UMBRACO_EXPECTED_MAJOR?.trim() || UMBRACO_TARGET_MAJOR,
13215
+ client: {
13216
+ getServerInformation: async () => {
13217
+ if (serverInfo) return serverInfo;
13218
+ throw serverInfoError ?? new Error("Unable to fetch Umbraco server information");
13219
+ }
13220
+ }
13221
+ });
13111
13222
  const rawConfig = await getServerConfig2(true);
13112
13223
  const configLoader2 = createCollectionConfigLoader2({
13113
13224
  modeRegistry: allModes,
@@ -13123,18 +13234,6 @@ var main = async () => {
13123
13234
  filterConfig,
13124
13235
  serverConfig: config
13125
13236
  });
13126
- const serverInfo = await client.getServerInformation();
13127
- setUmbracoVersion(serverInfo.version);
13128
- await checkUmbracoVersion({
13129
- mcpVersion: package_default.version,
13130
- // UMBRACO_TARGET_MAJOR is stamped into src/config/umbraco-target.generated.ts
13131
- // by the orval target-major transformer, from the Umbraco instance the API
13132
- // client was generated against. Override to point at a different major.
13133
- // (`?.trim() ||`, not `??`: an env var set to an empty string must still
13134
- // fall back, or the check silently no-ops with no log output at all.)
13135
- expectedUmbracoMajor: process.env.UMBRACO_EXPECTED_MAJOR?.trim() || UMBRACO_TARGET_MAJOR,
13136
- client: { getServerInformation: async () => serverInfo }
13137
- });
13138
13237
  configureVersionCheckHook();
13139
13238
  const versionCheckMessage = getVersionCheckMessage();
13140
13239
  const server = new McpServer(