@tyvm/swagger-mcp 0.0.13 → 0.0.16

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.
Files changed (44) hide show
  1. package/README.md +7 -0
  2. package/dist/core/cache.d.ts +50 -0
  3. package/dist/core/cache.d.ts.map +1 -0
  4. package/dist/core/cache.js +104 -0
  5. package/dist/core/cache.js.map +1 -0
  6. package/dist/core/core.d.ts +11 -0
  7. package/dist/core/core.d.ts.map +1 -0
  8. package/dist/core/core.js +55 -0
  9. package/dist/core/core.js.map +1 -0
  10. package/dist/core/execute.d.ts +28 -0
  11. package/dist/core/execute.d.ts.map +1 -0
  12. package/dist/core/execute.js +159 -0
  13. package/dist/core/execute.js.map +1 -0
  14. package/dist/core/index.d.ts +30 -0
  15. package/dist/core/index.d.ts.map +1 -0
  16. package/dist/core/index.js +156 -0
  17. package/dist/core/index.js.map +1 -0
  18. package/dist/core/jsonrpc.d.ts +74 -0
  19. package/dist/core/jsonrpc.d.ts.map +1 -0
  20. package/dist/core/jsonrpc.js +148 -0
  21. package/dist/core/jsonrpc.js.map +1 -0
  22. package/dist/core/openapi.d.ts +20 -0
  23. package/dist/core/openapi.d.ts.map +1 -0
  24. package/dist/core/openapi.js +175 -0
  25. package/dist/core/openapi.js.map +1 -0
  26. package/dist/core/types.d.ts +126 -0
  27. package/dist/core/types.d.ts.map +1 -0
  28. package/dist/core/types.js +7 -0
  29. package/dist/core/types.js.map +1 -0
  30. package/dist/generator.d.ts +1 -3
  31. package/dist/generator.d.ts.map +1 -1
  32. package/dist/generator.js +8 -204
  33. package/dist/generator.js.map +1 -1
  34. package/dist/index.d.ts +4 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +34 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/proxy-runtime.d.ts +27 -0
  39. package/dist/proxy-runtime.d.ts.map +1 -0
  40. package/dist/proxy-runtime.js +383 -0
  41. package/dist/proxy-runtime.js.map +1 -0
  42. package/dist/types.d.ts +6 -0
  43. package/dist/types.d.ts.map +1 -1
  44. package/package.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Generate MCP (Model Context Protocol) servers from Swagger/OpenAPI specifications.
4
4
 
5
+ ## Two Ways to Use
6
+
7
+ 1. **Code Generation** - Generate a standalone MCP server package for deployment
8
+ 2. **Stateless Proxy** - Dynamically serve MCP tools from any Swagger spec at runtime (see [PROXY.md](PROXY.md))
9
+
10
+ ## Code Generation Mode
11
+
5
12
  ## Usage
6
13
 
