@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.
@@ -7,22 +7,26 @@
7
7
  * MCP-compatible tool metadata.
8
8
  */
9
9
  // ---------------------------------------------------------------------------
10
- // Known services (functions that expose OpenAPI specs)
10
+ // Service discovery - reads from bundled specs directory at runtime
11
11
  // ---------------------------------------------------------------------------
12
- const SERVICES = [
13
- "accounting",
14
- "broker",
15
- "calculators",
16
- "chatgpt",
17
- "crypto",
18
- "employees",
19
- "events",
20
- "office",
21
- "platform",
22
- "power-office",
23
- "sync",
24
- "webshop",
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(SERVICES.map(async (service) => {
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 ${SERVICES[idx]}: ${result.reason}`);
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.1.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"