@snokam/mcp-server 0.1.0 → 0.2.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/openapi-loader.js +64 -18
- package/package.json +5 -1
- package/specs/production/accounting.json +1131 -0
- package/specs/production/broker.json +109 -0
- package/specs/production/calculators.json +1523 -0
- package/specs/production/chatgpt.json +1655 -0
- package/specs/production/crypto.json +2104 -0
- package/specs/production/employees.json +1936 -0
- package/specs/production/events.json +2322 -0
- package/specs/production/office.json +1984 -0
- package/specs/production/power-office.json +2383 -0
- package/specs/production/sync.json +181 -0
- package/specs/production/webshop.json +631 -0
- package/specs/test/accounting.json +1131 -0
- package/specs/test/calculators.json +1523 -0
- package/specs/test/chatgpt.json +1655 -0
- package/specs/test/crypto.json +2104 -0
- package/specs/test/employees.json +1936 -0
- package/specs/test/events.json +2322 -0
- package/specs/test/power-office.json +2383 -0
- package/specs/test/sync.json +181 -0
- package/specs/test/webshop.json +631 -0
package/dist/openapi-loader.js
CHANGED
|
@@ -7,22 +7,26 @@
|
|
|
7
7
|
* MCP-compatible tool metadata.
|
|
8
8
|
*/
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
|
-
//
|
|
10
|
+
// Service discovery - reads from bundled specs directory at runtime
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
async function discoverServices(environment) {
|
|
13
|
+
try {
|
|
14
|
+
const { readdir } = await import("fs/promises");
|
|
15
|
+
const { fileURLToPath } = await import("url");
|
|
16
|
+
const { dirname, join } = await import("path");
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const specsDir = join(__dirname, "..", "specs", environment);
|
|
19
|
+
const files = await readdir(specsDir);
|
|
20
|
+
return files
|
|
21
|
+
.filter((f) => f.endsWith(".json"))
|
|
22
|
+
.map((f) => f.replace(".json", ""))
|
|
23
|
+
.sort();
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// No bundled specs found - return empty array
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
26
30
|
// ---------------------------------------------------------------------------
|
|
27
31
|
// Environment-aware URL resolution
|
|
28
32
|
// ---------------------------------------------------------------------------
|
|
@@ -96,8 +100,26 @@ function parseSpec(spec, service, baseUrl) {
|
|
|
96
100
|
// Public API
|
|
97
101
|
// ---------------------------------------------------------------------------
|
|
98
102
|
export async function fetchSpecs(environment) {
|
|
103
|
+
// Try to load bundled specs first (for speed)
|
|
104
|
+
try {
|
|
105
|
+
const bundledSpecs = await loadBundledSpecs(environment);
|
|
106
|
+
if (bundledSpecs.length > 0) {
|
|
107
|
+
console.error(`[snokam-mcp] Loaded ${bundledSpecs.length} endpoints from bundled specs (env=${environment})`);
|
|
108
|
+
return bundledSpecs;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error(`[snokam-mcp] Failed to load bundled specs, falling back to live fetch:`, error);
|
|
113
|
+
}
|
|
114
|
+
// Fallback to live fetching (slower, for development)
|
|
115
|
+
// Discover services from environment to know which APIs to fetch
|
|
116
|
+
const services = await discoverServices(environment);
|
|
117
|
+
if (services.length === 0) {
|
|
118
|
+
console.error("[snokam-mcp] No services discovered. Unable to fetch specs.");
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
99
121
|
const endpoints = [];
|
|
100
|
-
const results = await Promise.allSettled(
|
|
122
|
+
const results = await Promise.allSettled(services.map(async (service) => {
|
|
101
123
|
const baseUrl = getBaseUrl(service, environment);
|
|
102
124
|
const swaggerUrl = `${baseUrl}/swagger.json`;
|
|
103
125
|
const response = await fetch(swaggerUrl, {
|
|
@@ -118,9 +140,33 @@ export async function fetchSpecs(environment) {
|
|
|
118
140
|
}
|
|
119
141
|
else {
|
|
120
142
|
const idx = results.indexOf(result);
|
|
121
|
-
console.error(`[snokam-mcp] Failed to fetch ${
|
|
143
|
+
console.error(`[snokam-mcp] Failed to fetch ${services[idx]}: ${result.reason}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
console.error(`[snokam-mcp] Loaded ${endpoints.length} endpoints from ${successCount}/${services.length} services (env=${environment})`);
|
|
147
|
+
return endpoints;
|
|
148
|
+
}
|
|
149
|
+
async function loadBundledSpecs(environment) {
|
|
150
|
+
const { readFile } = await import("fs/promises");
|
|
151
|
+
const { fileURLToPath } = await import("url");
|
|
152
|
+
const { dirname, join } = await import("path");
|
|
153
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
154
|
+
const specsDir = join(__dirname, "..", "specs", environment);
|
|
155
|
+
// Discover which specs are bundled
|
|
156
|
+
const services = await discoverServices(environment);
|
|
157
|
+
const endpoints = [];
|
|
158
|
+
for (const service of services) {
|
|
159
|
+
try {
|
|
160
|
+
const specPath = join(specsDir, `${service}.json`);
|
|
161
|
+
const specData = await readFile(specPath, "utf-8");
|
|
162
|
+
const spec = JSON.parse(specData);
|
|
163
|
+
const baseUrl = getBaseUrl(service, environment);
|
|
164
|
+
endpoints.push(...parseSpec(spec, service, baseUrl));
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
// Spec file doesn't exist or is invalid, skip
|
|
168
|
+
continue;
|
|
122
169
|
}
|
|
123
170
|
}
|
|
124
|
-
console.error(`[snokam-mcp] Loaded ${endpoints.length} endpoints from ${successCount}/${SERVICES.length} services (env=${environment})`);
|
|
125
171
|
return endpoints;
|
|
126
172
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snokam/mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP server exposing Snokam backend APIs as tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
},
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"scripts": {
|
|
11
|
+
"bundle-specs": "node scripts/bundle-specs.js",
|
|
12
|
+
"bundle-specs:prod": "node scripts/bundle-specs.js production",
|
|
13
|
+
"bundle-specs:test": "node scripts/bundle-specs.js test",
|
|
14
|
+
"prebuild": "npm run bundle-specs:prod && npm run bundle-specs:test",
|
|
11
15
|
"build": "tsc",
|
|
12
16
|
"dev": "tsc --watch",
|
|
13
17
|
"start": "node dist/index.js"
|