@ivotoby/openapi-mcp-server 1.10.1 → 1.12.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/bundle.js CHANGED
@@ -18672,9 +18672,7 @@ var ApiClient = class {
18672
18672
  };
18673
18673
  }
18674
18674
  } else {
18675
- if (Object.keys(paramsCopy).length > 0) {
18676
- config.data = paramsCopy;
18677
- }
18675
+ config.data = Object.keys(paramsCopy).length > 0 ? paramsCopy : {};
18678
18676
  }
18679
18677
  const response = await this.axiosInstance(config);
18680
18678
  return response.data;
@@ -23980,6 +23978,18 @@ function loadConfig() {
23980
23978
  }
23981
23979
  const apiBaseUrl = argv["api-base-url"] || process.env.API_BASE_URL;
23982
23980
  const disableAbbreviation = argv["disable-abbreviation"] || (process.env.DISABLE_ABBREVIATION ? process.env.DISABLE_ABBREVIATION === "true" : false);
23981
+ const toolsModeInput = (typeof argv.tools === "string" ? argv.tools : void 0) || process.env.TOOLS_MODE;
23982
+ let toolsMode = "all";
23983
+ if (typeof toolsModeInput === "string" && toolsModeInput.trim().length > 0) {
23984
+ const normalized = toolsModeInput.toLowerCase();
23985
+ if (normalized === "all" || normalized === "dynamic" || normalized === "explicit") {
23986
+ toolsMode = normalized;
23987
+ } else {
23988
+ throw new Error(
23989
+ "Invalid tools mode. Expected one of: all, dynamic, explicit"
23990
+ );
23991
+ }
23992
+ }
23983
23993
  if (!apiBaseUrl) {
23984
23994
  throw new Error("API base URL is required (--api-base-url or API_BASE_URL)");
23985
23995
  }
@@ -24000,7 +24010,7 @@ function loadConfig() {
24000
24010
  includeTags: argv.tag,
24001
24011
  includeResources: argv.resource,
24002
24012
  includeOperations: argv.operation,
24003
- toolsMode: argv.tools || process.env.TOOLS_MODE || "all",
24013
+ toolsMode,
24004
24014
  disableAbbreviation: disableAbbreviation ? true : void 0
24005
24015
  };
24006
24016
  }