7
14
  ```bash
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Simple LRU cache for operation indexes
3
+ * Avoids re-parsing swagger specs on every request
4
+ */
5
+ import { SwaggerSpec, Tool, OperationIndex } from './types';
6
+ interface CacheEntry {
7
+ swaggerSpec: SwaggerSpec;
8
+ tools: Tool[];
9
+ operations: OperationIndex[];
10
+ timestamp: number;
11
+ }
12
+ /**
13
+ * Simple LRU cache for swagger operation indexes
14
+ */
15
+ export declare class OperationIndexCache {
16
+ private cache;
17
+ private maxSize;
18
+ private ttlMs;
19
+ constructor(maxSize?: number, ttlMs?: number);
20
+ /**
21
+ * Get a cached entry by key (e.g., swagger hash)
22
+ */
23
+ get(key: string): CacheEntry | null;
24
+ /**
25
+ * Set a cache entry
26
+ */
27
+ set(key: string, swaggerSpec: SwaggerSpec): CacheEntry;
28
+ /**
29
+ * Clear the entire cache
30
+ */
31
+ clear(): void;
32
+ /**
33
+ * Get current cache size
34
+ */
35
+ size(): number;
36
+ /**
37
+ * Remove expired entries
38
+ */
39
+ cleanup(): void;
40
+ }
41
+ /**
42
+ * Get the global cache instance
43
+ */
44
+ export declare function getGlobalCache(): OperationIndexCache;
45
+ /**
46
+ * Reset the global cache (useful for testing)
47
+ */
48
+ export declare function resetGlobalCache(): void;
49
+ export {};
50
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/core/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG5D,UAAU,UAAU;IAClB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAS;gBAEV,OAAO,GAAE,MAAY,EAAE,KAAK,GAAE,MAAgB;IAO1D;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAoBnC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,UAAU;IAsBtD;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;OAEG;IACH,OAAO,IAAI,IAAI;CAQhB;AAOD;;GAEG;AACH,wBAAgB,cAAc,IAAI,mBAAmB,CAKpD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * Simple LRU cache for operation indexes
4
+ * Avoids re-parsing swagger specs on every request
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.resetGlobalCache = exports.getGlobalCache = exports.OperationIndexCache = void 0;
8
+ const index_1 = require("./index");
9
+ /**
10
+ * Simple LRU cache for swagger operation indexes
11
+ */
12
+ class OperationIndexCache {
13
+ constructor(maxSize = 100, ttlMs = 3600000) {
14
+ // Default: 100 entries, 1 hour TTL
15
+ this.cache = new Map();
16
+ this.maxSize = maxSize;
17
+ this.ttlMs = ttlMs;
18
+ }
19
+ /**
20
+ * Get a cached entry by key (e.g., swagger hash)
21
+ */
22
+ get(key) {
23
+ const entry = this.cache.get(key);
24
+ if (!entry) {
25
+ return null;
26
+ }
27
+ // Check if expired
28
+ if (Date.now() - entry.timestamp > this.ttlMs) {
29
+ this.cache.delete(key);
30
+ return null;
31
+ }
32
+ // Move to end (LRU)
33
+ this.cache.delete(key);
34
+ this.cache.set(key, entry);
35
+ return entry;
36
+ }
37
+ /**
38
+ * Set a cache entry
39
+ */
40
+ set(key, swaggerSpec) {
41
+ // Build tools and operations
42
+ const tools = (0, index_1.generateToolsFromSwagger)(swaggerSpec);
43
+ const operations = (0, index_1.buildOperationIndex)(swaggerSpec);
44
+ const entry = {
45
+ swaggerSpec,
46
+ tools,
47
+ operations,
48
+ timestamp: Date.now(),
49
+ };
50
+ // Evict oldest entry if at capacity
51
+ if (this.cache.size >= this.maxSize) {
52
+ const oldestKey = this.cache.keys().next().value;
53
+ this.cache.delete(oldestKey);
54
+ }
55
+ this.cache.set(key, entry);
56
+ return entry;
57
+ }
58
+ /**
59
+ * Clear the entire cache
60
+ */
61
+ clear() {
62
+ this.cache.clear();
63
+ }
64
+ /**
65
+ * Get current cache size
66
+ */
67
+ size() {
68
+ return this.cache.size;
69
+ }
70
+ /**
71
+ * Remove expired entries
72
+ */
73
+ cleanup() {
74
+ const now = Date.now();
75
+ for (const [key, entry] of this.cache.entries()) {
76
+ if (now - entry.timestamp > this.ttlMs) {
77
+ this.cache.delete(key);
78
+ }
79
+ }
80
+ }
81
+ }
82
+ exports.OperationIndexCache = OperationIndexCache;
83
+ /**
84
+ * Global cache instance (singleton)
85
+ */
86
+ let globalCache = null;
87
+ /**
88
+ * Get the global cache instance
89
+ */
90
+ function getGlobalCache() {
91
+ if (!globalCache) {
92
+ globalCache = new OperationIndexCache();
93
+ }
94
+ return globalCache;
95
+ }
96
+ exports.getGlobalCache = getGlobalCache;
97
+ /**
98
+ * Reset the global cache (useful for testing)
99
+ */
100
+ function resetGlobalCache() {
101
+ globalCache = null;
102
+ }
103
+ exports.resetGlobalCache = resetGlobalCache;
104
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/core/cache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,mCAAwE;AASxE;;GAEG;AACH,MAAa,mBAAmB;IAK9B,YAAY,UAAkB,GAAG,EAAE,QAAgB,OAAO;QACxD,mCAAmC;QACnC,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAW;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,IAAI,CAAC;SACb;QAED,mBAAmB;QACnB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,EAAE;YAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,IAAI,CAAC;SACb;QAED,oBAAoB;QACpB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAE3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,GAAW,EAAE,WAAwB;QACvC,6BAA6B;QAC7B,MAAM,KAAK,GAAG,IAAA,gCAAwB,EAAC,WAAW,CAAC,CAAC;QACpD,MAAM,UAAU,GAAG,IAAA,2BAAmB,EAAC,WAAW,CAAC,CAAC;QAEpD,MAAM,KAAK,GAAe;YACxB,WAAW;YACX,KAAK;YACL,UAAU;YACV,S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@@
1
+ /**
2
+ * Core swagger-mcp runtime
3
+ * Exports all core functionality for reuse
4
+ */
5
+ export * from './types';
6
+ export { resolveSchemaRef, convertSwaggerTypeToToolProp, validateBaseUrl, } from './openapi';
7
+ export { buildOperationIndex, findOperation, generateToolsFromSwagger, filterToolsByAllowlist, } from './index';
8
+ export { replacePathParams, executeOperation, DynamicSwaggerClient, } from './execute';
9
+ export { JsonRpcRequest, JsonRpcResponse, JsonRpcError, JsonRpcErrorCodes, createErrorResponse, createSuccessResponse, validateJsonRpcRequest, handleInitialize, handleToolsList, handleToolsCall, routeJsonRpcRequest, } from './jsonrpc';
10
+ export { OperationIndexCache, getGlobalCache, resetGlobalCache, } from './cache';
11
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/core/core.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,eAAe,GAChB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,cAAc,EACd,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,mBAAmB,GACpB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,GACjB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * Core swagger-mcp runtime
4
+ * Exports all core functionality for reuse
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.resetGlobalCache = exports.getGlobalCache = exports.OperationIndexCache = exports.routeJsonRpcRequest = exports.handleToolsCall = exports.handleToolsList = exports.handleInitialize = exports.validateJsonRpcRequest = exports.createSuccessResponse = exports.createErrorResponse = exports.JsonRpcErrorCodes = exports.DynamicSwaggerClient = exports.executeOperation = exports.replacePathParams = exports.filterToolsByAllowlist = exports.generateToolsFromSwagger = exports.findOperation = exports.buildOperationIndex = exports.validateBaseUrl = exports.convertSwaggerTypeToToolProp = exports.resolveSchemaRef = void 0;
22
+ // Types
23
+ __exportStar(require("./types"), exports);
24
+ // OpenAPI utilities
25
+ var openapi_1 = require("./openapi");
26
+ Object.defineProperty(exports, "resolveSchemaRef", { enumerable: true, get: function () { return openapi_1.resolveSchemaRef; } });
27
+ Object.defineProperty(exports, "convertSwaggerTypeToToolProp", { enumerable: true, get: function () { return openapi_1.convertSwaggerTypeToToolProp; } });
28
+ Object.defineProperty(exports, "validateBaseUrl", { enumerable: true, get: function () { return openapi_1.validateBaseUrl; } });
29
+ // Index building
30
+ var index_1 = require("./index");
31
+ Object.defineProperty(exports, "buildOperationIndex", { enumerable: true, get: function () { return index_1.buildOperationIndex; } });
32
+ Object.defineProperty(exports, "findOperation", { enumerable: true, get: function () { return index_1.findOperation; } });
33
+ Object.defineProperty(exports, "generateToolsFromSwagger", { enumerable: true, get: function () { return index_1.generateToolsFromSwagger; } });
34
+ Object.defineProperty(exports, "filterToolsByAllowlist", { enumerable: true, get: function () { return index_1.filterToolsByAllowlist; } });
35
+ // Execution
36
+ var execute_1 = require("./execute");
37
+ Object.defineProperty(exports, "replacePathParams", { enumerable: true, get: function () { return execute_1.replacePathParams; } });
38
+ Object.defineProperty(exports, "executeOperation", { enumerable: true, get: function () { return execute_1.executeOperation; } });
39
+ Object.defineProperty(exports, "DynamicSwaggerClient", { enumerable: true, get: function () { return execute_1.DynamicSwaggerClient; } });
40
+ // JSON-RPC protocol
41
+ var jsonrpc_1 = require("./jsonrpc");
42
+ Object.defineProperty(exports, "JsonRpcErrorCodes", { enumerable: true, get: function () { return jsonrpc_1.JsonRpcErrorCodes; } });
43
+ Object.defineProperty(exports, "createErrorResponse", { enumerable: true, get: function () { return jsonrpc_1.createErrorResponse; } });
44
+ Object.defineProperty(exports, "createSuccessResponse", { enumerable: true, get: function () { return jsonrpc_1.createSuccessResponse; } });
45
+ Object.defineProperty(exports, "validateJsonRpcRequest", { enumerable: true, get: function () { return jsonrpc_1.validateJsonRpcRequest; } });
46
+ Object.defineProperty(exports, "handleInitialize", { enumerable: true, get: function () { return jsonrpc_1.handleInitialize; } });
47
+ Object.defineProperty(exports, "handleToolsList", { enumerable: true, get: function () { return jsonrpc_1.handleToolsList; } });
48
+ Object.defineProperty(exports, "handleToolsCall", { enumerable: true, get: function () { return jsonrpc_1.handleToolsCall; } });
49
+ Object.defineProperty(exports, "routeJsonRpcRequest", { enumerable: true, get: function () { return jsonrpc_1.routeJsonRpcRequest; } });
50
+ // Caching
51
+ var cache_1 = require("./cache");
52
+ Object.defineProperty(exports, "OperationIndexCache", { enumerable: true, get: function () { return cache_1.OperationIndexCache; } });
53
+ Object.defineProperty(exports, "getGlobalCache", { enumerable: true, get: function () { return cache_1.getGlobalCache; } });
54
+ Object.defineProperty(exports, "resetGlobalCache", { enumerable: true, get: function () { return cache_1.resetGlobalCache; } });
55
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core/core.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;AAEH,QAAQ;AACR,0CAAwB;AAExB,oBAAoB;AACpB,qCAImB;AAHjB,2GAAA,gBAAgB,OAAA;AAChB,uHAAA,4BAA4B,OAAA;AAC5B,0GAAA,eAAe,OAAA;AAGjB,iBAAiB;AACjB,iCAKiB;AAJf,4GAAA,mBAAmB,OAAA;AACnB,sGAAA,aAAa,OAAA;AACb,iHAAA,wBAAwB,OAAA;AACxB,+GAAA,sBAAsB,OAAA;AAGxB,YAAY;AACZ,qCAImB;AAHjB,4GAAA,iBAAiB,OAAA;AACjB,2GAAA,gBAAgB,OAAA;AAChB,+GAAA,oBAAoB,OAAA;AAGtB,oBAAoB;AACpB,qCAYmB;AARjB,4GAAA,iBAAiB,OAAA;AACjB,8GAAA,mBAAmB,OAAA;AACnB,gHAAA,qBAAqB,OAAA;AACrB,iHAAA,sBAAsB,OAAA;AACtB,2GAAA,gBAAgB,OAAA;AAChB,0GAAA,eAAe,OAAA;AACf,0GAAA,eAAe,OAAA;AACf,8GAAA,mBAAmB,OAAA;AAGrB,UAAU;AACV,iCAIiB;AAHf,4GAAA,mBAAmB,OAAA;AACnB,uGAAA,cAAc,OAAA;AACd,yGAAA,gBAAgB,OAAA"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * HTTP request builder and executor for swagger operations
3
+ */
4
+ import { SwaggerSpec, ExecuteOptions, ExecuteResult, OperationIndex } from "./types";
5
+ /**
6
+ * Replace path parameters in a URL path with actual values
7
+ * Example: /users/{userId}/posts -> /users/123/posts
8
+ */
9
+ export declare function replacePathParams(path: string, params: Record<string, any>): string;
10
+ /**
11
+ * Execute an HTTP operation against a swagger API
12
+ * Handles path parameters, query parameters, and request bodies
13
+ */
14
+ export declare function executeOperation(swaggerSpec: SwaggerSpec, operation: OperationIndex, options: ExecuteOptions): Promise<ExecuteResult>;
15
+ /**
16
+ * DynamicSwaggerClient provides a high-level interface for calling swagger operations
17
+ */
18
+ export declare class DynamicSwaggerClient {
19
+ private baseUrl;
20
+ private swaggerSpec;
21
+ private headers;
22
+ constructor(baseUrl: string, swaggerSpec: SwaggerSpec, headers?: Record<string, string>);
23
+ /**
24
+ * Call an operation by its operationId
25
+ */
26
+ callOperation(operationId: string, params?: Record<string, any>): Promise<any>;
27
+ }
28
+ //# sourceMappingURL=execute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../src/core/execute.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,WAAW,EACX,cAAc,EACd,aAAa,EACb,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,MAAM,CAeR;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,CAgFxB;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,OAAO,CAAyB;gBAGtC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;IAUtC;;OAEG;IACG,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAC/B,OAAO,CAAC,GAAG,CAAC;CA0ChB"}
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ /**
3
+ * HTTP request builder and executor for swagger operations
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DynamicSwaggerClient = exports.executeOperation = exports.replacePathParams = void 0;
10
+ const axios_1 = __importDefault(require("axios"));
11
+ /**
12
+ * Replace path parameters in a URL path with actual values
13
+ * Example: /users/{userId}/posts -> /users/123/posts
14
+ */
15
+ function replacePathParams(path, params) {
16
+ let result = path;
17
+ const pathParams = path.match(/{([^}]+)}/g);
18
+ if (pathParams) {
19
+ for (const param of pathParams) {
20
+ const paramName = param.slice(1, -1);
21
+ if (params[paramName] !== undefined) {
22
+ result = result.replace(param, params[paramName]);
23
+ delete params[paramName];
24
+ }
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+ exports.replacePathParams = replacePathParams;
30
+ /**
31
+ * Execute an HTTP operation against a swagger API
32
+ * Handles path parameters, query parameters, and request bodies
33
+ */
34
+ async function executeOperation(swaggerSpec, operation, options) {
35
+ try {
36
+ // Clone parameters to avoid mutating the original
37
+ const params = { ...options.parameters };
38
+ // Replace path parameters
39
+ const path = replacePathParams(operation.path, params);
40
+ const fullUrl = options.baseUrl + path;
41
+ // Determine if this operation has a request body
42
+ const hasRequestBody = operation.operation.requestBody !== undefined;
43
+ // Prepare headers
44
+ const headers = {
45
+ "Content-Type": "application/json",
46
+ ...(options.headers || {}),
47
+ };
48
+ // Make the HTTP request
49
+ let response;
50
+ if (hasRequestBody) {
51
+ // Send remaining params as request body
52
+ response = await (0, axios_1.default)({
53
+ method: operation.method,
54
+ url: fullUrl,
55
+ data: params,
56
+ headers,
57
+ // Prevent following redirects for security
58
+ maxRedirects: 0,
59
+ validateStatus: (status) => status < 400,
60
+ });
61
+ }
62
+ else {
63
+ // Send remaining params as query parameters
64
+ response = await (0, axios_1.default)({
65
+ method: operation.method,
66
+ url: fullUrl,
67
+ params,
68
+ headers,
69
+ maxRedirects: 0,
70
+ validateStatus: (status) => status < 400,
71
+ });
72
+ }
73
+ return {
74
+ success: true,
75
+ data: response.data,
76
+ };
77
+ }
78
+ catch (error) {
79
+ let errorMessage = `Error calling ${options.operationId}: ${error.message}`;
80
+ if (error.response) {
81
+ errorMessage += `\n\nHTTP Status: ${error.response.status} ${error.response.statusText || ""}`;
82
+ if (error.response.data) {
83
+ errorMessage += `\nResponse Body: ${typeof error.response.data === "string"
84
+ ? error.response.data
85
+ : JSON.stringify(error.response.data, null, 2)}`;
86
+ }
87
+ }
88
+ else if (error.request) {
89
+ errorMessage += `\n\nNo response received from server`;
90
+ const requestDetails = {
91
+ method: error.request.method,
92
+ path: error.request.path,
93
+ timeout: error.request.timeout,
94
+ };
95
+ errorMessage += `\nRequest details: ${JSON.stringify(requestDetails, null, 2)}`;
96
+ }
97
+ return {
98
+ success: false,
99
+ error: errorMessage,
100
+ };
101
+ }
102
+ }
103
+ exports.executeOperation = executeOperation;
104
+ /**
105
+ * DynamicSwaggerClient provides a high-level interface for calling swagger operations
106
+ */
107
+ class DynamicSwaggerClient {
108
+ constructor(baseUrl, swaggerSpec, headers = {}) {
109
+ this.baseUrl = baseUrl;
110
+ this.swaggerSpec = swaggerSpec;
111
+ this.headers = {
112
+ "Content-Type": "application/json",
113
+ ...headers,
114
+ };
115
+ }
116
+ /**
117
+ * Call an operation by its operationId
118
+ */
119
+ async callOperation(operationId, params = {}) {
120
+ // Find the operation in the swagger spec
121
+ let foundOperation = null;
122
+ for (const [path, pathItem] of Object.entries(this.swaggerSpec.paths)) {
123
+ for (const [method, operation] of Object.entries(pathItem)) {
124
+ if (typeof operation !== "object" || !operation)
125
+ continue;
126
+ const opId = operation.operationId ||
127
+ `${method}_${path.replace(/[^a-zA-Z0-9]/g, "_")}`;
128
+ if (opId === operationId) {
129
+ foundOperation = {
130
+ operationId: opId,
131
+ path,
132
+ method,
133
+ operation,
134
+ summary: operation.summary || "",
135
+ description: operation.description || "",
136
+ };
137
+ break;
138
+ }
139
+ }
140
+ if (foundOperation)
141
+ break;
142
+ }
143
+ if (!foundOperation) {
144
+ throw new Error(`Operation ${operationId} not found in swagger spec`);
145
+ }
146
+ const result = await executeOperation(this.swaggerSpec, foundOperation, {
147
+ baseUrl: this.baseUrl,
148
+ operationId,
149
+ parameters: params,
150
+ headers: this.headers,
151
+ });
152
+ if (!result.success) {
153
+ throw new Error(result.error);
154
+ }
155
+ return result.data;
156
+ }
157
+ }
158
+ exports.DynamicSwaggerClient = DynamicSwaggerClient;
159
+ //# sourceMappingURL=execute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/core/execute.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,kDAA0B;AAQ1B;;;GAGG;AACH,SAAgB,iBAAiB,CAC/B,IAAY,EACZ,MAA2B;IAE3B,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAE5C,IAAI,UAAU,EAAE;QACd,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;YAC9B,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACrC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,SAAS,EAAE;gBACnC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;gBAClD,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;aAC1B;SACF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAlBD,8CAkBC;AAED;;;GAGG;AACI,KAAK,UAAU,gBAAgB,CACpC,WAAwB,EACxB,SAAyB,EACzB,OAAuB;IAEvB,IAAI;QACF,kDAAkD;QAClD,MAAM,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;QAEzC,0BAA0B;QAC1B,MAAM,IAAI,GAAG,iBAAiB,CAAC,SAAS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CP tools
4
+ */
5
+ import { SwaggerSpec, Tool, OperationIndex } from './types';
6
+ import { validateBaseUrl as validateBaseUrlImpl } from './openapi';
7
+ /**
8
+ * Build an index of all operations in a swagger spec for fast lookup
9
+ */
10
+ export declare function buildOperationIndex(swaggerSpec: SwaggerSpec): OperationIndex[];
11
+ /**
12
+ * Find an operation by its operationId
13
+ */
14
+ export declare function findOperation(operations: OperationIndex[], operationId: string): OperationIndex | null;
15
+ /**
16
+ * Generate MCP tools from a swagger specification
17
+ * Converts all operations to MCP tool definitions
18
+ */
19
+ export declare function generateToolsFromSwagger(swaggerSpec: SwaggerSpec): Tool[];
20
+ /**
21
+ * Filter tools by an allowlist of operation IDs
22
+ * If allowlist is empty or undefined, returns all tools
23
+ */
24
+ export declare function filterToolsByAllowlist(tools: Tool[], allowlist?: string[]): Tool[];
25
+ /**
26
+ * Re-export validateBaseUrl from openapi module
27
+ * Validates that a baseUrl is safe and matches the swagger spec servers
28
+ */
29
+ export declare const validateBaseUrl: typeof validateBaseUrlImpl;
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,IAAI,EAAY,cAAc,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAkD,eAAe,IAAI,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEnH;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,cAAc,EAAE,CAuB9E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,cAAc,EAAE,EAC5B,WAAW,EAAE,MAAM,GAClB,cAAc,GAAG,IAAI,CAEvB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,EAAE,CA2GzE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAMlF;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,4BAAsB,CAAC"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ /**
3
+ * Operation index building from OpenAPI/Swagger specs
4
+ * Converts swagger paths to MCP tools
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.validateBaseUrl = exports.filterToolsByAllowlist = exports.generateToolsFromSwagger = exports.findOperation = exports.buildOperationIndex = void 0;
8
+ const openapi_1 = require("./openapi");
9
+ /**
10
+ * Build an index of all operations in a swagger spec for fast lookup
11
+ */
12
+ function buildOperationIndex(swaggerSpec) {
13
+ const operations = [];
14
+ for (const [path, pathItem] of Object.entries(swaggerSpec.paths)) {
15
+ for (const [method, operation] of Object.entries(pathItem)) {
16
+ if (typeof operation !== 'object' || !operation)
17
+ continue;
18
+ const operationId = operation.operationId || `${method}_${path.replace(/[^a-zA-Z0-9]/g, '_')}`;
19
+ const summary = operation.summary || `${method.toUpperCase()} ${path}`;
20
+ const description = operation.description || summary;
21
+ operations.push({
22
+ operationId,
23
+ path,
24
+ method,
25
+ operation,
26
+ summary,
27
+ description,
28
+ });
29
+ }
30
+ }
31
+ return operations;
32
+ }
33
+ exports.buildOperationIndex = buildOperationIndex;
34
+ /**
35
+ * Find an operation by its operationId
36
+ */
37
+ function findOperation(operations, operationId) {
38
+ return operations.find((op) => op.operationId === operationId) || null;
39
+ }
40
+ exports.findOperation = findOperation;
41
+ /**
42
+ * Generate MCP tools from a swagger specification
43
+ * Converts all operations to MCP tool definitions
44
+ */
45
+ function generateToolsFromSwagger(swaggerSpec) {
46
+ const tools = [];
47
+ for (const [path, pathItem] of Object.entries(swaggerSpec.paths)) {
48
+ for (const [method, operation] of Object.entries(pathItem)) {
49
+ if (typeof operation !== 'object' || !operation)
50
+ continue;
51
+ const operationId = operation.operationId || `${method}_${path.replace(/[^a-zA-Z0-9]/g, '_')}`;
52
+ const summary = operation.summary || `${method.toUpperCase()} ${path}`;
53
+ const description = operation.description || summary;
54
+ const properties = {};
55
+ const required = [];
56
+ // Add path parameters
57
+ const pathParams = path.match(/{([^}]+)}/g);
58
+ if (pathParams) {
59
+ for (const param of pathParams) {
60
+ const paramName = param.slice(1, -1);
61
+ properties[paramName] = {
62
+ type: 'string',
63
+ description: `Path parameter: ${paramName}`,
64
+ };
65
+ required.push(paramName);
66
+ }
67
+ }
68
+ // Add query parameters (excluding header parameters which are provided separately)
69
+ if (operation.parameters) {
70
+ for (const param of operation.parameters) {
71
+ // Only include query parameters; skip header and path parameters
72
+ if (param.in === 'query') {
73
+ // Skip common authentication parameters - these are injected by the proxy layer
74
+ const excludedAuthParams = ["token", "api_key", "apikey", "access_token", "auth", "authorization"];
75
+ if (excludedAuthParams.includes(param.name.toLowerCase())) {
76
+ continue;
77
+ }
78
+ let schema = param.schema || param;
79
+ if (schema && schema.$ref) {
80
+ schema = (0, openapi_1.resolveSchemaRef)(schema.$ref, swaggerSpec);
81
+ }
82
+ else if (!schema || !schema.type) {
83
+ schema = {
84
+ type: param.type || 'string',
85
+ description: param.description,
86
+ };
87
+ }
88
+ properties[param.name] = (0, openapi_1.convertSwaggerTypeToToolProp)(schema, swaggerSpec);
89
+ if (!properties[param.name].description) {
90
+ properties[param.name].description = param.description || `Query parameter: ${param.name}`;
91
+ }
92
+ if (param.required) {
93
+ required.push(param.name);
94
+ }
95
+ }
96
+ }
97
+ }
98
+ // Add request body properties
99
+ if (operation.requestBody) {
100
+ const content = operation.requestBody.content;
101
+ // Check if content exists before accessing it
102
+ if (!content) {
103
+ console.warn(`Operation ${operationId} has requestBody but no content`);
104
+ }
105
+ else {
106
+ // Support both JSON and form-encoded content types
107
+ const jsonContent = content['application/json'] || content['application/x-www-form-urlencoded'];
108
+ if (jsonContent && jsonContent.schema) {
109
+ let schema = jsonContent.schema;
110
+ if (schema.$ref) {
111
+ schema = (0, openapi_1.resolveSchemaRef)(schema.$ref, swaggerSpec);
112
+ }
113
+ if (schema.properties) {
114
+ for (const [key, value] of Object.entries(schema.properties)) {
115
+ const propSchema = (0, openapi_1.convertSwaggerTypeToToolProp)(value, swaggerSpec);
116
+ properties[key] = propSchema;
117
+ }
118
+ if (schema.required) {
119
+ required.push(...schema.required);
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ const tool = {
126
+ name: operationId,
127
+ description: description,
128
+ inputSchema: {
129
+ type: 'object',
130
+ properties,
131
+ required: Array.from(new Set(required)),
132
+ },
133
+ };
134
+ tools.push(tool);
135
+ }
136
+ }
137
+ return tools;
138
+ }
139
+ exports.generateToolsFromSwagger = generateToolsFromSwagger;
140
+ /**
141
+ * Filter tools by an allowlist of operation IDs
142
+ * If allowlist is empty or undefined, returns all tools
143
+ */
144
+ function filterToolsByAllowlist(tools, allowlist) {
145
+ if (!allowlist || allowlist.length === 0) {
146
+ return tools;
147
+ }
148
+ return tools.filter((tool) => allowlist.includes(tool.name));
149
+ }
150
+ exports.filterToolsByAllowlist = filterToolsByAllowlist;
151
+ /**
152
+ * Re-export validateBaseUrl from openapi module
153
+ * Validates that a baseUrl is safe and matches the swagger spec servers
154
+ */
155
+ exports.validateBaseUrl = openapi_1.validateBaseUrl;
156
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,uCAAmH;AAEnH;;GAEG;AACH,SAAgB,mBAAmB,CAAC,WAAwB;IAC1D,MAAM,UAAU,GAAqB,EAAE,CAAC;IAExC,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;QAChE,KAAK,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC1D,IAAI,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