@shoppexio/mcp-commerce-server 0.3.0 → 0.4.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.mjs +22 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoppexio/mcp-commerce-server",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Shoppex MCP server for commerce operations over the Dev API",
5
5
  "type": "module",
6
6
  "repository": {
package/src/server.mjs CHANGED
@@ -12,6 +12,9 @@ function resolveBaseUrl(explicitValue) {
12
12
  }
13
13
 
14
14
  function jsonContent(value) {
15
+ const structured = Array.isArray(value) || value === null || typeof value !== 'object'
16
+ ? { result: value }
17
+ : value;
15
18
  return {
16
19
  content: [
17
20
  {
@@ -19,7 +22,7 @@ function jsonContent(value) {
19
22
  text: JSON.stringify(value, null, 2),
20
23
  },
21
24
  ],
22
- structuredContent: value,
25
+ structuredContent: structured,
23
26
  };
24
27
  }
25
28
 
@@ -257,13 +260,29 @@ export class ShoppexCommerceDevApiClient {
257
260
  }
258
261
 
259
262
  const BaseToolSchema = {
260
- shop_api_key: z.string().trim().min(1),
263
+ shop_api_key: z.string().trim().min(1).optional(),
261
264
  api_base_url: z.string().trim().url().optional(),
262
265
  };
263
266
 
267
+ function resolveShopApiKey(explicitValue) {
268
+ if (typeof explicitValue === 'string' && explicitValue.trim()) {
269
+ return explicitValue.trim();
270
+ }
271
+ const fromEnv = process.env.SHOPPEX_SHOP_API_KEY?.trim()
272
+ || process.env.SHOPPEX_API_KEY?.trim()
273
+ || process.env.SHOP_API_KEY?.trim();
274
+ if (!fromEnv) {
275
+ throw new ShoppexCommerceDevApiError(
276
+ 'Missing Shoppex shop API key. Set SHOPPEX_SHOP_API_KEY in the MCP server env, or pass shop_api_key to the tool.',
277
+ { code: 'auth_error', retryable: false },
278
+ );
279
+ }
280
+ return fromEnv;
281
+ }
282
+
264
283
  function createClient(args) {
265
284
  return new ShoppexCommerceDevApiClient({
266
- shopApiKey: args.shop_api_key,
285
+ shopApiKey: resolveShopApiKey(args.shop_api_key),
267
286
  apiBaseUrl: args.api_base_url,
268
287
  });
269
288
  }