@snokam/mcp-api 0.109.0 → 0.110.0
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 +49 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { getAccessToken } from "./auth.js";
|
|
|
15
15
|
// State
|
|
16
16
|
// ---------------------------------------------------------------------------
|
|
17
17
|
let currentEnvironment = process.env.SNOKAM_ENVIRONMENT ?? "production";
|
|
18
|
+
let currentApiDomain = null;
|
|
18
19
|
let endpoints = [];
|
|
19
20
|
let endpointsByTool = new Map();
|
|
20
21
|
const serviceUrlOverrides = new Map();
|
|
@@ -25,9 +26,18 @@ async function loadEndpoints(environment) {
|
|
|
25
26
|
for (const ep of endpoints) {
|
|
26
27
|
endpointsByTool.set(ep.toolName, ep);
|
|
27
28
|
}
|
|
28
|
-
// Re-
|
|
29
|
+
// Re-target every service at the active business domain (if set), then layer
|
|
30
|
+
// per-service overrides on top (most specific wins).
|
|
31
|
+
applyDomainOverride();
|
|
29
32
|
applyUrlOverrides();
|
|
30
33
|
}
|
|
34
|
+
function applyDomainOverride() {
|
|
35
|
+
if (!currentApiDomain)
|
|
36
|
+
return;
|
|
37
|
+
for (const ep of endpoints) {
|
|
38
|
+
ep.baseUrl = `https://${ep.service}.${currentApiDomain}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
31
41
|
function applyUrlOverrides() {
|
|
32
42
|
for (const ep of endpoints) {
|
|
33
43
|
const override = serviceUrlOverrides.get(ep.service);
|
|
@@ -36,6 +46,12 @@ function applyUrlOverrides() {
|
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
}
|
|
49
|
+
function normalizeDomain(raw) {
|
|
50
|
+
return raw
|
|
51
|
+
.trim()
|
|
52
|
+
.replace(/^https?:\/\//, "")
|
|
53
|
+
.replace(/\/$/, "");
|
|
54
|
+
}
|
|
39
55
|
// ---------------------------------------------------------------------------
|
|
40
56
|
// Built-in tool: SwitchEnvironment
|
|
41
57
|
// ---------------------------------------------------------------------------
|
|
@@ -92,6 +108,21 @@ const resetUrlToolDef = {
|
|
|
92
108
|
},
|
|
93
109
|
},
|
|
94
110
|
};
|
|
111
|
+
const SWITCH_DOMAIN_TOOL_NAME = "SwitchDomain";
|
|
112
|
+
const switchDomainToolDef = {
|
|
113
|
+
name: SWITCH_DOMAIN_TOOL_NAME,
|
|
114
|
+
description: "Point all Snokam API calls at a specific business's API domain, so the same MCP can serve any tenant. Pass the business's API domain (custom, e.g. api.acme.com, or its snosky fallback, e.g. api.acme.snosky.no); calls then go to {service}.{domain}. Pass an empty string to reset to the environment default (snokam).",
|
|
115
|
+
inputSchema: {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
domain: {
|
|
119
|
+
type: "string",
|
|
120
|
+
description: "The business's API base domain (e.g. api.acme.com). Empty string resets to the snokam default.",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
required: ["domain"],
|
|
124
|
+
},
|
|
125
|
+
};
|
|
95
126
|
// ---------------------------------------------------------------------------
|
|
96
127
|
// JSON Schema builder for tool inputs
|
|
97
128
|
// ---------------------------------------------------------------------------
|
|
@@ -293,6 +324,7 @@ Controls: Sonos speakers, lights, YouTube queue
|
|
|
293
324
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
294
325
|
tools: [
|
|
295
326
|
switchToolDef,
|
|
327
|
+
switchDomainToolDef,
|
|
296
328
|
setUrlToolDef,
|
|
297
329
|
resetUrlToolDef,
|
|
298
330
|
...endpoints.map((ep) => ({
|
|
@@ -341,6 +373,22 @@ Controls: Sonos speakers, lights, YouTube queue
|
|
|
341
373
|
],
|
|
342
374
|
};
|
|
343
375
|
}
|
|
376
|
+
// Handle SwitchDomain
|
|
377
|
+
if (name === SWITCH_DOMAIN_TOOL_NAME) {
|
|
378
|
+
currentApiDomain = normalizeDomain(String(args.domain ?? "")) || null;
|
|
379
|
+
await loadEndpoints(currentEnvironment);
|
|
380
|
+
await server.sendToolListChanged();
|
|
381
|
+
return {
|
|
382
|
+
content: [
|
|
383
|
+
{
|
|
384
|
+
type: "text",
|
|
385
|
+
text: currentApiDomain
|
|
386
|
+
? `API calls now target ${currentApiDomain} ({service}.${currentApiDomain}).`
|
|
387
|
+
: "API domain reset to the environment default.",
|
|
388
|
+
},
|
|
389
|
+
],
|
|
390
|
+
};
|
|
391
|
+
}
|
|
344
392
|
// Handle SetServiceUrl
|
|
345
393
|
if (name === SET_URL_TOOL_NAME) {
|
|
346
394
|
const service = String(args.service ?? "");
|