vendure-mcp-graphql 1.5.0 → 1.6.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.
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
68
68
  variables: { type: "object", description: "Optional variables" },
69
69
  channelToken: {
70
70
  type: "string",
71
- description: "Optional channel token to set channel context (e.g., 'default-channel', 'test-channel')",
71
+ description: "Optional channel token to scope the request to a specific channel. Requires CHANNEL_API_KEY_MAP to be configured with a key for this channel.",
72
72
  },
73
73
  },
74
74
  required: ["query"],
@@ -87,7 +87,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
87
87
  variables: { type: "object", description: "Optional variables" },
88
88
  channelToken: {
89
89
  type: "string",
90
- description: "Optional channel token to set channel context (e.g., 'default-channel', 'test-channel')",
90
+ description: "Optional channel token to scope the request to a specific channel. Requires CHANNEL_API_KEY_MAP to be configured with a key for this channel.",
91
91
  },
92
92
  },
93
93
  required: ["mutation"],
@@ -150,7 +150,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
150
150
  variables: { type: "object", description: "Optional variables" },
151
151
  channelToken: {
152
152
  type: "string",
153
- description: "Optional channel token to set channel context (e.g., 'default-channel', 'test-channel')",
153
+ description: "Optional channel token to scope the request to a specific channel. Requires CHANNEL_API_KEY_MAP to be configured with a key for this channel.",
154
154
  },
155
155
  },
156
156
  required: ["query"],
@@ -169,7 +169,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
169
169
  variables: { type: "object", description: "Optional variables" },
170
170
  channelToken: {
171
171
  type: "string",
172
- description: "Optional channel token to set channel context (e.g., 'default-channel', 'test-channel')",
172
+ description: "Optional channel token to scope the request to a specific channel. Requires CHANNEL_API_KEY_MAP to be configured with a key for this channel.",
173
173
  },
174
174
  },
175
175
  required: ["mutation"],
@@ -206,7 +206,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
206
206
  },
207
207
  channelToken: {
208
208
  type: "string",
209
- description: "Optional channel token to set channel context (e.g., 'default-channel', 'test-channel')",
209
+ description: "Optional channel token to scope the request to a specific channel. Requires CHANNEL_API_KEY_MAP to be configured with a key for this channel.",
210
210
  },
211
211
  },
212
212
  required: ["mutation", "ids"],
@@ -370,6 +370,20 @@ async function main() {
370
370
  console.error(`API Key: ${process.env.VENDURE_API_KEY ? "Present" : "Missing"}`);
371
371
  console.error(`Admin URL: ${process.env.ADMIN_API_URL || "default"}`);
372
372
  console.error(`Shop URL: ${process.env.SHOP_API_URL || "default"}`);
373
+ // Log available channel API key mappings
374
+ const raw = process.env.CHANNEL_API_KEY_MAP;
375
+ if (raw) {
376
+ try {
377
+ const map = JSON.parse(raw);
378
+ const channels = Object.keys(map);
379
+ if (channels.length > 0) {
380
+ console.error(`Channel API keys configured for: ${channels.join(", ")}`);
381
+ }
382
+ }
383
+ catch {
384
+ console.error("Invalid CHANNEL_API_KEY_MAP environment variable");
385
+ }
386
+ }
373
387
  }
