@commercetools/commerce-mcp 1.0.6 → 1.0.7
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 +72 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.ACCEPTED_TOOLS = void 0;
|
|
|
5
5
|
exports.parseArgs = parseArgs;
|
|
6
6
|
exports.main = main;
|
|
7
7
|
const modelcontextprotocol_1 = require("@commercetools/commerce-agent/modelcontextprotocol");
|
|
8
|
+
const modelcontextprotocol_2 = require("@commercetools/commerce-agent/modelcontextprotocol");
|
|
8
9
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
9
10
|
const colors_1 = require("colors");
|
|
10
11
|
const HIDDEN_ARGS = ['customerId', 'isAdmin', 'storeKey', 'businessUnitKey'];
|
|
@@ -126,11 +127,9 @@ exports.ACCEPTED_TOOLS = [
|
|
|
126
127
|
'transactions.read',
|
|
127
128
|
'transactions.create',
|
|
128
129
|
];
|
|
129
|
-
// eslint-disable-next-line complexity
|
|
130
130
|
function parseArgs(args) {
|
|
131
131
|
const options = {};
|
|
132
132
|
const env = {};
|
|
133
|
-
// eslint-disable-next-line complexity
|
|
134
133
|
args.forEach((arg) => {
|
|
135
134
|
if (arg.startsWith('--')) {
|
|
136
135
|
const [key, value] = arg.slice(2).split('=');
|
|
@@ -181,6 +180,9 @@ function parseArgs(args) {
|
|
|
181
180
|
options.toolOutputFormat = value;
|
|
182
181
|
}
|
|
183
182
|
}
|
|
183
|
+
else if (key == 'fieldFiltering') {
|
|
184
|
+
options.fieldFiltering = tryParseFieldFiltering(value);
|
|
185
|
+
}
|
|
184
186
|
else if (key == 'logging') {
|
|
185
187
|
options.logging = value == 'true';
|
|
186
188
|
}
|
|
@@ -267,6 +269,71 @@ function parseArgs(args) {
|
|
|
267
269
|
}
|
|
268
270
|
return { options, env };
|
|
269
271
|
}
|
|
272
|
+
function tryParseFieldFiltering(fieldFilteringString) {
|
|
273
|
+
let fieldFilteringConfig;
|
|
274
|
+
try {
|
|
275
|
+
fieldFilteringConfig = JSON.parse(fieldFilteringString);
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
throw new Error(`Invalid argument: fieldFiltering. Error parsing JSON: ${error}`);
|
|
279
|
+
}
|
|
280
|
+
if (typeof fieldFilteringConfig !== 'object' ||
|
|
281
|
+
fieldFilteringConfig === null ||
|
|
282
|
+
Array.isArray(fieldFilteringConfig)) {
|
|
283
|
+
throw new Error(`Invalid argument: fieldFiltering. Value must be a stringified object of type FieldFilteringManagerConfig.`);
|
|
284
|
+
}
|
|
285
|
+
if (fieldFilteringConfig.paths) {
|
|
286
|
+
if (!isFieldFilteringRuleArray(fieldFilteringConfig.paths)) {
|
|
287
|
+
throw new Error(`Invalid argument: fieldFiltering.paths. Value must be a stringified array of type { type: "filter" | "redact", value: string, value: boolean }`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (fieldFilteringConfig.properties) {
|
|
291
|
+
if (!isFieldFilteringRuleArray(fieldFilteringConfig.properties)) {
|
|
292
|
+
throw new Error(`Invalid argument: fieldFiltering.properties. Value must be a stringified array of type { type: "filter" | "redact", value: string, value: boolean }`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (fieldFilteringConfig.whitelistPaths) {
|
|
296
|
+
if (!isFieldFilteringRuleArray(
|
|
297
|
+
// add value property to whitelistPaths depsite irrelevance to reuse isFieldFilteringRuleArray logic
|
|
298
|
+
fieldFilteringConfig.whitelistPaths.map((path) => ({
|
|
299
|
+
...path,
|
|
300
|
+
value: 'filter',
|
|
301
|
+
})))) {
|
|
302
|
+
throw new Error(`Invalid argument: fieldFiltering.whitelistPaths. Value must be a stringified array of type { value: string, value: boolean }`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (fieldFilteringConfig.includes) {
|
|
306
|
+
if (!isFieldFilteringRuleArray(fieldFilteringConfig.includes)) {
|
|
307
|
+
throw new Error(`Invalid argument: fieldFiltering.includes. Value must be a stringified array of type { type: "filter" | "redact", value: string, value: boolean }`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (fieldFilteringConfig.jsonRedactionText) {
|
|
311
|
+
if (typeof fieldFilteringConfig.jsonRedactionText !== 'string') {
|
|
312
|
+
throw new Error(`Invalid argument: fieldFiltering.jsonRedactionText. Value must be of type string`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (fieldFilteringConfig.urlRedactionText) {
|
|
316
|
+
if (typeof fieldFilteringConfig.urlRedactionText !== 'string') {
|
|
317
|
+
throw new Error(`Invalid argument: fieldFiltering.urlRedactionText. Value must be of type string`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return fieldFilteringConfig;
|
|
321
|
+
}
|
|
322
|
+
function isFieldFilteringRuleArray(possibleRules) {
|
|
323
|
+
if (!Array.isArray(possibleRules)) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
return (possibleRules
|
|
327
|
+
.map((rule) => isFieldFilteringRule(rule))
|
|
328
|
+
.findIndex((bool) => bool === false) === -1);
|
|
329
|
+
}
|
|
330
|
+
function isFieldFilteringRule(possibleRule) {
|
|
331
|
+
const rule = possibleRule;
|
|
332
|
+
return (!!rule.value &&
|
|
333
|
+
typeof rule.value === 'string' &&
|
|
334
|
+
typeof rule.caseSensitive === 'boolean' &&
|
|
335
|
+
(rule.type === 'filter' || rule.type === 'redact'));
|
|
336
|
+
}
|
|
270
337
|
function createAuthConfig(env) {
|
|
271
338
|
const baseConfig = {
|
|
272
339
|
authUrl: env.authUrl,
|
|
@@ -315,6 +382,9 @@ async function main() {
|
|
|
315
382
|
storeKey: options.storeKey,
|
|
316
383
|
businessUnitKey: options.businessUnitKey,
|
|
317
384
|
logging: options.logging,
|
|
385
|
+
fieldFiltering: options.fieldFiltering
|
|
386
|
+
? new modelcontextprotocol_2.FieldFilteringHandler(options.fieldFiltering)
|
|
387
|
+
: undefined,
|
|
318
388
|
},
|
|
319
389
|
};
|
|
320
390
|
if (selectedTools[0] === 'all') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools/commerce-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"mcpName": "io.github.commercetools/commerce-mcp",
|
|
5
5
|
"homepage": "https://github.com/commercetools/commerce-mcp",
|
|
6
6
|
"description": "A command line tool for setting up commercetools MCP server",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"colors": "^1.4.0",
|
|
24
24
|
"dotenv": "^17.2.1",
|
|
25
25
|
"mcp-remote": "^0.1.18",
|
|
26
|
-
"@commercetools/commerce-agent": "1.0
|
|
26
|
+
"@commercetools/commerce-agent": "1.1.0"
|
|
27
27
|
},
|
|
28
28
|
"keywords": [
|
|
29
29
|
"mcp",
|