@snokam/mcp-api 0.9.0 → 0.11.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.d.ts +1 -1
- package/dist/index.js +35 -2
- package/dist/openapi-loader.d.ts +5 -0
- package/dist/openapi-loader.js +15 -0
- package/package.json +1 -1
- package/specs/production/accounting.json +5161 -527
- package/specs/production/broker.json +2 -2
- package/specs/production/chatgpt.json +21 -17
- package/specs/production/employees.json +350 -353
- package/specs/production/events.json +260 -176
- package/specs/production/notifications.json +10 -10
- package/specs/production/office.json +4 -4
- package/specs/production/recruitment.json +39 -0
- package/specs/production/sales.json +39 -0
- package/specs/production/sanity.json +127 -150
- package/specs/production/sync.json +181 -0
- package/specs/production/webshop.json +10 -10
- package/specs/test/accounting.json +5161 -527
- package/specs/test/broker.json +2 -2
- package/specs/test/chatgpt.json +21 -17
- package/specs/test/employees.json +350 -353
- package/specs/test/events.json +260 -176
- package/specs/test/notifications.json +10 -10
- package/specs/test/office.json +1984 -0
- package/specs/test/recruitment.json +39 -0
- package/specs/test/sales.json +39 -0
- package/specs/test/sanity.json +127 -150
- package/specs/test/sync.json +181 -0
- package/specs/test/webshop.json +10 -10
- package/specs/production/calculators.json +0 -1523
- package/specs/production/crypto.json +0 -1998
- package/specs/production/power-office.json +0 -2383
- package/specs/test/calculators.json +0 -1523
- package/specs/test/crypto.json +0 -1998
- package/specs/test/power-office.json +0 -2383
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Snokam MCP Server
|
|
3
|
+
* Snokam MCP Server — triggers spec refresh on rebuild
|
|
4
4
|
*
|
|
5
5
|
* Exposes Snokam backend APIs as MCP tools by reading bundled OpenAPI specs.
|
|
6
6
|
* Auth is handled via @azure/identity — supports Azure CLI (local),
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
10
10
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
11
|
import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
12
|
-
import { fetchSpecs } from "./openapi-loader.js";
|
|
12
|
+
import { fetchSpecs, fetchSpecFromUrl, } from "./openapi-loader.js";
|
|
13
13
|
import { getAccessToken } from "./auth.js";
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
15
15
|
// State
|
|
@@ -345,6 +345,39 @@ Controls: Sonos speakers, lights, YouTube queue
|
|
|
345
345
|
if (name === SET_URL_TOOL_NAME) {
|
|
346
346
|
const service = String(args.service ?? "");
|
|
347
347
|
const url = String(args.url ?? "");
|
|
348
|
+
const isLocal = url.startsWith("http://localhost") ||
|
|
349
|
+
url.startsWith("http://127.0.0.1");
|
|
350
|
+
// For localhost URLs, fetch the live swagger spec from the local function
|
|
351
|
+
// to pick up any new/changed endpoints during development
|
|
352
|
+
if (isLocal) {
|
|
353
|
+
try {
|
|
354
|
+
const liveEndpoints = await fetchSpecFromUrl(service, url);
|
|
355
|
+
// Remove old endpoints for this service
|
|
356
|
+
endpoints = endpoints.filter((ep) => ep.service !== service);
|
|
357
|
+
// Add the fresh ones
|
|
358
|
+
endpoints.push(...liveEndpoints);
|
|
359
|
+
// Rebuild lookup map
|
|
360
|
+
endpointsByTool = new Map();
|
|
361
|
+
for (const ep of endpoints) {
|
|
362
|
+
endpointsByTool.set(ep.toolName, ep);
|
|
363
|
+
}
|
|
364
|
+
serviceUrlOverrides.set(service, url);
|
|
365
|
+
await server.sendToolListChanged();
|
|
366
|
+
return {
|
|
367
|
+
content: [
|
|
368
|
+
{
|
|
369
|
+
type: "text",
|
|
370
|
+
text: `Overrode ${service} → ${url}. Loaded ${liveEndpoints.length} endpoints from local swagger.`,
|
|
371
|
+
},
|
|
372
|
+
],
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
// Fall through to static override if swagger fetch fails
|
|
377
|
+
console.error(`[snokam-mcp] Failed to fetch swagger from ${url}, falling back to static spec:`, error instanceof Error ? error.message : error);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
// Static override: just change the base URL on existing endpoints
|
|
348
381
|
const serviceEndpoints = endpoints.filter((ep) => ep.service === service);
|
|
349
382
|
if (serviceEndpoints.length === 0) {
|
|
350
383
|
const available = [
|
package/dist/openapi-loader.d.ts
CHANGED
|
@@ -42,5 +42,10 @@ interface OpenApiRequestBody {
|
|
|
42
42
|
schema?: Record<string, unknown>;
|
|
43
43
|
}>;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Fetch a swagger spec from a specific URL (e.g. a locally running function)
|
|
47
|
+
* and return parsed endpoints for that service.
|
|
48
|
+
*/
|
|
49
|
+
export declare function fetchSpecFromUrl(service: string, baseUrl: string): Promise<ApiEndpoint[]>;
|
|
45
50
|
export declare function fetchSpecs(environment: string): Promise<ApiEndpoint[]>;
|
|
46
51
|
export {};
|
package/dist/openapi-loader.js
CHANGED
|
@@ -101,6 +101,21 @@ function parseSpec(spec, service, baseUrl) {
|
|
|
101
101
|
// ---------------------------------------------------------------------------
|
|
102
102
|
// Public API
|
|
103
103
|
// ---------------------------------------------------------------------------
|
|
104
|
+
/**
|
|
105
|
+
* Fetch a swagger spec from a specific URL (e.g. a locally running function)
|
|
106
|
+
* and return parsed endpoints for that service.
|
|
107
|
+
*/
|
|
108
|
+
export async function fetchSpecFromUrl(service, baseUrl) {
|
|
109
|
+
const swaggerUrl = `${baseUrl}/swagger.json`;
|
|
110
|
+
const response = await fetch(swaggerUrl, {
|
|
111
|
+
signal: AbortSignal.timeout(10_000),
|
|
112
|
+
});
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
throw new Error(`HTTP ${response.status} from ${swaggerUrl}`);
|
|
115
|
+
}
|
|
116
|
+
const spec = (await response.json());
|
|
117
|
+
return parseSpec(spec, service, baseUrl);
|
|
118
|
+
}
|
|
104
119
|
export async function fetchSpecs(environment) {
|
|
105
120
|
// Try to load bundled specs first (for speed)
|
|
106
121
|
try {
|