374
388
  main().catch((error) => {
375
389
  console.error("Server error:", error);
@@ -1,6 +1,12 @@
1
1
  /**
2
2
  * GraphQL Client for Vendure API
3
- * Handles authentication via API Key for both Admin and Shop APIs
3
+ * Handles authentication via API Key for both Admin and Shop APIs.
4
+ *
5
+ * Channel switching is done via per-channel API keys (CHANNEL_API_KEY_MAP)
6
+ * combined with the vendure-token header. The per-channel API key provides
7
+ * authentication scoped to the target channel, and the vendure-token header
8
+ * tells Vendure which channel context to use for the request.
9
+ * Both are required for proper channel switching.
4
10
  */
5
11
  export interface GraphQLResponse<T = any> {
6
12
  data?: T;
@@ -10,8 +16,9 @@ export interface GraphQLResponse<T = any> {
10
16
  }>;
11
17
  }
12
18
  export declare class GraphQLClient {
13
- private apiKey;
14
- constructor(apiKey?: string | null);
19
+ private defaultApiKey;
20
+ private channelApiKeys;
21
+ constructor(defaultApiKey?: string | null, channelApiKeys?: Record<string, string>);
15
22
  request<T = any>(url: string, queryString: string, variables?: Record<string, any>, channelToken?: string): Promise<T>;
16
23
  }
17
24
  export declare function getClient(): GraphQLClient;
@@ -1,19 +1,32 @@
1
1
  /**
2
2
  * GraphQL Client for Vendure API
3
- * Handles authentication via API Key for both Admin and Shop APIs
3
+ * Handles authentication via API Key for both Admin and Shop APIs.
4
+ *
5
+ * Channel switching is done via per-channel API keys (CHANNEL_API_KEY_MAP)
6
+ * combined with the vendure-token header. The per-channel API key provides
7
+ * authentication scoped to the target channel, and the vendure-token header
8
+ * tells Vendure which channel context to use for the request.
9
+ * Both are required for proper channel switching.
4
10
  */
5
11
  export class GraphQLClient {
6
- apiKey;
7
- constructor(apiKey = null) {
8
- this.apiKey = apiKey;
12
+ defaultApiKey;
13
+ channelApiKeys;
14
+ constructor(defaultApiKey = null, channelApiKeys = {}) {
15
+ this.defaultApiKey = defaultApiKey;
16
+ this.channelApiKeys = channelApiKeys;
9
17
  }
10
18
  async request(url, queryString, variables, channelToken) {
19
+ // Resolve API key: use channel-specific key if available, fall back to default
20
+ const apiKey = (channelToken && this.channelApiKeys[channelToken]) || this.defaultApiKey;
11
21
  const headers = {
12
22
  "Content-Type": "application/json",
13
23
  };
14
- if (this.apiKey) {
15
- headers["vendure-api-key"] = this.apiKey;
24
+ if (apiKey) {
25
+ headers["vendure-api-key"] = apiKey;
16
26
  }
27
+ // Set vendure-token header when a channel token is provided and we have
28
+ // a mapped API key for it (ensuring the API key has access to this channel).
29
+ // The vendure-token header tells Vendure which channel context to use for the request.
17
30
  if (channelToken) {
18
31
  headers["vendure-token"] = channelToken;
19
32
  }
@@ -39,11 +52,20 @@ export class GraphQLClient {
39
52
  // Singleton instance
40
53
  let clientInstance = null;
41
54
  export function getClient() {
42
- if (clientInstance) {
55
+ if (clientInstance)
43
56
  return clientInstance;
57
+ const defaultApiKey = process.env.VENDURE_API_KEY || null;
58
+ let channelApiKeys = {};
59
+ const raw = process.env.CHANNEL_API_KEY_MAP;
60
+ if (raw) {
61
+ try {
62
+ channelApiKeys = JSON.parse(raw);
63
+ }
64
+ catch (e) {
65
+ console.error("Invalid CHANNEL_API_KEY_MAP JSON:", e);
66
+ }
44
67
  }
45
- const apiKey = process.env.VENDURE_API_KEY || null;
46
- clientInstance = new GraphQLClient(apiKey);
68
+ clientInstance = new GraphQLClient(defaultApiKey, channelApiKeys);
47
69
  return clientInstance;
48
70
  }
49
71
  export function getAdminUrl() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vendure-mcp-graphql",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "MCP server for Vendure Admin and Shop GraphQL APIs",
5
5
  "type": "module",
6
6
  "bin": {