@ivotoby/openapi-mcp-server 1.10.2 → 1.12.1
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/bundle.js +52 -4
- package/dist/cli.js +52 -4
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -14794,8 +14794,31 @@ var OpenAPISpecLoader = class {
|
|
|
14794
14794
|
}
|
|
14795
14795
|
}
|
|
14796
14796
|
}
|
|
14797
|
-
if (op.requestBody
|
|
14798
|
-
|
|
14797
|
+
if (op.requestBody) {
|
|
14798
|
+
let requestBodyObj;
|
|
14799
|
+
if ("$ref" in op.requestBody && typeof op.requestBody.$ref === "string") {
|
|
14800
|
+
const refMatch = op.requestBody.$ref.match(/^#\/components\/requestBodies\/(.+)$/);
|
|
14801
|
+
if (refMatch && spec.components?.requestBodies) {
|
|
14802
|
+
const requestBodyName = refMatch[1];
|
|
14803
|
+
const resolvedRequestBody = spec.components.requestBodies[requestBodyName];
|
|
14804
|
+
if (resolvedRequestBody && "content" in resolvedRequestBody) {
|
|
14805
|
+
requestBodyObj = resolvedRequestBody;
|
|
14806
|
+
} else {
|
|
14807
|
+
console.warn(
|
|
14808
|
+
`Could not resolve requestBody reference or invalid structure: ${op.requestBody.$ref}`
|
|
14809
|
+
);
|
|
14810
|
+
continue;
|
|
14811
|
+
}
|
|
14812
|
+
} else {
|
|
14813
|
+
console.warn(`Could not parse requestBody reference: ${op.requestBody.$ref}`);
|
|
14814
|
+
continue;
|
|
14815
|
+
}
|
|
14816
|
+
} else if ("content" in op.requestBody) {
|
|
14817
|
+
requestBodyObj = op.requestBody;
|
|
14818
|
+
} else {
|
|
14819
|
+
console.warn("Skipping requestBody due to invalid structure:", op.requestBody);
|
|
14820
|
+
continue;
|
|
14821
|
+
}
|
|
14799
14822
|
let mediaTypeObj;
|
|
14800
14823
|
if (requestBodyObj.content["application/json"]) {
|
|
14801
14824
|
mediaTypeObj = requestBodyObj.content["application/json"];
|
|
@@ -24024,18 +24047,32 @@ import {
|
|
|
24024
24047
|
import * as http2 from "http";
|
|
24025
24048
|
import { randomUUID } from "crypto";
|
|
24026
24049
|
var StreamableHttpServerTransport = class {
|
|
24050
|
+
// Track if using an external server
|
|
24027
24051
|
/**
|
|
24028
24052
|
* Initialize a new StreamableHttpServerTransport
|
|
24029
24053
|
*
|
|
24030
24054
|
* @param port HTTP port to listen on
|
|
24031
24055
|
* @param host Host to bind to (default: 127.0.0.1)
|
|
24032
24056
|
* @param endpointPath Endpoint path (default: /mcp)
|
|
24057
|
+
* @param server Optional HTTP server instance. If not provided, a new server will be created.
|
|
24058
|
+
* If provided, the transport will attach its request handler to the server.
|
|
24059
|
+
* Note: When using an external server, all handlers added via server.on('request', handler)
|
|
24060
|
+
* will be called for every request, in the order they were added. Custom handlers should be
|
|
24061
|
+
* added FIRST and should fully handle their routes (including sending responses) to prevent
|
|
24062
|
+
* further handlers from running for those requests. The MCP handler should be added after
|
|
24063
|
+
* custom handlers and will return early for non-MCP paths.
|
|
24033
24064
|
*/
|
|
24034
|
-
constructor(port, host = "127.0.0.1", endpointPath = "/mcp") {
|
|
24065
|
+
constructor(port, host = "127.0.0.1", endpointPath = "/mcp", server) {
|
|
24035
24066
|
this.port = port;
|
|
24036
24067
|
this.host = host;
|
|
24037
24068
|
this.endpointPath = endpointPath;
|
|
24038
|
-
this.
|
|
24069
|
+
this.isExternalServer = !!server;
|
|
24070
|
+
if (server) {
|
|
24071
|
+
this.server = server;
|
|
24072
|
+
this.server.on("request", this.handleRequest.bind(this));
|
|
24073
|
+
} else {
|
|
24074
|
+
this.server = http2.createServer(this.handleRequest.bind(this));
|
|
24075
|
+
}
|
|
24039
24076
|
}
|
|
24040
24077
|
server;
|
|
24041
24078
|
sessions = /* @__PURE__ */ new Map();
|
|
@@ -24046,6 +24083,7 @@ var StreamableHttpServerTransport = class {
|
|
|
24046
24083
|
requestSessionMap = /* @__PURE__ */ new Map();
|
|
24047
24084
|
// Maps request IDs to session IDs
|
|
24048
24085
|
healthCheckPath = "/health";
|
|
24086
|
+
isExternalServer;
|
|
24049
24087
|
/**
|
|
24050
24088
|
* Callback when message is received
|
|
24051
24089
|
*/
|
|
@@ -24094,6 +24132,13 @@ var StreamableHttpServerTransport = class {
|
|
|
24094
24132
|
}
|
|
24095
24133
|
}
|
|
24096
24134
|
this.sessions.clear();
|
|
24135
|
+
if (this.isExternalServer) {
|
|
24136
|
+
this.started = false;
|
|
24137
|
+
if (this.onclose) {
|
|
24138
|
+
this.onclose();
|
|
24139
|
+
}
|
|
24140
|
+
return;
|
|
24141
|
+
}
|
|
24097
24142
|
return new Promise((resolve5, reject) => {
|
|
24098
24143
|
this.server.close((err) => {
|
|
24099
24144
|
if (err) {
|
|
@@ -24212,6 +24257,9 @@ var StreamableHttpServerTransport = class {
|
|
|
24212
24257
|
return;
|
|
24213
24258
|
}
|
|
24214
24259
|
if (req.url !== this.endpointPath) {
|
|
24260
|
+
if (this.isExternalServer) {
|
|
24261
|
+
return;
|
|
24262
|
+
}
|
|
24215
24263
|
res.writeHead(404);
|
|
24216
24264
|
res.end();
|
|
24217
24265
|
return;
|
package/dist/cli.js
CHANGED
|
@@ -14794,8 +14794,31 @@ var OpenAPISpecLoader = class {
|
|
|
14794
14794
|
}
|
|
14795
14795
|
}
|
|
14796
14796
|
}
|
|
14797
|
-
if (op.requestBody
|
|
14798
|
-
|
|
14797
|
+
if (op.requestBody) {
|
|
14798
|
+
let requestBodyObj;
|
|
14799
|
+
if ("$ref" in op.requestBody && typeof op.requestBody.$ref === "string") {
|
|
14800
|
+
const refMatch = op.requestBody.$ref.match(/^#\/components\/requestBodies\/(.+)$/);
|
|
14801
|
+
if (refMatch && spec.components?.requestBodies) {
|
|
14802
|
+
const requestBodyName = refMatch[1];
|
|
14803
|
+
const resolvedRequestBody = spec.components.requestBodies[requestBodyName];
|
|
14804
|
+
if (resolvedRequestBody && "content" in resolvedRequestBody) {
|
|
14805
|
+
requestBodyObj = resolvedRequestBody;
|
|
14806
|
+
} else {
|
|
14807
|
+
console.warn(
|
|
14808
|
+
`Could not resolve requestBody reference or invalid structure: ${op.requestBody.$ref}`
|
|
14809
|
+
);
|
|
14810
|
+
continue;
|
|
14811
|
+
}
|
|
14812
|
+
} else {
|
|
14813
|
+
console.warn(`Could not parse requestBody reference: ${op.requestBody.$ref}`);
|
|
14814
|
+
continue;
|
|
14815
|
+
}
|
|
14816
|
+
} else if ("content" in op.requestBody) {
|
|
14817
|
+
requestBodyObj = op.requestBody;
|
|
14818
|
+
} else {
|
|
14819
|
+
console.warn("Skipping requestBody due to invalid structure:", op.requestBody);
|
|
14820
|
+
continue;
|
|
14821
|
+
}
|
|
14799
14822
|
let mediaTypeObj;
|
|
14800
14823
|
if (requestBodyObj.content["application/json"]) {
|
|
14801
14824
|
mediaTypeObj = requestBodyObj.content["application/json"];
|
|
@@ -24024,18 +24047,32 @@ import {
|
|
|
24024
24047
|
import * as http2 from "http";
|
|
24025
24048
|
import { randomUUID } from "crypto";
|
|
24026
24049
|
var StreamableHttpServerTransport = class {
|
|
24050
|
+
// Track if using an external server
|
|
24027
24051
|
/**
|
|
24028
24052
|
* Initialize a new StreamableHttpServerTransport
|
|
24029
24053
|
*
|
|
24030
24054
|
* @param port HTTP port to listen on
|
|
24031
24055
|
* @param host Host to bind to (default: 127.0.0.1)
|
|
24032
24056
|
* @param endpointPath Endpoint path (default: /mcp)
|
|
24057
|
+
* @param server Optional HTTP server instance. If not provided, a new server will be created.
|
|
24058
|
+
* If provided, the transport will attach its request handler to the server.
|
|
24059
|
+
* Note: When using an external server, all handlers added via server.on('request', handler)
|
|
24060
|
+
* will be called for every request, in the order they were added. Custom handlers should be
|
|
24061
|
+
* added FIRST and should fully handle their routes (including sending responses) to prevent
|
|
24062
|
+
* further handlers from running for those requests. The MCP handler should be added after
|
|
24063
|
+
* custom handlers and will return early for non-MCP paths.
|
|
24033
24064
|
*/
|
|
24034
|
-
constructor(port, host = "127.0.0.1", endpointPath = "/mcp") {
|
|
24065
|
+
constructor(port, host = "127.0.0.1", endpointPath = "/mcp", server) {
|
|
24035
24066
|
this.port = port;
|
|
24036
24067
|
this.host = host;
|
|
24037
24068
|
this.endpointPath = endpointPath;
|
|
24038
|
-
this.
|
|
24069
|
+
this.isExternalServer = !!server;
|
|
24070
|
+
if (server) {
|
|
24071
|
+
this.server = server;
|
|
24072
|
+
this.server.on("request", this.handleRequest.bind(this));
|
|
24073
|
+
} else {
|
|
24074
|
+
this.server = http2.createServer(this.handleRequest.bind(this));
|
|
24075
|
+
}
|
|
24039
24076
|
}
|
|
24040
24077
|
server;
|
|
24041
24078
|
sessions = /* @__PURE__ */ new Map();
|
|
@@ -24046,6 +24083,7 @@ var StreamableHttpServerTransport = class {
|
|
|
24046
24083
|
requestSessionMap = /* @__PURE__ */ new Map();
|
|
24047
24084
|
// Maps request IDs to session IDs
|
|
24048
24085
|
healthCheckPath = "/health";
|
|
24086
|
+
isExternalServer;
|
|
24049
24087
|
/**
|
|
24050
24088
|
* Callback when message is received
|
|
24051
24089
|
*/
|
|
@@ -24094,6 +24132,13 @@ var StreamableHttpServerTransport = class {
|
|
|
24094
24132
|
}
|
|
24095
24133
|
}
|
|
24096
24134
|
this.sessions.clear();
|
|
24135
|
+
if (this.isExternalServer) {
|
|
24136
|
+
this.started = false;
|
|
24137
|
+
if (this.onclose) {
|
|
24138
|
+
this.onclose();
|
|
24139
|
+
}
|
|
24140
|
+
return;
|
|
24141
|
+
}
|
|
24097
24142
|
return new Promise((resolve5, reject) => {
|
|
24098
24143
|
this.server.close((err) => {
|
|
24099
24144
|
if (err) {
|
|
@@ -24212,6 +24257,9 @@ var StreamableHttpServerTransport = class {
|
|
|
24212
24257
|
return;
|
|
24213
24258
|
}
|
|
24214
24259
|
if (req.url !== this.endpointPath) {
|
|
24260
|
+
if (this.isExternalServer) {
|
|
24261
|
+
return;
|
|
24262
|
+
}
|
|
24215
24263
|
res.writeHead(404);
|
|
24216
24264
|
res.end();
|
|
24217
24265
|
return;
|