@ivotoby/openapi-mcp-server 1.12.0 → 1.12.2
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/README.md +234 -1
- package/dist/bundle.js +491 -97
- package/dist/cli.js +489 -97
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8883,11 +8883,11 @@ var require_mime_types = __commonJS({
|
|
|
8883
8883
|
}
|
|
8884
8884
|
return exts[0];
|
|
8885
8885
|
}
|
|
8886
|
-
function lookup(
|
|
8887
|
-
if (!
|
|
8886
|
+
function lookup(path2) {
|
|
8887
|
+
if (!path2 || typeof path2 !== "string") {
|
|
8888
8888
|
return false;
|
|
8889
8889
|
}
|
|
8890
|
-
var extension2 = extname2("x." +
|
|
8890
|
+
var extension2 = extname2("x." + path2).toLowerCase().substr(1);
|
|
8891
8891
|
if (!extension2) {
|
|
8892
8892
|
return false;
|
|
8893
8893
|
}
|
|
@@ -9990,11 +9990,11 @@ var require_form_data = __commonJS({
|
|
|
9990
9990
|
"node_modules/form-data/lib/form_data.js"(exports, module) {
|
|
9991
9991
|
var CombinedStream = require_combined_stream();
|
|
9992
9992
|
var util3 = __require("util");
|
|
9993
|
-
var
|
|
9993
|
+
var path2 = __require("path");
|
|
9994
9994
|
var http3 = __require("http");
|
|
9995
9995
|
var https2 = __require("https");
|
|
9996
9996
|
var parseUrl = __require("url").parse;
|
|
9997
|
-
var
|
|
9997
|
+
var fs2 = __require("fs");
|
|
9998
9998
|
var Stream = __require("stream").Stream;
|
|
9999
9999
|
var mime = require_mime_types();
|
|
10000
10000
|
var asynckit = require_asynckit();
|
|
@@ -10060,7 +10060,7 @@ var require_form_data = __commonJS({
|
|
|
10060
10060
|
if (value.end != void 0 && value.end != Infinity && value.start != void 0) {
|
|
10061
10061
|
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
10062
10062
|
} else {
|
|
10063
|
-
|
|
10063
|
+
fs2.stat(value.path, function(err, stat) {
|
|
10064
10064
|
var fileSize;
|
|
10065
10065
|
if (err) {
|
|
10066
10066
|
callback(err);
|
|
@@ -10118,11 +10118,11 @@ var require_form_data = __commonJS({
|
|
|
10118
10118
|
FormData3.prototype._getContentDisposition = function(value, options) {
|
|
10119
10119
|
var filename, contentDisposition;
|
|
10120
10120
|
if (typeof options.filepath === "string") {
|
|
10121
|
-
filename =
|
|
10121
|
+
filename = path2.normalize(options.filepath).replace(/\\/g, "/");
|
|
10122
10122
|
} else if (options.filename || value.name || value.path) {
|
|
10123
|
-
filename =
|
|
10123
|
+
filename = path2.basename(options.filename || value.name || value.path);
|
|
10124
10124
|
} else if (value.readable && Object.prototype.hasOwnProperty.call(value, "httpVersion")) {
|
|
10125
|
-
filename =
|
|
10125
|
+
filename = path2.basename(value.client._httpMessage.path || "");
|
|
10126
10126
|
}
|
|
10127
10127
|
if (filename) {
|
|
10128
10128
|
contentDisposition = 'filename="' + filename + '"';
|
|
@@ -11656,7 +11656,14 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
11656
11656
|
|
|
11657
11657
|
// src/server.ts
|
|
11658
11658
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
11659
|
-
import {
|
|
11659
|
+
import {
|
|
11660
|
+
ListToolsRequestSchema,
|
|
11661
|
+
CallToolRequestSchema,
|
|
11662
|
+
ListPromptsRequestSchema,
|
|
11663
|
+
GetPromptRequestSchema,
|
|
11664
|
+
ListResourcesRequestSchema,
|
|
11665
|
+
ReadResourceRequestSchema
|
|
11666
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
11660
11667
|
|
|
11661
11668
|
// src/openapi-loader.ts
|
|
11662
11669
|
import { readFile } from "fs/promises";
|
|
@@ -14377,8 +14384,8 @@ function parseToolId(toolId) {
|
|
|
14377
14384
|
if (!pathPart) {
|
|
14378
14385
|
return { method, path: "" };
|
|
14379
14386
|
}
|
|
14380
|
-
const
|
|
14381
|
-
return { method, path: "/" +
|
|
14387
|
+
const path2 = pathPart.replace(/__/g, "/");
|
|
14388
|
+
return { method, path: "/" + path2 };
|
|
14382
14389
|
}
|
|
14383
14390
|
function sanitizeForToolId(input) {
|
|
14384
14391
|
let result = input.replace(/[^A-Za-z0-9_.-]/g, "").replace(/_{3,}/g, "__");
|
|
@@ -14388,8 +14395,8 @@ function sanitizeForToolId(input) {
|
|
|
14388
14395
|
function collapseExcessiveHyphens(input) {
|
|
14389
14396
|
return input.replace(/-{4,}/g, "---");
|
|
14390
14397
|
}
|
|
14391
|
-
function generateToolId(method,
|
|
14392
|
-
const cleanPath =
|
|
14398
|
+
function generateToolId(method, path2) {
|
|
14399
|
+
const cleanPath = path2.replace(/^\//, "").replace(/\/+/g, "/").replace(/\{([^}]+)\}/g, "---$1").replace(/\//g, "__");
|
|
14393
14400
|
const sanitizedPath = sanitizeForToolId(cleanPath);
|
|
14394
14401
|
return `${method.toUpperCase()}::${sanitizedPath}`;
|
|
14395
14402
|
}
|
|
@@ -14456,7 +14463,7 @@ var OpenAPISpecLoader = class {
|
|
|
14456
14463
|
* Load spec content from standard input
|
|
14457
14464
|
*/
|
|
14458
14465
|
async loadFromStdin() {
|
|
14459
|
-
return new Promise((
|
|
14466
|
+
return new Promise((resolve6, reject) => {
|
|
14460
14467
|
let data = "";
|
|
14461
14468
|
process.stdin.setEncoding("utf8");
|
|
14462
14469
|
process.stdin.on("data", (chunk) => {
|
|
@@ -14466,7 +14473,7 @@ var OpenAPISpecLoader = class {
|
|
|
14466
14473
|
if (data.trim().length === 0) {
|
|
14467
14474
|
reject(new Error("No data received from stdin"));
|
|
14468
14475
|
} else {
|
|
14469
|
-
|
|
14476
|
+
resolve6(data);
|
|
14470
14477
|
}
|
|
14471
14478
|
});
|
|
14472
14479
|
process.stdin.on("error", (error) => {
|
|
@@ -14646,8 +14653,8 @@ var OpenAPISpecLoader = class {
|
|
|
14646
14653
|
* - "/api/v1/users/{id}/posts" -> "posts"
|
|
14647
14654
|
* - "/health" -> "health"
|
|
14648
14655
|
*/
|
|
14649
|
-
extractResourceName(
|
|
14650
|
-
const segments =
|
|
14656
|
+
extractResourceName(path2) {
|
|
14657
|
+
const segments = path2.replace(/^\//, "").split("/");
|
|
14651
14658
|
for (let i = segments.length - 1; i >= 0; i--) {
|
|
14652
14659
|
const segment = segments[i];
|
|
14653
14660
|
if (!segment.includes("{") && !segment.includes("}") && segment.length > 0) {
|
|
@@ -14661,7 +14668,7 @@ var OpenAPISpecLoader = class {
|
|
|
14661
14668
|
*/
|
|
14662
14669
|
parseOpenAPISpec(spec) {
|
|
14663
14670
|
const tools = /* @__PURE__ */ new Map();
|
|
14664
|
-
for (const [
|
|
14671
|
+
for (const [path2, pathItem] of Object.entries(spec.paths)) {
|
|
14665
14672
|
if (!pathItem) continue;
|
|
14666
14673
|
const pathLevelParameters = [];
|
|
14667
14674
|
if (pathItem.parameters) {
|
|
@@ -14703,16 +14710,16 @@ var OpenAPISpecLoader = class {
|
|
|
14703
14710
|
if (!["get", "post", "put", "patch", "delete", "options", "head"].includes(
|
|
14704
14711
|
method.toLowerCase()
|
|
14705
14712
|
)) {
|
|
14706
|
-
console.warn(`Skipping non-HTTP method "${method}" for path ${
|
|
14713
|
+
console.warn(`Skipping non-HTTP method "${method}" for path ${path2}`);
|
|
14707
14714
|
continue;
|
|
14708
14715
|
}
|
|
14709
14716
|
const op = operation;
|
|
14710
|
-
const toolId = generateToolId(method,
|
|
14711
|
-
const nameSource = op.operationId || op.summary || `${method.toUpperCase()} ${
|
|
14717
|
+
const toolId = generateToolId(method, path2);
|
|
14718
|
+
const nameSource = op.operationId || op.summary || `${method.toUpperCase()} ${path2}`;
|
|
14712
14719
|
const name = this.abbreviateOperationId(nameSource);
|
|
14713
14720
|
const tool = {
|
|
14714
14721
|
name,
|
|
14715
|
-
description: op.description || `Make a ${method.toUpperCase()} request to ${
|
|
14722
|
+
description: op.description || `Make a ${method.toUpperCase()} request to ${path2}`,
|
|
14716
14723
|
inputSchema: {
|
|
14717
14724
|
type: "object",
|
|
14718
14725
|
properties: {}
|
|
@@ -14720,10 +14727,10 @@ var OpenAPISpecLoader = class {
|
|
|
14720
14727
|
// Add metadata for filtering
|
|
14721
14728
|
tags: op.tags || [],
|
|
14722
14729
|
httpMethod: method.toUpperCase(),
|
|
14723
|
-
resourceName: this.extractResourceName(
|
|
14724
|
-
originalPath:
|
|
14730
|
+
resourceName: this.extractResourceName(path2),
|
|
14731
|
+
originalPath: path2
|
|
14725
14732
|
};
|
|
14726
|
-
tool["x-original-path"] =
|
|
14733
|
+
tool["x-original-path"] = path2;
|
|
14727
14734
|
const requiredParams = [];
|
|
14728
14735
|
const parameterMap = /* @__PURE__ */ new Map();
|
|
14729
14736
|
for (const pathParam of pathLevelParameters) {
|
|
@@ -14794,8 +14801,31 @@ var OpenAPISpecLoader = class {
|
|
|
14794
14801
|
}
|
|
14795
14802
|
}
|
|
14796
14803
|
}
|
|
14797
|
-
if (op.requestBody
|
|
14798
|
-
|
|
14804
|
+
if (op.requestBody) {
|
|
14805
|
+
let requestBodyObj;
|
|
14806
|
+
if ("$ref" in op.requestBody && typeof op.requestBody.$ref === "string") {
|
|
14807
|
+
const refMatch = op.requestBody.$ref.match(/^#\/components\/requestBodies\/(.+)$/);
|
|
14808
|
+
if (refMatch && spec.components?.requestBodies) {
|
|
14809
|
+
const requestBodyName = refMatch[1];
|
|
14810
|
+
const resolvedRequestBody = spec.components.requestBodies[requestBodyName];
|
|
14811
|
+
if (resolvedRequestBody && "content" in resolvedRequestBody) {
|
|
14812
|
+
requestBodyObj = resolvedRequestBody;
|
|
14813
|
+
} else {
|
|
14814
|
+
console.warn(
|
|
14815
|
+
`Could not resolve requestBody reference or invalid structure: ${op.requestBody.$ref}`
|
|
14816
|
+
);
|
|
14817
|
+
continue;
|
|
14818
|
+
}
|
|
14819
|
+
} else {
|
|
14820
|
+
console.warn(`Could not parse requestBody reference: ${op.requestBody.$ref}`);
|
|
14821
|
+
continue;
|
|
14822
|
+
}
|
|
14823
|
+
} else if ("content" in op.requestBody) {
|
|
14824
|
+
requestBodyObj = op.requestBody;
|
|
14825
|
+
} else {
|
|
14826
|
+
console.warn("Skipping requestBody due to invalid structure:", op.requestBody);
|
|
14827
|
+
continue;
|
|
14828
|
+
}
|
|
14799
14829
|
let mediaTypeObj;
|
|
14800
14830
|
if (requestBodyObj.content["application/json"]) {
|
|
14801
14831
|
mediaTypeObj = requestBodyObj.content["application/json"];
|
|
@@ -15628,9 +15658,9 @@ function isVisitable(thing) {
|
|
|
15628
15658
|
function removeBrackets(key) {
|
|
15629
15659
|
return utils_default.endsWith(key, "[]") ? key.slice(0, -2) : key;
|
|
15630
15660
|
}
|
|
15631
|
-
function renderKey(
|
|
15632
|
-
if (!
|
|
15633
|
-
return
|
|
15661
|
+
function renderKey(path2, key, dots) {
|
|
15662
|
+
if (!path2) return key;
|
|
15663
|
+
return path2.concat(key).map(function each(token, i) {
|
|
15634
15664
|
token = removeBrackets(token);
|
|
15635
15665
|
return !dots && i ? "[" + token + "]" : token;
|
|
15636
15666
|
}).join(dots ? "." : "");
|
|
@@ -15678,9 +15708,9 @@ function toFormData(obj, formData, options) {
|
|
|
15678
15708
|
}
|
|
15679
15709
|
return value;
|
|
15680
15710
|
}
|
|
15681
|
-
function defaultVisitor(value, key,
|
|
15711
|
+
function defaultVisitor(value, key, path2) {
|
|
15682
15712
|
let arr = value;
|
|
15683
|
-
if (value && !
|
|
15713
|
+
if (value && !path2 && typeof value === "object") {
|
|
15684
15714
|
if (utils_default.endsWith(key, "{}")) {
|
|
15685
15715
|
key = metaTokens ? key : key.slice(0, -2);
|
|
15686
15716
|
value = JSON.stringify(value);
|
|
@@ -15699,7 +15729,7 @@ function toFormData(obj, formData, options) {
|
|
|
15699
15729
|
if (isVisitable(value)) {
|
|
15700
15730
|
return true;
|
|
15701
15731
|
}
|
|
15702
|
-
formData.append(renderKey(
|
|
15732
|
+
formData.append(renderKey(path2, key, dots), convertValue(value));
|
|
15703
15733
|
return false;
|
|
15704
15734
|
}
|
|
15705
15735
|
const stack = [];
|
|
@@ -15708,10 +15738,10 @@ function toFormData(obj, formData, options) {
|
|
|
15708
15738
|
convertValue,
|
|
15709
15739
|
isVisitable
|
|
15710
15740
|
});
|
|
15711
|
-
function build(value,
|
|
15741
|
+
function build(value, path2) {
|
|
15712
15742
|
if (utils_default.isUndefined(value)) return;
|
|
15713
15743
|
if (stack.indexOf(value) !== -1) {
|
|
15714
|
-
throw Error("Circular reference detected in " +
|
|
15744
|
+
throw Error("Circular reference detected in " + path2.join("."));
|
|
15715
15745
|
}
|
|
15716
15746
|
stack.push(value);
|
|
15717
15747
|
utils_default.forEach(value, function each(el, key) {
|
|
@@ -15719,11 +15749,11 @@ function toFormData(obj, formData, options) {
|
|
|
15719
15749
|
formData,
|
|
15720
15750
|
el,
|
|
15721
15751
|
utils_default.isString(key) ? key.trim() : key,
|
|
15722
|
-
|
|
15752
|
+
path2,
|
|
15723
15753
|
exposedHelpers
|
|
15724
15754
|
);
|
|
15725
15755
|
if (result === true) {
|
|
15726
|
-
build(el,
|
|
15756
|
+
build(el, path2 ? path2.concat(key) : [key]);
|
|
15727
15757
|
}
|
|
15728
15758
|
});
|
|
15729
15759
|
stack.pop();
|
|
@@ -15935,7 +15965,7 @@ var platform_default = {
|
|
|
15935
15965
|
// node_modules/axios/lib/helpers/toURLEncodedForm.js
|
|
15936
15966
|
function toURLEncodedForm(data, options) {
|
|
15937
15967
|
return toFormData_default(data, new platform_default.classes.URLSearchParams(), Object.assign({
|
|
15938
|
-
visitor: function(value, key,
|
|
15968
|
+
visitor: function(value, key, path2, helpers) {
|
|
15939
15969
|
if (platform_default.isNode && utils_default.isBuffer(value)) {
|
|
15940
15970
|
this.append(key, value.toString("base64"));
|
|
15941
15971
|
return false;
|
|
@@ -15964,11 +15994,11 @@ function arrayToObject(arr) {
|
|
|
15964
15994
|
return obj;
|
|
15965
15995
|
}
|
|
15966
15996
|
function formDataToJSON(formData) {
|
|
15967
|
-
function buildPath(
|
|
15968
|
-
let name =
|
|
15997
|
+
function buildPath(path2, value, target, index) {
|
|
15998
|
+
let name = path2[index++];
|
|
15969
15999
|
if (name === "__proto__") return true;
|
|
15970
16000
|
const isNumericKey = Number.isFinite(+name);
|
|
15971
|
-
const isLast = index >=
|
|
16001
|
+
const isLast = index >= path2.length;
|
|
15972
16002
|
name = !name && utils_default.isArray(target) ? target.length : name;
|
|
15973
16003
|
if (isLast) {
|
|
15974
16004
|
if (utils_default.hasOwnProp(target, name)) {
|
|
@@ -15981,7 +16011,7 @@ function formDataToJSON(formData) {
|
|
|
15981
16011
|
if (!target[name] || !utils_default.isObject(target[name])) {
|
|
15982
16012
|
target[name] = [];
|
|
15983
16013
|
}
|
|
15984
|
-
const result = buildPath(
|
|
16014
|
+
const result = buildPath(path2, value, target[name], index);
|
|
15985
16015
|
if (result && utils_default.isArray(target[name])) {
|
|
15986
16016
|
target[name] = arrayToObject(target[name]);
|
|
15987
16017
|
}
|
|
@@ -16410,10 +16440,10 @@ utils_default.inherits(CanceledError, AxiosError_default, {
|
|
|
16410
16440
|
var CanceledError_default = CanceledError;
|
|
16411
16441
|
|
|
16412
16442
|
// node_modules/axios/lib/core/settle.js
|
|
16413
|
-
function settle(
|
|
16443
|
+
function settle(resolve6, reject, response) {
|
|
16414
16444
|
const validateStatus2 = response.config.validateStatus;
|
|
16415
16445
|
if (!response.status || !validateStatus2 || validateStatus2(response.status)) {
|
|
16416
|
-
|
|
16446
|
+
resolve6(response);
|
|
16417
16447
|
} else {
|
|
16418
16448
|
reject(new AxiosError_default(
|
|
16419
16449
|
"Request failed with status code " + response.status,
|
|
@@ -16914,7 +16944,7 @@ function setProxy(options, configProxy, location) {
|
|
|
16914
16944
|
}
|
|
16915
16945
|
var isHttpAdapterSupported = typeof process !== "undefined" && utils_default.kindOf(process) === "process";
|
|
16916
16946
|
var wrapAsync = (asyncExecutor) => {
|
|
16917
|
-
return new Promise((
|
|
16947
|
+
return new Promise((resolve6, reject) => {
|
|
16918
16948
|
let onDone;
|
|
16919
16949
|
let isDone;
|
|
16920
16950
|
const done = (value, isRejected) => {
|
|
@@ -16924,7 +16954,7 @@ var wrapAsync = (asyncExecutor) => {
|
|
|
16924
16954
|
};
|
|
16925
16955
|
const _resolve = (value) => {
|
|
16926
16956
|
done(value);
|
|
16927
|
-
|
|
16957
|
+
resolve6(value);
|
|
16928
16958
|
};
|
|
16929
16959
|
const _reject = (reason) => {
|
|
16930
16960
|
done(reason, true);
|
|
@@ -16944,7 +16974,7 @@ var resolveFamily = ({ address, family }) => {
|
|
|
16944
16974
|
};
|
|
16945
16975
|
var buildAddressEntry = (address, family) => resolveFamily(utils_default.isObject(address) ? address : { address, family });
|
|
16946
16976
|
var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
16947
|
-
return wrapAsync(async function dispatchHttpRequest(
|
|
16977
|
+
return wrapAsync(async function dispatchHttpRequest(resolve6, reject, onDone) {
|
|
16948
16978
|
let { data, lookup, family } = config;
|
|
16949
16979
|
const { responseType, responseEncoding } = config;
|
|
16950
16980
|
const method = config.method.toUpperCase();
|
|
@@ -16996,7 +17026,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
16996
17026
|
if (protocol === "data:") {
|
|
16997
17027
|
let convertedData;
|
|
16998
17028
|
if (method !== "GET") {
|
|
16999
|
-
return settle(
|
|
17029
|
+
return settle(resolve6, reject, {
|
|
17000
17030
|
status: 405,
|
|
17001
17031
|
statusText: "method not allowed",
|
|
17002
17032
|
headers: {},
|
|
@@ -17018,7 +17048,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17018
17048
|
} else if (responseType === "stream") {
|
|
17019
17049
|
convertedData = stream3.Readable.from(convertedData);
|
|
17020
17050
|
}
|
|
17021
|
-
return settle(
|
|
17051
|
+
return settle(resolve6, reject, {
|
|
17022
17052
|
data: convertedData,
|
|
17023
17053
|
status: 200,
|
|
17024
17054
|
statusText: "OK",
|
|
@@ -17116,9 +17146,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17116
17146
|
auth = urlUsername + ":" + urlPassword;
|
|
17117
17147
|
}
|
|
17118
17148
|
auth && headers.delete("authorization");
|
|
17119
|
-
let
|
|
17149
|
+
let path2;
|
|
17120
17150
|
try {
|
|
17121
|
-
|
|
17151
|
+
path2 = buildURL(
|
|
17122
17152
|
parsed.pathname + parsed.search,
|
|
17123
17153
|
config.params,
|
|
17124
17154
|
config.paramsSerializer
|
|
@@ -17136,7 +17166,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17136
17166
|
false
|
|
17137
17167
|
);
|
|
17138
17168
|
const options = {
|
|
17139
|
-
path,
|
|
17169
|
+
path: path2,
|
|
17140
17170
|
method,
|
|
17141
17171
|
headers: headers.toJSON(),
|
|
17142
17172
|
agents: { http: config.httpAgent, https: config.httpsAgent },
|
|
@@ -17236,7 +17266,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17236
17266
|
};
|
|
17237
17267
|
if (responseType === "stream") {
|
|
17238
17268
|
response.data = responseStream;
|
|
17239
|
-
settle(
|
|
17269
|
+
settle(resolve6, reject, response);
|
|
17240
17270
|
} else {
|
|
17241
17271
|
const responseBuffer = [];
|
|
17242
17272
|
let totalResponseBytes = 0;
|
|
@@ -17284,7 +17314,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17284
17314
|
} catch (err) {
|
|
17285
17315
|
return reject(AxiosError_default.from(err, null, config, response.request, response));
|
|
17286
17316
|
}
|
|
17287
|
-
settle(
|
|
17317
|
+
settle(resolve6, reject, response);
|
|
17288
17318
|
});
|
|
17289
17319
|
}
|
|
17290
17320
|
emitter.once("abort", (err) => {
|
|
@@ -17366,10 +17396,10 @@ var isURLSameOrigin_default = platform_default.hasStandardBrowserEnv ? /* @__PUR
|
|
|
17366
17396
|
var cookies_default = platform_default.hasStandardBrowserEnv ? (
|
|
17367
17397
|
// Standard browser envs support document.cookie
|
|
17368
17398
|
{
|
|
17369
|
-
write(name, value, expires,
|
|
17399
|
+
write(name, value, expires, path2, domain, secure) {
|
|
17370
17400
|
const cookie = [name + "=" + encodeURIComponent(value)];
|
|
17371
17401
|
utils_default.isNumber(expires) && cookie.push("expires=" + new Date(expires).toGMTString());
|
|
17372
|
-
utils_default.isString(
|
|
17402
|
+
utils_default.isString(path2) && cookie.push("path=" + path2);
|
|
17373
17403
|
utils_default.isString(domain) && cookie.push("domain=" + domain);
|
|
17374
17404
|
secure === true && cookie.push("secure");
|
|
17375
17405
|
document.cookie = cookie.join("; ");
|
|
@@ -17511,7 +17541,7 @@ var resolveConfig_default = (config) => {
|
|
|
17511
17541
|
// node_modules/axios/lib/adapters/xhr.js
|
|
17512
17542
|
var isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
17513
17543
|
var xhr_default = isXHRAdapterSupported && function(config) {
|
|
17514
|
-
return new Promise(function dispatchXhrRequest(
|
|
17544
|
+
return new Promise(function dispatchXhrRequest(resolve6, reject) {
|
|
17515
17545
|
const _config = resolveConfig_default(config);
|
|
17516
17546
|
let requestData = _config.data;
|
|
17517
17547
|
const requestHeaders = AxiosHeaders_default.from(_config.headers).normalize();
|
|
@@ -17545,7 +17575,7 @@ var xhr_default = isXHRAdapterSupported && function(config) {
|
|
|
17545
17575
|
request
|
|
17546
17576
|
};
|
|
17547
17577
|
settle(function _resolve(value) {
|
|
17548
|
-
|
|
17578
|
+
resolve6(value);
|
|
17549
17579
|
done();
|
|
17550
17580
|
}, function _reject(err) {
|
|
17551
17581
|
reject(err);
|
|
@@ -17888,8 +17918,8 @@ var fetch_default = isFetchSupported && (async (config) => {
|
|
|
17888
17918
|
responseType = responseType || "text";
|
|
17889
17919
|
let responseData = await resolvers[utils_default.findKey(resolvers, responseType) || "text"](response, config);
|
|
17890
17920
|
!isStreamResponse && unsubscribe && unsubscribe();
|
|
17891
|
-
return await new Promise((
|
|
17892
|
-
settle(
|
|
17921
|
+
return await new Promise((resolve6, reject) => {
|
|
17922
|
+
settle(resolve6, reject, {
|
|
17893
17923
|
data: responseData,
|
|
17894
17924
|
headers: AxiosHeaders_default.from(response.headers),
|
|
17895
17925
|
status: response.status,
|
|
@@ -18255,8 +18285,8 @@ var CancelToken = class _CancelToken {
|
|
|
18255
18285
|
throw new TypeError("executor must be a function.");
|
|
18256
18286
|
}
|
|
18257
18287
|
let resolvePromise;
|
|
18258
|
-
this.promise = new Promise(function promiseExecutor(
|
|
18259
|
-
resolvePromise =
|
|
18288
|
+
this.promise = new Promise(function promiseExecutor(resolve6) {
|
|
18289
|
+
resolvePromise = resolve6;
|
|
18260
18290
|
});
|
|
18261
18291
|
const token = this;
|
|
18262
18292
|
this.promise.then((cancel) => {
|
|
@@ -18269,9 +18299,9 @@ var CancelToken = class _CancelToken {
|
|
|
18269
18299
|
});
|
|
18270
18300
|
this.promise.then = (onfulfilled) => {
|
|
18271
18301
|
let _resolve;
|
|
18272
|
-
const promise = new Promise((
|
|
18273
|
-
token.subscribe(
|
|
18274
|
-
_resolve =
|
|
18302
|
+
const promise = new Promise((resolve6) => {
|
|
18303
|
+
token.subscribe(resolve6);
|
|
18304
|
+
_resolve = resolve6;
|
|
18275
18305
|
}).then(onfulfilled);
|
|
18276
18306
|
promise.cancel = function reject() {
|
|
18277
18307
|
token.unsubscribe(_resolve);
|
|
@@ -18598,10 +18628,10 @@ var ApiClient = class {
|
|
|
18598
18628
|
if (toolId === "INVOKE-API-ENDPOINT") {
|
|
18599
18629
|
return this.handleInvokeApiEndpoint(toolId, params);
|
|
18600
18630
|
}
|
|
18601
|
-
const { method, path } = this.parseToolId(toolId);
|
|
18631
|
+
const { method, path: path2 } = this.parseToolId(toolId);
|
|
18602
18632
|
const toolDef = this.getToolDefinition(toolId);
|
|
18603
18633
|
const paramsCopy = { ...params };
|
|
18604
|
-
let resolvedPath =
|
|
18634
|
+
let resolvedPath = path2;
|
|
18605
18635
|
const escapeRegExp = (str2) => {
|
|
18606
18636
|
return str2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18607
18637
|
};
|
|
@@ -18726,7 +18756,7 @@ var ApiClient = class {
|
|
|
18726
18756
|
async handleListApiEndpoints() {
|
|
18727
18757
|
const endpoints = [];
|
|
18728
18758
|
if (this.openApiSpec) {
|
|
18729
|
-
for (const [
|
|
18759
|
+
for (const [path2, pathItem] of Object.entries(this.openApiSpec.paths)) {
|
|
18730
18760
|
if (!pathItem) continue;
|
|
18731
18761
|
for (const [method, operation] of Object.entries(pathItem)) {
|
|
18732
18762
|
if (method === "parameters" || !operation) continue;
|
|
@@ -18736,7 +18766,7 @@ var ApiClient = class {
|
|
|
18736
18766
|
const op = operation;
|
|
18737
18767
|
endpoints.push({
|
|
18738
18768
|
method: method.toUpperCase(),
|
|
18739
|
-
path,
|
|
18769
|
+
path: path2,
|
|
18740
18770
|
summary: op.summary || "",
|
|
18741
18771
|
description: op.description || "",
|
|
18742
18772
|
operationId: op.operationId || "",
|
|
@@ -18750,13 +18780,13 @@ var ApiClient = class {
|
|
|
18750
18780
|
continue;
|
|
18751
18781
|
}
|
|
18752
18782
|
try {
|
|
18753
|
-
const { method, path } = this.parseToolId(toolId);
|
|
18783
|
+
const { method, path: path2 } = this.parseToolId(toolId);
|
|
18754
18784
|
endpoints.push({
|
|
18755
18785
|
toolId,
|
|
18756
18786
|
name: tool.name,
|
|
18757
18787
|
description: tool.description,
|
|
18758
18788
|
method: method.toUpperCase(),
|
|
18759
|
-
path
|
|
18789
|
+
path: path2
|
|
18760
18790
|
});
|
|
18761
18791
|
} catch (error) {
|
|
18762
18792
|
continue;
|
|
@@ -18814,8 +18844,8 @@ var ApiClient = class {
|
|
|
18814
18844
|
let matchingToolId;
|
|
18815
18845
|
for (const [toolId2, tool] of this.toolsMap.entries()) {
|
|
18816
18846
|
try {
|
|
18817
|
-
const { path } = this.parseToolId(toolId2);
|
|
18818
|
-
if (
|
|
18847
|
+
const { path: path2 } = this.parseToolId(toolId2);
|
|
18848
|
+
if (path2 === endpoint) {
|
|
18819
18849
|
matchingTool = tool;
|
|
18820
18850
|
matchingToolId = toolId2;
|
|
18821
18851
|
break;
|
|
@@ -18852,8 +18882,8 @@ var ApiClient = class {
|
|
|
18852
18882
|
} else if (this.openApiSpec) {
|
|
18853
18883
|
const pathItem = this.openApiSpec.paths[endpoint];
|
|
18854
18884
|
if (pathItem && pathItem[method.toLowerCase()]) {
|
|
18855
|
-
const { method: httpMethod, path } = { method: method.toUpperCase(), path: endpoint };
|
|
18856
|
-
return this.makeDirectHttpRequest(httpMethod,
|
|
18885
|
+
const { method: httpMethod, path: path2 } = { method: method.toUpperCase(), path: endpoint };
|
|
18886
|
+
return this.makeDirectHttpRequest(httpMethod, path2, endpointParams);
|
|
18857
18887
|
} else {
|
|
18858
18888
|
throw new Error(
|
|
18859
18889
|
`No endpoint found for path '${endpoint}' with method '${method}' in tool '${toolId2}'`
|
|
@@ -18882,11 +18912,11 @@ var ApiClient = class {
|
|
|
18882
18912
|
* Make a direct HTTP request without going through the tool system
|
|
18883
18913
|
* Used by dynamic meta-tools when we have OpenAPI spec but no corresponding tool
|
|
18884
18914
|
*/
|
|
18885
|
-
async makeDirectHttpRequest(method,
|
|
18915
|
+
async makeDirectHttpRequest(method, path2, params) {
|
|
18886
18916
|
const authHeaders = await this.authProvider.getAuthHeaders();
|
|
18887
18917
|
const config = {
|
|
18888
18918
|
method: method.toLowerCase(),
|
|
18889
|
-
url:
|
|
18919
|
+
url: path2,
|
|
18890
18920
|
headers: authHeaders
|
|
18891
18921
|
};
|
|
18892
18922
|
if (isGetLikeMethod(method)) {
|
|
@@ -18909,22 +18939,265 @@ var ApiClient = class {
|
|
|
18909
18939
|
}
|
|
18910
18940
|
};
|
|
18911
18941
|
|
|
18942
|
+
// src/prompts-manager.ts
|
|
18943
|
+
var PromptsManager = class {
|
|
18944
|
+
prompts = /* @__PURE__ */ new Map();
|
|
18945
|
+
constructor(config) {
|
|
18946
|
+
if (config.prompts) {
|
|
18947
|
+
for (const prompt of config.prompts) {
|
|
18948
|
+
this.addPrompt(prompt);
|
|
18949
|
+
}
|
|
18950
|
+
}
|
|
18951
|
+
}
|
|
18952
|
+
/**
|
|
18953
|
+
* Add a prompt definition
|
|
18954
|
+
*/
|
|
18955
|
+
addPrompt(prompt) {
|
|
18956
|
+
if (!prompt.name) {
|
|
18957
|
+
throw new Error("Prompt name is required");
|
|
18958
|
+
}
|
|
18959
|
+
if (!prompt.template) {
|
|
18960
|
+
throw new Error(`Prompt "${prompt.name}" requires a template`);
|
|
18961
|
+
}
|
|
18962
|
+
this.prompts.set(prompt.name, prompt);
|
|
18963
|
+
}
|
|
18964
|
+
/**
|
|
18965
|
+
* Remove a prompt by name
|
|
18966
|
+
*/
|
|
18967
|
+
removePrompt(name) {
|
|
18968
|
+
return this.prompts.delete(name);
|
|
18969
|
+
}
|
|
18970
|
+
/**
|
|
18971
|
+
* Get all prompts in MCP format for listing
|
|
18972
|
+
*/
|
|
18973
|
+
getAllPrompts() {
|
|
18974
|
+
return Array.from(this.prompts.values()).map((def) => this.toMCPPrompt(def));
|
|
18975
|
+
}
|
|
18976
|
+
/**
|
|
18977
|
+
* Get a specific prompt with arguments applied
|
|
18978
|
+
*/
|
|
18979
|
+
getPrompt(name, args) {
|
|
18980
|
+
const def = this.prompts.get(name);
|
|
18981
|
+
if (!def) {
|
|
18982
|
+
throw new Error(`Prompt not found: ${name}`);
|
|
18983
|
+
}
|
|
18984
|
+
if (def.arguments) {
|
|
18985
|
+
for (const arg of def.arguments) {
|
|
18986
|
+
if (arg.required && (!args || args[arg.name] === void 0)) {
|
|
18987
|
+
throw new Error(`Missing required argument: ${arg.name}`);
|
|
18988
|
+
}
|
|
18989
|
+
}
|
|
18990
|
+
}
|
|
18991
|
+
const renderedText = this.renderTemplate(def.template, args || {});
|
|
18992
|
+
const messages = [
|
|
18993
|
+
{
|
|
18994
|
+
role: "user",
|
|
18995
|
+
content: {
|
|
18996
|
+
type: "text",
|
|
18997
|
+
text: renderedText
|
|
18998
|
+
}
|
|
18999
|
+
}
|
|
19000
|
+
];
|
|
19001
|
+
return {
|
|
19002
|
+
description: def.description,
|
|
19003
|
+
messages
|
|
19004
|
+
};
|
|
19005
|
+
}
|
|
19006
|
+
/**
|
|
19007
|
+
* Check if a prompt exists
|
|
19008
|
+
*/
|
|
19009
|
+
hasPrompt(name) {
|
|
19010
|
+
return this.prompts.has(name);
|
|
19011
|
+
}
|
|
19012
|
+
/**
|
|
19013
|
+
* Get the count of prompts
|
|
19014
|
+
*/
|
|
19015
|
+
get count() {
|
|
19016
|
+
return this.prompts.size;
|
|
19017
|
+
}
|
|
19018
|
+
/**
|
|
19019
|
+
* Convert internal prompt definition to MCP Prompt format
|
|
19020
|
+
*/
|
|
19021
|
+
toMCPPrompt(def) {
|
|
19022
|
+
const prompt = {
|
|
19023
|
+
name: def.name,
|
|
19024
|
+
description: def.description
|
|
19025
|
+
};
|
|
19026
|
+
if (def.arguments && def.arguments.length > 0) {
|
|
19027
|
+
prompt.arguments = def.arguments.map(
|
|
19028
|
+
(arg) => ({
|
|
19029
|
+
name: arg.name,
|
|
19030
|
+
description: arg.description,
|
|
19031
|
+
required: arg.required
|
|
19032
|
+
})
|
|
19033
|
+
);
|
|
19034
|
+
}
|
|
19035
|
+
return prompt;
|
|
19036
|
+
}
|
|
19037
|
+
/**
|
|
19038
|
+
* Render a template string by replacing {{argName}} placeholders
|
|
19039
|
+
*/
|
|
19040
|
+
renderTemplate(template, args) {
|
|
19041
|
+
return template.replace(/\{\{(\w+)\}\}/g, (match, argName) => {
|
|
19042
|
+
if (args[argName] !== void 0) {
|
|
19043
|
+
return args[argName];
|
|
19044
|
+
}
|
|
19045
|
+
return "";
|
|
19046
|
+
});
|
|
19047
|
+
}
|
|
19048
|
+
};
|
|
19049
|
+
|
|
19050
|
+
// src/resources-manager.ts
|
|
19051
|
+
var ResourcesManager = class {
|
|
19052
|
+
resources = /* @__PURE__ */ new Map();
|
|
19053
|
+
constructor(config) {
|
|
19054
|
+
if (config.resources) {
|
|
19055
|
+
for (const resource of config.resources) {
|
|
19056
|
+
this.addResource(resource);
|
|
19057
|
+
}
|
|
19058
|
+
}
|
|
19059
|
+
}
|
|
19060
|
+
/**
|
|
19061
|
+
* Add a resource definition
|
|
19062
|
+
*/
|
|
19063
|
+
addResource(resource) {
|
|
19064
|
+
if (!resource.uri) {
|
|
19065
|
+
throw new Error("Resource URI is required");
|
|
19066
|
+
}
|
|
19067
|
+
if (!resource.name) {
|
|
19068
|
+
throw new Error(`Resource "${resource.uri}" requires a name`);
|
|
19069
|
+
}
|
|
19070
|
+
if (!resource.text && !resource.blob && !resource.contentProvider) {
|
|
19071
|
+
throw new Error(
|
|
19072
|
+
`Resource "${resource.uri}" requires content (text, blob, or contentProvider)`
|
|
19073
|
+
);
|
|
19074
|
+
}
|
|
19075
|
+
this.resources.set(resource.uri, resource);
|
|
19076
|
+
}
|
|
19077
|
+
/**
|
|
19078
|
+
* Remove a resource by URI
|
|
19079
|
+
*/
|
|
19080
|
+
removeResource(uri) {
|
|
19081
|
+
return this.resources.delete(uri);
|
|
19082
|
+
}
|
|
19083
|
+
/**
|
|
19084
|
+
* Get all resources in MCP format for listing
|
|
19085
|
+
*/
|
|
19086
|
+
getAllResources() {
|
|
19087
|
+
return Array.from(this.resources.values()).map((def) => this.toMCPResource(def));
|
|
19088
|
+
}
|
|
19089
|
+
/**
|
|
19090
|
+
* Read a specific resource by URI
|
|
19091
|
+
*/
|
|
19092
|
+
async readResource(uri) {
|
|
19093
|
+
const def = this.resources.get(uri);
|
|
19094
|
+
if (!def) {
|
|
19095
|
+
throw new Error(`Resource not found: ${uri}`);
|
|
19096
|
+
}
|
|
19097
|
+
let contents;
|
|
19098
|
+
if (def.contentProvider) {
|
|
19099
|
+
let content;
|
|
19100
|
+
try {
|
|
19101
|
+
content = await def.contentProvider();
|
|
19102
|
+
} catch (error) {
|
|
19103
|
+
throw new Error(
|
|
19104
|
+
`Failed to load content for resource "${uri}": ${error instanceof Error ? error.message : String(error)}`
|
|
19105
|
+
);
|
|
19106
|
+
}
|
|
19107
|
+
if (typeof content === "string") {
|
|
19108
|
+
contents = [
|
|
19109
|
+
{
|
|
19110
|
+
uri: def.uri,
|
|
19111
|
+
mimeType: def.mimeType,
|
|
19112
|
+
text: content
|
|
19113
|
+
}
|
|
19114
|
+
];
|
|
19115
|
+
} else {
|
|
19116
|
+
contents = [
|
|
19117
|
+
{
|
|
19118
|
+
uri: def.uri,
|
|
19119
|
+
mimeType: def.mimeType,
|
|
19120
|
+
blob: content.blob
|
|
19121
|
+
}
|
|
19122
|
+
];
|
|
19123
|
+
}
|
|
19124
|
+
} else if (def.text !== void 0) {
|
|
19125
|
+
contents = [
|
|
19126
|
+
{
|
|
19127
|
+
uri: def.uri,
|
|
19128
|
+
mimeType: def.mimeType,
|
|
19129
|
+
text: def.text
|
|
19130
|
+
}
|
|
19131
|
+
];
|
|
19132
|
+
} else if (def.blob !== void 0) {
|
|
19133
|
+
contents = [
|
|
19134
|
+
{
|
|
19135
|
+
uri: def.uri,
|
|
19136
|
+
mimeType: def.mimeType,
|
|
19137
|
+
blob: def.blob
|
|
19138
|
+
}
|
|
19139
|
+
];
|
|
19140
|
+
} else {
|
|
19141
|
+
throw new Error(`Resource "${uri}" has no content`);
|
|
19142
|
+
}
|
|
19143
|
+
return { contents };
|
|
19144
|
+
}
|
|
19145
|
+
/**
|
|
19146
|
+
* Check if a resource exists
|
|
19147
|
+
*/
|
|
19148
|
+
hasResource(uri) {
|
|
19149
|
+
return this.resources.has(uri);
|
|
19150
|
+
}
|
|
19151
|
+
/**
|
|
19152
|
+
* Get the count of resources
|
|
19153
|
+
*/
|
|
19154
|
+
get count() {
|
|
19155
|
+
return this.resources.size;
|
|
19156
|
+
}
|
|
19157
|
+
/**
|
|
19158
|
+
* Convert internal resource definition to MCP Resource format
|
|
19159
|
+
*/
|
|
19160
|
+
toMCPResource(def) {
|
|
19161
|
+
return {
|
|
19162
|
+
uri: def.uri,
|
|
19163
|
+
name: def.name,
|
|
19164
|
+
description: def.description,
|
|
19165
|
+
mimeType: def.mimeType
|
|
19166
|
+
};
|
|
19167
|
+
}
|
|
19168
|
+
};
|
|
19169
|
+
|
|
18912
19170
|
// src/server.ts
|
|
18913
19171
|
var OpenAPIServer = class {
|
|
18914
19172
|
server;
|
|
18915
19173
|
toolsManager;
|
|
18916
19174
|
apiClient;
|
|
19175
|
+
promptsManager;
|
|
19176
|
+
resourcesManager;
|
|
19177
|
+
config;
|
|
18917
19178
|
constructor(config) {
|
|
19179
|
+
this.config = config;
|
|
19180
|
+
if (config.prompts?.length) {
|
|
19181
|
+
this.promptsManager = new PromptsManager({ prompts: config.prompts });
|
|
19182
|
+
}
|
|
19183
|
+
if (config.resources?.length) {
|
|
19184
|
+
this.resourcesManager = new ResourcesManager({ resources: config.resources });
|
|
19185
|
+
}
|
|
19186
|
+
const capabilities = {
|
|
19187
|
+
tools: {
|
|
19188
|
+
list: true,
|
|
19189
|
+
execute: true
|
|
19190
|
+
}
|
|
19191
|
+
};
|
|
19192
|
+
if (this.promptsManager) {
|
|
19193
|
+
capabilities.prompts = {};
|
|
19194
|
+
}
|
|
19195
|
+
if (this.resourcesManager) {
|
|
19196
|
+
capabilities.resources = {};
|
|
19197
|
+
}
|
|
18918
19198
|
this.server = new Server(
|
|
18919
19199
|
{ name: config.name, version: config.version },
|
|
18920
|
-
{
|
|
18921
|
-
capabilities: {
|
|
18922
|
-
tools: {
|
|
18923
|
-
list: true,
|
|
18924
|
-
execute: true
|
|
18925
|
-
}
|
|
18926
|
-
}
|
|
18927
|
-
}
|
|
19200
|
+
{ capabilities }
|
|
18928
19201
|
);
|
|
18929
19202
|
this.toolsManager = new ToolsManager(config);
|
|
18930
19203
|
const authProviderOrHeaders = config.authProvider || new StaticAuthProvider(config.headers);
|
|
@@ -18986,6 +19259,25 @@ var OpenAPIServer = class {
|
|
|
18986
19259
|
throw error;
|
|
18987
19260
|
}
|
|
18988
19261
|
});
|
|
19262
|
+
if (this.promptsManager) {
|
|
19263
|
+
this.server.setRequestHandler(ListPromptsRequestSchema, async () => ({
|
|
19264
|
+
prompts: this.promptsManager.getAllPrompts()
|
|
19265
|
+
}));
|
|
19266
|
+
this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
19267
|
+
return this.promptsManager.getPrompt(
|
|
19268
|
+
request.params.name,
|
|
19269
|
+
request.params.arguments
|
|
19270
|
+
);
|
|
19271
|
+
});
|
|
19272
|
+
}
|
|
19273
|
+
if (this.resourcesManager) {
|
|
19274
|
+
this.server.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
19275
|
+
resources: this.resourcesManager.getAllResources()
|
|
19276
|
+
}));
|
|
19277
|
+
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
19278
|
+
return this.resourcesManager.readResource(request.params.uri);
|
|
19279
|
+
});
|
|
19280
|
+
}
|
|
18989
19281
|
}
|
|
18990
19282
|
/**
|
|
18991
19283
|
* Start the server with the given transport
|
|
@@ -19003,6 +19295,18 @@ var OpenAPIServer = class {
|
|
|
19003
19295
|
}
|
|
19004
19296
|
await this.server.connect(transport);
|
|
19005
19297
|
}
|
|
19298
|
+
/**
|
|
19299
|
+
* Get the prompts manager (for library users to add prompts dynamically)
|
|
19300
|
+
*/
|
|
19301
|
+
getPromptsManager() {
|
|
19302
|
+
return this.promptsManager;
|
|
19303
|
+
}
|
|
19304
|
+
/**
|
|
19305
|
+
* Get the resources manager (for library users to add resources dynamically)
|
|
19306
|
+
*/
|
|
19307
|
+
getResourcesManager() {
|
|
19308
|
+
return this.resourcesManager;
|
|
19309
|
+
}
|
|
19006
19310
|
};
|
|
19007
19311
|
|
|
19008
19312
|
// node_modules/yargs/lib/platform-shims/esm.mjs
|
|
@@ -20281,11 +20585,11 @@ var parser = new YargsParser({
|
|
|
20281
20585
|
resolve: resolve2,
|
|
20282
20586
|
// TODO: figure out a way to combine ESM and CJS coverage, such that
|
|
20283
20587
|
// we can exercise all the lines below:
|
|
20284
|
-
require: (
|
|
20588
|
+
require: (path2) => {
|
|
20285
20589
|
if (typeof __require !== "undefined") {
|
|
20286
|
-
return __require(
|
|
20287
|
-
} else if (
|
|
20288
|
-
return JSON.parse(readFileSync(
|
|
20590
|
+
return __require(path2);
|
|
20591
|
+
} else if (path2.match(/\.json$/)) {
|
|
20592
|
+
return JSON.parse(readFileSync(path2, "utf8"));
|
|
20289
20593
|
} else {
|
|
20290
20594
|
throw Error("only .json config files are supported in ESM");
|
|
20291
20595
|
}
|
|
@@ -22810,12 +23114,12 @@ var YargsInstance = class {
|
|
|
22810
23114
|
async getCompletion(args, done) {
|
|
22811
23115
|
argsert("<array> [function]", [args, done], arguments.length);
|
|
22812
23116
|
if (!done) {
|
|
22813
|
-
return new Promise((
|
|
23117
|
+
return new Promise((resolve6, reject) => {
|
|
22814
23118
|
__classPrivateFieldGet(this, _YargsInstance_completion, "f").getCompletion(args, (err, completions) => {
|
|
22815
23119
|
if (err)
|
|
22816
23120
|
reject(err);
|
|
22817
23121
|
else
|
|
22818
|
-
|
|
23122
|
+
resolve6(completions);
|
|
22819
23123
|
});
|
|
22820
23124
|
});
|
|
22821
23125
|
} else {
|
|
@@ -23934,6 +24238,18 @@ function loadConfig() {
|
|
|
23934
24238
|
}).option("disable-abbreviation", {
|
|
23935
24239
|
type: "boolean",
|
|
23936
24240
|
description: "Disable name optimization"
|
|
24241
|
+
}).option("prompts", {
|
|
24242
|
+
type: "string",
|
|
24243
|
+
description: "Path or URL to prompts JSON/YAML file"
|
|
24244
|
+
}).option("prompts-inline", {
|
|
24245
|
+
type: "string",
|
|
24246
|
+
description: "Provide prompts directly as JSON string"
|
|
24247
|
+
}).option("resources", {
|
|
24248
|
+
type: "string",
|
|
24249
|
+
description: "Path or URL to resources JSON/YAML file"
|
|
24250
|
+
}).option("resources-inline", {
|
|
24251
|
+
type: "string",
|
|
24252
|
+
description: "Provide resources directly as JSON string"
|
|
23937
24253
|
}).help().parseSync();
|
|
23938
24254
|
let transportType;
|
|
23939
24255
|
if (argv.transport === "http" || process.env.TRANSPORT_TYPE === "http") {
|
|
@@ -24011,7 +24327,11 @@ function loadConfig() {
|
|
|
24011
24327
|
includeResources: argv.resource,
|
|
24012
24328
|
includeOperations: argv.operation,
|
|
24013
24329
|
toolsMode,
|
|
24014
|
-
disableAbbreviation: disableAbbreviation ? true : void 0
|
|
24330
|
+
disableAbbreviation: disableAbbreviation ? true : void 0,
|
|
24331
|
+
promptsPath: argv.prompts || process.env.PROMPTS_PATH,
|
|
24332
|
+
promptsInline: argv["prompts-inline"] || process.env.PROMPTS_INLINE,
|
|
24333
|
+
resourcesPath: argv.resources || process.env.RESOURCES_PATH,
|
|
24334
|
+
resourcesInline: argv["resources-inline"] || process.env.RESOURCES_INLINE
|
|
24015
24335
|
};
|
|
24016
24336
|
}
|
|
24017
24337
|
|
|
@@ -24080,13 +24400,13 @@ var StreamableHttpServerTransport = class {
|
|
|
24080
24400
|
if (this.started) {
|
|
24081
24401
|
throw new Error("Transport already started");
|
|
24082
24402
|
}
|
|
24083
|
-
return new Promise((
|
|
24403
|
+
return new Promise((resolve6, reject) => {
|
|
24084
24404
|
this.server.listen(this.port, this.host, () => {
|
|
24085
24405
|
this.started = true;
|
|
24086
24406
|
console.error(
|
|
24087
24407
|
`Streamable HTTP transport listening on http://${this.host}:${this.port}${this.endpointPath}`
|
|
24088
24408
|
);
|
|
24089
|
-
|
|
24409
|
+
resolve6();
|
|
24090
24410
|
});
|
|
24091
24411
|
this.server.on("error", (err) => {
|
|
24092
24412
|
reject(err);
|
|
@@ -24116,7 +24436,7 @@ var StreamableHttpServerTransport = class {
|
|
|
24116
24436
|
}
|
|
24117
24437
|
return;
|
|
24118
24438
|
}
|
|
24119
|
-
return new Promise((
|
|
24439
|
+
return new Promise((resolve6, reject) => {
|
|
24120
24440
|
this.server.close((err) => {
|
|
24121
24441
|
if (err) {
|
|
24122
24442
|
reject(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -24125,7 +24445,7 @@ var StreamableHttpServerTransport = class {
|
|
|
24125
24445
|
if (this.onclose) {
|
|
24126
24446
|
this.onclose();
|
|
24127
24447
|
}
|
|
24128
|
-
|
|
24448
|
+
resolve6();
|
|
24129
24449
|
}
|
|
24130
24450
|
});
|
|
24131
24451
|
});
|
|
@@ -24607,10 +24927,82 @@ var StreamableHttpServerTransport = class {
|
|
|
24607
24927
|
}
|
|
24608
24928
|
};
|
|
24609
24929
|
|
|
24930
|
+
// src/content-loader.ts
|
|
24931
|
+
import * as fs from "fs";
|
|
24932
|
+
import * as path from "path";
|
|
24933
|
+
async function loadContent(pathOrUrl, inline) {
|
|
24934
|
+
if (inline) {
|
|
24935
|
+
return inline;
|
|
24936
|
+
}
|
|
24937
|
+
if (!pathOrUrl) {
|
|
24938
|
+
return void 0;
|
|
24939
|
+
}
|
|
24940
|
+
if (pathOrUrl.startsWith("http://") || pathOrUrl.startsWith("https://")) {
|
|
24941
|
+
const response = await axios_default.get(pathOrUrl, {
|
|
24942
|
+
responseType: "text",
|
|
24943
|
+
headers: { Accept: "application/json, application/yaml, text/yaml" }
|
|
24944
|
+
});
|
|
24945
|
+
return response.data;
|
|
24946
|
+
}
|
|
24947
|
+
const absolutePath = path.isAbsolute(pathOrUrl) ? pathOrUrl : path.resolve(process.cwd(), pathOrUrl);
|
|
24948
|
+
return fs.readFileSync(absolutePath, "utf-8");
|
|
24949
|
+
}
|
|
24950
|
+
function parseContent(content, source) {
|
|
24951
|
+
try {
|
|
24952
|
+
return JSON.parse(content);
|
|
24953
|
+
} catch {
|
|
24954
|
+
try {
|
|
24955
|
+
return js_yaml_default.load(content);
|
|
24956
|
+
} catch (yamlError) {
|
|
24957
|
+
throw new Error(
|
|
24958
|
+
`Failed to parse ${source} as JSON or YAML: ${yamlError}`
|
|
24959
|
+
);
|
|
24960
|
+
}
|
|
24961
|
+
}
|
|
24962
|
+
}
|
|
24963
|
+
async function loadPrompts(pathOrUrl, inline) {
|
|
24964
|
+
const content = await loadContent(pathOrUrl, inline);
|
|
24965
|
+
if (!content) {
|
|
24966
|
+
return void 0;
|
|
24967
|
+
}
|
|
24968
|
+
const source = inline ? "inline prompts" : pathOrUrl;
|
|
24969
|
+
const prompts = parseContent(content, source);
|
|
24970
|
+
if (!Array.isArray(prompts)) {
|
|
24971
|
+
throw new Error(`Prompts must be an array, got: ${typeof prompts}`);
|
|
24972
|
+
}
|
|
24973
|
+
return prompts;
|
|
24974
|
+
}
|
|
24975
|
+
async function loadResources(pathOrUrl, inline) {
|
|
24976
|
+
const content = await loadContent(pathOrUrl, inline);
|
|
24977
|
+
if (!content) {
|
|
24978
|
+
return void 0;
|
|
24979
|
+
}
|
|
24980
|
+
const source = inline ? "inline resources" : pathOrUrl;
|
|
24981
|
+
const resources = parseContent(content, source);
|
|
24982
|
+
if (!Array.isArray(resources)) {
|
|
24983
|
+
throw new Error(`Resources must be an array, got: ${typeof resources}`);
|
|
24984
|
+
}
|
|
24985
|
+
return resources;
|
|
24986
|
+
}
|
|
24987
|
+
|
|
24610
24988
|
// src/index.ts
|
|
24611
24989
|
async function main() {
|
|
24612
24990
|
try {
|
|
24613
24991
|
const config = loadConfig();
|
|
24992
|
+
if (config.promptsPath || config.promptsInline) {
|
|
24993
|
+
const prompts = await loadPrompts(config.promptsPath, config.promptsInline);
|
|
24994
|
+
if (prompts) {
|
|
24995
|
+
config.prompts = prompts;
|
|
24996
|
+
console.error(`Loaded ${prompts.length} prompt(s)`);
|
|
24997
|
+
}
|
|
24998
|
+
}
|
|
24999
|
+
if (config.resourcesPath || config.resourcesInline) {
|
|
25000
|
+
const resources = await loadResources(config.resourcesPath, config.resourcesInline);
|
|
25001
|
+
if (resources) {
|
|
25002
|
+
config.resources = resources;
|
|
25003
|
+
console.error(`Loaded ${resources.length} resource(s)`);
|
|
25004
|
+
}
|
|
25005
|
+
}
|
|
24614
25006
|
const server = new OpenAPIServer(config);
|
|
24615
25007
|
let transport;
|
|
24616
25008
|
if (config.transportType === "http") {
|