@snokam/mcp-server 0.1.0 → 0.3.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 +97 -2
- package/dist/openapi-loader.d.ts +1 -0
- package/dist/openapi-loader.js +66 -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/broker.json +109 -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/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
10
10
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
12
12
|
import { fetchSpecs } from "./openapi-loader.js";
|
|
13
13
|
import { getAccessToken } from "./auth.js";
|
|
14
14
|
// ---------------------------------------------------------------------------
|
|
@@ -120,7 +120,102 @@ async function main() {
|
|
|
120
120
|
for (const ep of endpoints) {
|
|
121
121
|
endpointsByTool.set(ep.toolName, ep);
|
|
122
122
|
}
|
|
123
|
-
const server = new Server({
|
|
123
|
+
const server = new Server({
|
|
124
|
+
name: "snokam",
|
|
125
|
+
version: "0.2.0",
|
|
126
|
+
}, {
|
|
127
|
+
capabilities: {
|
|
128
|
+
tools: {},
|
|
129
|
+
resources: {},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
// List resources
|
|
133
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
134
|
+
resources: [
|
|
135
|
+
{
|
|
136
|
+
uri: "snokam://about",
|
|
137
|
+
name: "About Snøkam",
|
|
138
|
+
description: "Information about Snøkam and available API services",
|
|
139
|
+
mimeType: "text/markdown",
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
}));
|
|
143
|
+
// Read resource
|
|
144
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
145
|
+
const { uri } = request.params;
|
|
146
|
+
if (uri === "snokam://about") {
|
|
147
|
+
// Group endpoints by service with their descriptions
|
|
148
|
+
const serviceMap = new Map();
|
|
149
|
+
for (const ep of endpoints) {
|
|
150
|
+
const existing = serviceMap.get(ep.service);
|
|
151
|
+
if (existing) {
|
|
152
|
+
existing.count++;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
serviceMap.set(ep.service, {
|
|
156
|
+
count: 1,
|
|
157
|
+
description: ep.serviceDescription,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const serviceList = Array.from(serviceMap.entries())
|
|
162
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
163
|
+
.map(([service, { count, description }]) => {
|
|
164
|
+
return `- **${service}** (${count} endpoints): ${description}`;
|
|
165
|
+
})
|
|
166
|
+
.join("\n");
|
|
167
|
+
const about = `# Snøkam MCP Server
|
|
168
|
+
|
|
169
|
+
**Snøkam** is a Norwegian software consulting company. This MCP server provides programmatic access to Snøkam's internal backend APIs.
|
|
170
|
+
|
|
171
|
+
## Environment
|
|
172
|
+
|
|
173
|
+
Currently connected to: **${ENVIRONMENT}**
|
|
174
|
+
|
|
175
|
+
## Available Services
|
|
176
|
+
|
|
177
|
+
${serviceList}
|
|
178
|
+
|
|
179
|
+
## Authentication
|
|
180
|
+
|
|
181
|
+
- **Public endpoints**: No authentication required (e.g., \`employees__GetEmployeesPublic\`)
|
|
182
|
+
- **Protected endpoints**: Require Azure AD authentication (e.g., \`employees__GetEmployeesProtected\`)
|
|
183
|
+
|
|
184
|
+
## Common Use Cases
|
|
185
|
+
|
|
186
|
+
**Find out who works at Snøkam:**
|
|
187
|
+
\`\`\`
|
|
188
|
+
Use: employees__GetEmployeesPublic
|
|
189
|
+
Returns: List of all employees with names, roles, and technologies
|
|
190
|
+
\`\`\`
|
|
191
|
+
|
|
192
|
+
**Get upcoming events:**
|
|
193
|
+
\`\`\`
|
|
194
|
+
Use: events__GetPublicEvents (if available)
|
|
195
|
+
Returns: Company events and gatherings
|
|
196
|
+
\`\`\`
|
|
197
|
+
|
|
198
|
+
**Check office status or control music:**
|
|
199
|
+
\`\`\`
|
|
200
|
+
Use: office__* tools
|
|
201
|
+
Controls: Sonos speakers, lights, YouTube queue
|
|
202
|
+
\`\`\`
|
|
203
|
+
`;
|
|
204
|
+
return {
|
|
205
|
+
contents: [
|
|
206
|
+
{
|
|
207
|
+
uri,
|
|
208
|
+
mimeType: "text/markdown",
|
|
209
|
+
text: about,
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
contents: [],
|
|
216
|
+
isError: true,
|
|
217
|
+
};
|
|
218
|
+
});
|
|
124
219
|
// List tools
|
|
125
220
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
126
221
|
tools: endpoints.map((ep) => ({
|
package/dist/openapi-loader.d.ts
CHANGED
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
|
// ---------------------------------------------------------------------------
|
|
@@ -66,6 +70,7 @@ function parseSpec(spec, service, baseUrl) {
|
|
|
66
70
|
const paths = spec.paths;
|
|
67
71
|
if (!paths || Object.keys(paths).length === 0)
|
|
68
72
|
return endpoints;
|
|
73
|
+
const serviceDescription = spec.info.description || spec.info.title || "";
|
|
69
74
|
for (const [path, pathItem] of Object.entries(paths)) {
|
|
70
75
|
for (const method of ["get", "post", "put", "patch", "delete"]) {
|
|
71
76
|
const operation = pathItem[method];
|
|
@@ -77,6 +82,7 @@ function parseSpec(spec, service, baseUrl) {
|
|
|
77
82
|
const scope = extractScope(operation);
|
|
78
83
|
endpoints.push({
|
|
79
84
|
service,
|
|
85
|
+
serviceDescription,
|
|
80
86
|
toolName: makeToolName(service, operationId),
|
|
81
87
|
operationId,
|
|
82
88
|
method: method.toUpperCase(),
|
|
@@ -96,8 +102,26 @@ function parseSpec(spec, service, baseUrl) {
|
|
|
96
102
|
// Public API
|
|
97
103
|
// ---------------------------------------------------------------------------
|
|
98
104
|
export async function fetchSpecs(environment) {
|
|
105
|
+
// Try to load bundled specs first (for speed)
|
|
106
|
+
try {
|
|
107
|
+
const bundledSpecs = await loadBundledSpecs(environment);
|
|
108
|
+
if (bundledSpecs.length > 0) {
|
|
109
|
+
console.error(`[snokam-mcp] Loaded ${bundledSpecs.length} endpoints from bundled specs (env=${environment})`);
|
|
110
|
+
return bundledSpecs;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
console.error(`[snokam-mcp] Failed to load bundled specs, falling back to live fetch:`, error);
|
|
115
|
+
}
|
|
116
|
+
// Fallback to live fetching (slower, for development)
|
|
117
|
+
// Discover services from environment to know which APIs to fetch
|
|
118
|
+
const services = await discoverServices(environment);
|
|
119
|
+
if (services.length === 0) {
|
|
120
|
+
console.error("[snokam-mcp] No services discovered. Unable to fetch specs.");
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
99
123
|
const endpoints = [];
|
|
100
|
-
const results = await Promise.allSettled(
|
|
124
|
+
const results = await Promise.allSettled(services.map(async (service) => {
|
|
101
125
|
const baseUrl = getBaseUrl(service, environment);
|
|
102
126
|
const swaggerUrl = `${baseUrl}/swagger.json`;
|
|
103
127
|
const response = await fetch(swaggerUrl, {
|
|
@@ -118,9 +142,33 @@ export async function fetchSpecs(environment) {
|
|
|
118
142
|
}
|
|
119
143
|
else {
|
|
120
144
|
const idx = results.indexOf(result);
|
|
121
|
-
console.error(`[snokam-mcp] Failed to fetch ${
|
|
145
|
+
console.error(`[snokam-mcp] Failed to fetch ${services[idx]}: ${result.reason}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
console.error(`[snokam-mcp] Loaded ${endpoints.length} endpoints from ${successCount}/${services.length} services (env=${environment})`);
|
|
149
|
+
return endpoints;
|
|
150
|
+
}
|
|
151
|
+
async function loadBundledSpecs(environment) {
|
|
152
|
+
const { readFile } = await import("fs/promises");
|
|
153
|
+
const { fileURLToPath } = await import("url");
|
|
154
|
+
const { dirname, join } = await import("path");
|
|
155
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
156
|
+
const specsDir = join(__dirname, "..", "specs", environment);
|
|
157
|
+
// Discover which specs are bundled
|
|
158
|
+
const services = await discoverServices(environment);
|
|
159
|
+
const endpoints = [];
|
|
160
|
+
for (const service of services) {
|
|
161
|
+
try {
|
|
162
|
+
const specPath = join(specsDir, `${service}.json`);
|
|
163
|
+
const specData = await readFile(specPath, "utf-8");
|
|
164
|
+
const spec = JSON.parse(specData);
|
|
165
|
+
const baseUrl = getBaseUrl(service, environment);
|
|
166
|
+
endpoints.push(...parseSpec(spec, service, baseUrl));
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
// Spec file doesn't exist or is invalid, skip
|
|
170
|
+
continue;
|
|
122
171
|
}
|
|
123
172
|
}
|
|
124
|
-
console.error(`[snokam-mcp] Loaded ${endpoints.length} endpoints from ${successCount}/${SERVICES.length} services (env=${environment})`);
|
|
125
173
|
return endpoints;
|
|
126
174
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snokam/mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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"
|