@@ -24014,18 +24024,32 @@ import {
24014
24024
  import * as http2 from "http";
24015
24025
  import { randomUUID } from "crypto";
24016
24026
  var StreamableHttpServerTransport = class {
24027
+ // Track if using an external server
24017
24028
  /**
24018
24029
  * Initialize a new StreamableHttpServerTransport
24019
24030
  *
24020
24031
  * @param port HTTP port to listen on
24021
24032
  * @param host Host to bind to (default: 127.0.0.1)
24022
24033
  * @param endpointPath Endpoint path (default: /mcp)
24034
+ * @param server Optional HTTP server instance. If not provided, a new server will be created.
24035
+ * If provided, the transport will attach its request handler to the server.
24036
+ * Note: When using an external server, all handlers added via server.on('request', handler)
24037
+ * will be called for every request, in the order they were added. Custom handlers should be
24038
+ * added FIRST and should fully handle their routes (including sending responses) to prevent
24039
+ * further handlers from running for those requests. The MCP handler should be added after
24040
+ * custom handlers and will return early for non-MCP paths.
24023
24041
  */
24024
- constructor(port, host = "127.0.0.1", endpointPath = "/mcp") {
24042
+ constructor(port, host = "127.0.0.1", endpointPath = "/mcp", server) {
24025
24043
  this.port = port;
24026
24044
  this.host = host;
24027
24045
  this.endpointPath = endpointPath;
24028
- this.server = http2.createServer(this.handleRequest.bind(this));
24046
+ this.isExternalServer = !!server;
24047
+ if (server) {
24048
+ this.server = server;
24049
+ this.server.on("request", this.handleRequest.bind(this));
24050
+ } else {
24051
+ this.server = http2.createServer(this.handleRequest.bind(this));
24052
+ }
24029
24053
  }
24030
24054
  server;
24031
24055
  sessions = /* @__PURE__ */ new Map();
@@ -24036,6 +24060,7 @@ var StreamableHttpServerTransport = class {
24036
24060
  requestSessionMap = /* @__PURE__ */ new Map();
24037
24061
  // Maps request IDs to session IDs
24038
24062
  healthCheckPath = "/health";
24063
+ isExternalServer;
24039
24064
  /**
24040
24065
  * Callback when message is received
24041
24066
  */
@@ -24084,6 +24109,13 @@ var StreamableHttpServerTransport = class {
24084
24109
  }
24085
24110
  }
24086
24111
  this.sessions.clear();
24112
+ if (this.isExternalServer) {
24113
+ this.started = false;
24114
+ if (this.onclose) {
24115
+ this.onclose();
24116
+ }
24117
+ return;
24118
+ }
24087
24119
  return new Promise((resolve5, reject) => {
24088
24120
  this.server.close((err) => {
24089
24121
  if (err) {
@@ -24202,6 +24234,9 @@ var StreamableHttpServerTransport = class {
24202
24234
  return;
24203
24235
  }
24204
24236
  if (req.url !== this.endpointPath) {
24237
+ if (this.isExternalServer) {
24238
+ return;
24239
+ }
24205
24240
  res.writeHead(404);
24206
24241
  res.end();
24207
24242
  return;
package/dist/cli.js CHANGED
@@ -18672,9 +18672,7 @@ var ApiClient = class {
18672
18672
  };
18673
18673
  }
18674
18674
  } else {
18675
- if (Object.keys(paramsCopy).length > 0) {
18676
- config.data = paramsCopy;
18677
- }
18675
+ config.data = Object.keys(paramsCopy).length > 0 ? paramsCopy : {};
18678
18676
  }
18679
18677
  const response = await this.axiosInstance(config);
18680
18678
  return response.data;
@@ -23980,6 +23978,18 @@ function loadConfig() {
23980
23978
  }
23981
23979
  const apiBaseUrl = argv["api-base-url"] || process.env.API_BASE_URL;
23982
23980
  const disableAbbreviation = argv["disable-abbreviation"] || (process.env.DISABLE_ABBREVIATION ? process.env.DISABLE_ABBREVIATION === "true" : false);
23981
+ const toolsModeInput = (typeof argv.tools === "string" ? argv.tools : void 0) || process.env.TOOLS_MODE;
23982
+ let toolsMode = "all";
23983
+ if (typeof toolsModeInput === "string" && toolsModeInput.trim().length > 0) {
23984
+ const normalized = toolsModeInput.toLowerCase();
23985
+ if (normalized === "all" || normalized === "dynamic" || normalized === "explicit") {
23986
+ toolsMode = normalized;
23987
+ } else {
23988
+ throw new Error(
23989
+ "Invalid tools mode. Expected one of: all, dynamic, explicit"
23990
+ );
23991
+ }
23992
+ }
23983
23993
  if (!apiBaseUrl) {
23984
23994
  throw new Error("API base URL is required (--api-base-url or API_BASE_URL)");
23985
23995
  }
@@ -24000,7 +24010,7 @@ function loadConfig() {
24000
24010
  includeTags: argv.tag,
24001
24011
  includeResources: argv.resource,
24002
24012
  includeOperations: argv.operation,
24003
- toolsMode: argv.tools || process.env.TOOLS_MODE || "all",
24013
+ toolsMode,
24004
24014
  disableAbbreviation: disableAbbreviation ? true : void 0
24005
24015
  };
24006
24016
  }
@@ -24014,18 +24024,32 @@ import {
24014
24024
  import * as http2 from "http";
24015
24025
  import { randomUUID } from "crypto";
24016
24026
  var StreamableHttpServerTransport = class {
24027
+ // Track if using an external server
24017
24028
  /**
24018
24029
  * Initialize a new StreamableHttpServerTransport
24019
24030
  *
24020
24031
  * @param port HTTP port to listen on
24021
24032
  * @param host Host to bind to (default: 127.0.0.1)
24022
24033
  * @param endpointPath Endpoint path (default: /mcp)
24034
+ * @param server Optional HTTP server instance. If not provided, a new server will be created.
24035
+ * If provided, the transport will attach its request handler to the server.
24036
+ * Note: When using an external server, all handlers added via server.on('request', handler)
24037
+ * will be called for every request, in the order they were added. Custom handlers should be
24038
+ * added FIRST and should fully handle their routes (including sending responses) to prevent
24039
+ * further handlers from running for those requests. The MCP handler should be added after
24040
+ * custom handlers and will return early for non-MCP paths.
24023
24041
  */
24024
- constructor(port, host = "127.0.0.1", endpointPath = "/mcp") {
24042
+ constructor(port, host = "127.0.0.1", endpointPath = "/mcp", server) {
24025
24043
  this.port = port;
24026
24044
  this.host = host;
24027
24045
  this.endpointPath = endpointPath;
24028
- this.server = http2.createServer(this.handleRequest.bind(this));
24046
+ this.isExternalServer = !!server;
24047
+ if (server) {
24048
+ this.server = server;
24049
+ this.server.on("request", this.handleRequest.bind(this));
24050
+ } else {
24051
+ this.server = http2.createServer(this.handleRequest.bind(this));
24052
+ }
24029
24053
  }
24030
24054
  server;
24031
24055
  sessions = /* @__PURE__ */ new Map();
@@ -24036,6 +24060,7 @@ var StreamableHttpServerTransport = class {
24036
24060
  requestSessionMap = /* @__PURE__ */ new Map();
24037
24061
  // Maps request IDs to session IDs
24038
24062
  healthCheckPath = "/health";
24063
+ isExternalServer;
24039
24064
  /**
24040
24065
  * Callback when message is received
24041
24066
  */
@@ -24084,6 +24109,13 @@ var StreamableHttpServerTransport = class {
24084
24109
  }
24085
24110
  }
24086
24111
  this.sessions.clear();
24112
+ if (this.isExternalServer) {
24113
+ this.started = false;
24114
+ if (this.onclose) {
24115
+ this.onclose();
24116
+ }
24117
+ return;
24118
+ }
24087
24119
  return new Promise((resolve5, reject) => {
24088
24120
  this.server.close((err) => {
24089
24121
  if (err) {
@@ -24202,6 +24234,9 @@ var StreamableHttpServerTransport = class {
24202
24234
  return;
24203
24235
  }
24204
24236
  if (req.url !== this.endpointPath) {
24237
+ if (this.isExternalServer) {
24238
+ return;
24239
+ }
24205
24240
  res.writeHead(404);
24206
24241
  res.end();
24207
24242
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ivotoby/openapi-mcp-server",
3
- "version": "1.10.1",
3
+ "version": "1.12.0",
4
4
  "description": "An MCP server that exposes OpenAPI endpoints as resources",
5
5
  "license": "MIT",
6
6
  "type": "module",