@costgate/momentum-mcp 0.2.2 → 0.2.4
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/README.md +2 -2
- package/momentum-mcp.mjs +92 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ MOMENTUM_TOKEN=mom_agent_xxx \
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
整条命令不用自己拼 —— 在 Momentum 的「设置 › Agent」里签发令牌时会直接给出,
|
|
12
|
-
默认用 `@latest`,发新版不用改配置;想固定某一版时把 latest 换成版本号(当前是 0.2.
|
|
12
|
+
默认用 `@latest`,发新版不用改配置;想固定某一版时把 latest 换成版本号(当前是 0.2.4)。
|
|
13
13
|
|
|
14
14
|
| 环境变量 | 必填 | 说明 |
|
|
15
15
|
|---|---|---|
|
|
@@ -18,4 +18,4 @@ MOMENTUM_TOKEN=mom_agent_xxx \
|
|
|
18
18
|
| `MOMENTUM_CF_ACCESS_CLIENT_ID` | 否 | 部署在 Cloudflare Access 后面时才需要 |
|
|
19
19
|
| `MOMENTUM_CF_ACCESS_CLIENT_SECRET` | 否 | 同上 |
|
|
20
20
|
|
|
21
|
-
版本 0.2.
|
|
21
|
+
版本 0.2.4。客户端和服务端版本不一致时,启动日志(stderr)会明确警告。
|
package/momentum-mcp.mjs
CHANGED
|
@@ -7195,7 +7195,7 @@ var require_dist = __commonJS({
|
|
|
7195
7195
|
}
|
|
7196
7196
|
});
|
|
7197
7197
|
|
|
7198
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
7198
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
7199
7199
|
import process2 from "node:process";
|
|
7200
7200
|
|
|
7201
7201
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/core/core.js
|
|
@@ -11699,7 +11699,7 @@ function preprocess(fn, schema) {
|
|
|
11699
11699
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v4/classic/external.js
|
|
11700
11700
|
config(en_default());
|
|
11701
11701
|
|
|
11702
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
11702
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js
|
|
11703
11703
|
var LATEST_PROTOCOL_VERSION = "2025-11-25";
|
|
11704
11704
|
var SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
|
|
11705
11705
|
var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
@@ -13230,7 +13230,7 @@ var UrlElicitationRequiredError = class extends McpError {
|
|
|
13230
13230
|
}
|
|
13231
13231
|
};
|
|
13232
13232
|
|
|
13233
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
13233
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
13234
13234
|
var STDIO_DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
13235
13235
|
var ReadBuffer = class {
|
|
13236
13236
|
constructor(options) {
|
|
@@ -13267,7 +13267,7 @@ function serializeMessage(message) {
|
|
|
13267
13267
|
return JSON.stringify(message) + "\n";
|
|
13268
13268
|
}
|
|
13269
13269
|
|
|
13270
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
13270
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
13271
13271
|
var StdioServerTransport = class {
|
|
13272
13272
|
constructor(_stdin = process2.stdin, _stdout = process2.stdout, options) {
|
|
13273
13273
|
this._stdin = _stdin;
|
|
@@ -15339,7 +15339,7 @@ var allowErrorProps = SuperJSON.allowErrorProps;
|
|
|
15339
15339
|
|
|
15340
15340
|
// src/version.ts
|
|
15341
15341
|
var UNKNOWN = "unknown";
|
|
15342
|
-
var MCP_VERSION = true ? "0.2.
|
|
15342
|
+
var MCP_VERSION = true ? "0.2.4" : versionFromRepo();
|
|
15343
15343
|
var CLIENT_HEADER = `momentum-mcp/${MCP_VERSION}`;
|
|
15344
15344
|
function compareVersions(a, b) {
|
|
15345
15345
|
const parse4 = (v) => {
|
|
@@ -19477,7 +19477,7 @@ function object2(shape, params) {
|
|
|
19477
19477
|
return new ZodMiniObject(def);
|
|
19478
19478
|
}
|
|
19479
19479
|
|
|
19480
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
19480
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
|
|
19481
19481
|
function isZ4Schema(s) {
|
|
19482
19482
|
const schema = s;
|
|
19483
19483
|
return !!schema._zod;
|
|
@@ -19637,7 +19637,7 @@ function getLiteralValue(schema) {
|
|
|
19637
19637
|
return void 0;
|
|
19638
19638
|
}
|
|
19639
19639
|
|
|
19640
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
19640
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js
|
|
19641
19641
|
function isTerminal(status) {
|
|
19642
19642
|
return status === "completed" || status === "failed" || status === "cancelled";
|
|
19643
19643
|
}
|
|
@@ -20926,7 +20926,7 @@ var zodToJsonSchema = (schema, options) => {
|
|
|
20926
20926
|
return combined;
|
|
20927
20927
|
};
|
|
20928
20928
|
|
|
20929
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
20929
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js
|
|
20930
20930
|
function mapMiniTarget(t) {
|
|
20931
20931
|
if (!t)
|
|
20932
20932
|
return "draft-7";
|
|
@@ -20968,7 +20968,7 @@ function parseWithCompat(schema, data) {
|
|
|
20968
20968
|
return result.data;
|
|
20969
20969
|
}
|
|
20970
20970
|
|
|
20971
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
20971
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
|
|
20972
20972
|
var DEFAULT_REQUEST_TIMEOUT_MSEC = 6e4;
|
|
20973
20973
|
var Protocol = class {
|
|
20974
20974
|
constructor(_options) {
|
|
@@ -21009,6 +21009,9 @@ var Protocol = class {
|
|
|
21009
21009
|
this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
|
|
21010
21010
|
const handleTaskResult = async () => {
|
|
21011
21011
|
const taskId = request.params.taskId;
|
|
21012
|
+
if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
|
|
21013
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
21014
|
+
}
|
|
21012
21015
|
if (this._taskMessageQueue) {
|
|
21013
21016
|
let queuedMessage;
|
|
21014
21017
|
while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
|
|
@@ -21039,12 +21042,12 @@ var Protocol = class {
|
|
|
21039
21042
|
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
|
|
21040
21043
|
}
|
|
21041
21044
|
if (!isTerminal(task.status)) {
|
|
21042
|
-
await this._waitForTaskUpdate(taskId, extra.signal);
|
|
21045
|
+
await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
|
|
21043
21046
|
return await handleTaskResult();
|
|
21044
21047
|
}
|
|
21045
21048
|
if (isTerminal(task.status)) {
|
|
21046
21049
|
const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
|
|
21047
|
-
this._clearTaskQueue(taskId);
|
|
21050
|
+
this._clearTaskQueue(taskId, extra.sessionId);
|
|
21048
21051
|
return {
|
|
21049
21052
|
...result,
|
|
21050
21053
|
_meta: {
|
|
@@ -21081,7 +21084,7 @@ var Protocol = class {
|
|
|
21081
21084
|
throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
|
|
21082
21085
|
}
|
|
21083
21086
|
await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
|
|
21084
|
-
this._clearTaskQueue(request.params.taskId);
|
|
21087
|
+
this._clearTaskQueue(request.params.taskId, extra.sessionId);
|
|
21085
21088
|
const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
|
|
21086
21089
|
if (!cancelledTask) {
|
|
21087
21090
|
throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
|
|
@@ -21209,6 +21212,19 @@ var Protocol = class {
|
|
|
21209
21212
|
const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
|
|
21210
21213
|
const capturedTransport = this._transport;
|
|
21211
21214
|
const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
|
|
21215
|
+
const sessionId = capturedTransport?.sessionId;
|
|
21216
|
+
const store = this._taskStore;
|
|
21217
|
+
let relatedTaskFound = true;
|
|
21218
|
+
let relatedTaskLookup;
|
|
21219
|
+
if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
|
|
21220
|
+
relatedTaskFound = false;
|
|
21221
|
+
relatedTaskLookup = (async () => {
|
|
21222
|
+
if (!await store.getTask(relatedTaskId, sessionId)) {
|
|
21223
|
+
throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
|
|
21224
|
+
}
|
|
21225
|
+
relatedTaskFound = true;
|
|
21226
|
+
})();
|
|
21227
|
+
}
|
|
21212
21228
|
if (handler === void 0) {
|
|
21213
21229
|
const errorResponse = {
|
|
21214
21230
|
jsonrpc: "2.0",
|
|
@@ -21218,7 +21234,10 @@ var Protocol = class {
|
|
|
21218
21234
|
message: "Method not found"
|
|
21219
21235
|
}
|
|
21220
21236
|
};
|
|
21221
|
-
if (relatedTaskId &&
|
|
21237
|
+
if (relatedTaskId && relatedTaskLookup) {
|
|
21238
|
+
const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
|
|
21239
|
+
relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error2) => this._onerror(new Error(`Failed to send an error response: ${error2}`)));
|
|
21240
|
+
} else if (relatedTaskId && this._taskMessageQueue) {
|
|
21222
21241
|
this._enqueueTaskMessage(relatedTaskId, {
|
|
21223
21242
|
type: "error",
|
|
21224
21243
|
message: errorResponse,
|
|
@@ -21269,7 +21288,10 @@ var Protocol = class {
|
|
|
21269
21288
|
closeSSEStream: extra?.closeSSEStream,
|
|
21270
21289
|
closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
|
|
21271
21290
|
};
|
|
21272
|
-
Promise.resolve().then(() => {
|
|
21291
|
+
(relatedTaskLookup ?? Promise.resolve()).then(() => {
|
|
21292
|
+
if (relatedTaskLookup && abortController.signal.aborted) {
|
|
21293
|
+
throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
|
|
21294
|
+
}
|
|
21273
21295
|
if (taskCreationParams) {
|
|
21274
21296
|
this.assertTaskHandlerCapability(request.method);
|
|
21275
21297
|
}
|
|
@@ -21304,7 +21326,7 @@ var Protocol = class {
|
|
|
21304
21326
|
...error2["data"] !== void 0 && { data: error2["data"] }
|
|
21305
21327
|
}
|
|
21306
21328
|
};
|
|
21307
|
-
if (relatedTaskId && this._taskMessageQueue) {
|
|
21329
|
+
if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
|
|
21308
21330
|
await this._enqueueTaskMessage(relatedTaskId, {
|
|
21309
21331
|
type: "error",
|
|
21310
21332
|
message: errorResponse,
|
|
@@ -21784,7 +21806,7 @@ var Protocol = class {
|
|
|
21784
21806
|
throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
|
|
21785
21807
|
}
|
|
21786
21808
|
const maxQueueSize = this._options?.maxTaskQueueSize;
|
|
21787
|
-
await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
|
|
21809
|
+
await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
|
|
21788
21810
|
}
|
|
21789
21811
|
/**
|
|
21790
21812
|
* Clears the message queue for a task and rejects any pending request resolvers.
|
|
@@ -21813,12 +21835,13 @@ var Protocol = class {
|
|
|
21813
21835
|
* Uses polling to check for updates at the task's configured poll interval.
|
|
21814
21836
|
* @param taskId The task ID to wait for
|
|
21815
21837
|
* @param signal Abort signal to cancel the wait
|
|
21838
|
+
* @param sessionId Session of the request that waits, passed to the task store
|
|
21816
21839
|
* @returns Promise that resolves when an update occurs or rejects if aborted
|
|
21817
21840
|
*/
|
|
21818
|
-
async _waitForTaskUpdate(taskId, signal) {
|
|
21841
|
+
async _waitForTaskUpdate(taskId, signal, sessionId) {
|
|
21819
21842
|
let interval = this._options?.defaultTaskPollInterval ?? 1e3;
|
|
21820
21843
|
try {
|
|
21821
|
-
const task = await this._taskStore?.getTask(taskId);
|
|
21844
|
+
const task = await this._taskStore?.getTask(taskId, sessionId);
|
|
21822
21845
|
if (task?.pollInterval) {
|
|
21823
21846
|
interval = task.pollInterval;
|
|
21824
21847
|
}
|
|
@@ -21922,7 +21945,7 @@ function mergeCapabilities(base, additional) {
|
|
|
21922
21945
|
return result;
|
|
21923
21946
|
}
|
|
21924
21947
|
|
|
21925
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
21948
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js
|
|
21926
21949
|
var import_ajv = __toESM(require_ajv(), 1);
|
|
21927
21950
|
var import_ajv_formats = __toESM(require_dist(), 1);
|
|
21928
21951
|
function createDefaultAjvInstance() {
|
|
@@ -21990,7 +22013,7 @@ var AjvJsonSchemaValidator = class {
|
|
|
21990
22013
|
}
|
|
21991
22014
|
};
|
|
21992
22015
|
|
|
21993
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
22016
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js
|
|
21994
22017
|
var ExperimentalServerTasks = class {
|
|
21995
22018
|
constructor(_server) {
|
|
21996
22019
|
this._server = _server;
|
|
@@ -22203,7 +22226,7 @@ var ExperimentalServerTasks = class {
|
|
|
22203
22226
|
}
|
|
22204
22227
|
};
|
|
22205
22228
|
|
|
22206
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
22229
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js
|
|
22207
22230
|
function assertToolsCallTaskCapability(requests, method, entityName) {
|
|
22208
22231
|
if (!requests) {
|
|
22209
22232
|
throw new Error(`${entityName} does not support task creation (required for ${method})`);
|
|
@@ -22238,7 +22261,7 @@ function assertClientRequestTaskCapability(requests, method, entityName) {
|
|
|
22238
22261
|
}
|
|
22239
22262
|
}
|
|
22240
22263
|
|
|
22241
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
22264
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js
|
|
22242
22265
|
var Server = class extends Protocol {
|
|
22243
22266
|
/**
|
|
22244
22267
|
* Initializes this server with the given name and version information.
|
|
@@ -22609,7 +22632,7 @@ var Server = class extends Protocol {
|
|
|
22609
22632
|
}
|
|
22610
22633
|
};
|
|
22611
22634
|
|
|
22612
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
22635
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js
|
|
22613
22636
|
var COMPLETABLE_SYMBOL = Symbol.for("mcp.completable");
|
|
22614
22637
|
function isCompletable(schema) {
|
|
22615
22638
|
return !!schema && typeof schema === "object" && COMPLETABLE_SYMBOL in schema;
|
|
@@ -22623,7 +22646,7 @@ var McpZodTypeKind;
|
|
|
22623
22646
|
McpZodTypeKind2["Completable"] = "McpCompletable";
|
|
22624
22647
|
})(McpZodTypeKind || (McpZodTypeKind = {}));
|
|
22625
22648
|
|
|
22626
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
22649
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/uriTemplate.js
|
|
22627
22650
|
var MAX_TEMPLATE_LENGTH = 1e6;
|
|
22628
22651
|
var MAX_VARIABLE_LENGTH = 1e6;
|
|
22629
22652
|
var MAX_TEMPLATE_EXPRESSIONS = 1e4;
|
|
@@ -22845,7 +22868,7 @@ var UriTemplate = class _UriTemplate {
|
|
|
22845
22868
|
}
|
|
22846
22869
|
};
|
|
22847
22870
|
|
|
22848
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
22871
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js
|
|
22849
22872
|
var TOOL_NAME_REGEX = /^[A-Za-z0-9._-]{1,128}$/;
|
|
22850
22873
|
function validateToolName(name) {
|
|
22851
22874
|
const warnings = [];
|
|
@@ -22903,7 +22926,7 @@ function validateAndWarnToolName(name) {
|
|
|
22903
22926
|
return result.isValid;
|
|
22904
22927
|
}
|
|
22905
22928
|
|
|
22906
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
22929
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js
|
|
22907
22930
|
var ExperimentalMcpServerTasks = class {
|
|
22908
22931
|
constructor(_mcpServer) {
|
|
22909
22932
|
this._mcpServer = _mcpServer;
|
|
@@ -22918,7 +22941,43 @@ var ExperimentalMcpServerTasks = class {
|
|
|
22918
22941
|
}
|
|
22919
22942
|
};
|
|
22920
22943
|
|
|
22921
|
-
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.
|
|
22944
|
+
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.32.1_zod@3.25.76/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
|
|
22945
|
+
function toolInputElementCount(value, max) {
|
|
22946
|
+
let count = 0;
|
|
22947
|
+
const stack = [value];
|
|
22948
|
+
while (stack.length > 0) {
|
|
22949
|
+
const node = stack.pop();
|
|
22950
|
+
if (node === null || typeof node !== "object")
|
|
22951
|
+
continue;
|
|
22952
|
+
if (Array.isArray(node)) {
|
|
22953
|
+
for (const child of node) {
|
|
22954
|
+
if (++count > max)
|
|
22955
|
+
return count;
|
|
22956
|
+
if (child !== null && typeof child === "object")
|
|
22957
|
+
stack.push(child);
|
|
22958
|
+
}
|
|
22959
|
+
} else {
|
|
22960
|
+
for (const key in node) {
|
|
22961
|
+
if (!Object.prototype.hasOwnProperty.call(node, key))
|
|
22962
|
+
continue;
|
|
22963
|
+
if (++count > max)
|
|
22964
|
+
return count;
|
|
22965
|
+
const child = node[key];
|
|
22966
|
+
if (child !== null && typeof child === "object")
|
|
22967
|
+
stack.push(child);
|
|
22968
|
+
}
|
|
22969
|
+
}
|
|
22970
|
+
}
|
|
22971
|
+
return count;
|
|
22972
|
+
}
|
|
22973
|
+
function resolveMaxToolInputElements(value) {
|
|
22974
|
+
if (value === void 0 || value === Infinity)
|
|
22975
|
+
return void 0;
|
|
22976
|
+
if (typeof value !== "number" || Number.isNaN(value) || value < 1) {
|
|
22977
|
+
throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
|
|
22978
|
+
}
|
|
22979
|
+
return value;
|
|
22980
|
+
}
|
|
22922
22981
|
var McpServer = class {
|
|
22923
22982
|
constructor(serverInfo, options) {
|
|
22924
22983
|
this._registeredResources = {};
|
|
@@ -22930,6 +22989,7 @@ var McpServer = class {
|
|
|
22930
22989
|
this._resourceHandlersInitialized = false;
|
|
22931
22990
|
this._promptHandlersInitialized = false;
|
|
22932
22991
|
this.server = new Server(serverInfo, options);
|
|
22992
|
+
this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
|
|
22933
22993
|
}
|
|
22934
22994
|
/**
|
|
22935
22995
|
* Access experimental features.
|
|
@@ -23060,12 +23120,15 @@ var McpServer = class {
|
|
|
23060
23120
|
* Validates tool input arguments against the tool's input schema.
|
|
23061
23121
|
*/
|
|
23062
23122
|
async validateToolInput(tool, args, toolName) {
|
|
23123
|
+
if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) {
|
|
23124
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
|
|
23125
|
+
}
|
|
23063
23126
|
if (!tool.inputSchema) {
|
|
23064
23127
|
return void 0;
|
|
23065
23128
|
}
|
|
23066
23129
|
const inputObj = normalizeObjectSchema(tool.inputSchema);
|
|
23067
23130
|
const schemaToParse = inputObj ?? tool.inputSchema;
|
|
23068
|
-
const parseResult = await safeParseAsync3(schemaToParse, args);
|
|
23131
|
+
const parseResult = await safeParseAsync3(schemaToParse, args ?? {});
|
|
23069
23132
|
if (!parseResult.success) {
|
|
23070
23133
|
const error2 = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
23071
23134
|
const errorMessage = getParseErrorMessage(error2);
|
|
@@ -23303,7 +23366,7 @@ var McpServer = class {
|
|
|
23303
23366
|
}
|
|
23304
23367
|
if (prompt.argsSchema) {
|
|
23305
23368
|
const argsObj = normalizeObjectSchema(prompt.argsSchema);
|
|
23306
|
-
const parseResult = await safeParseAsync3(argsObj, request.params.arguments);
|
|
23369
|
+
const parseResult = await safeParseAsync3(argsObj, request.params.arguments ?? {});
|
|
23307
23370
|
if (!parseResult.success) {
|
|
23308
23371
|
const error2 = "error" in parseResult ? parseResult.error : "Unknown error";
|
|
23309
23372
|
const errorMessage = getParseErrorMessage(error2);
|