mcp-from-openapi 2.1.0 → 2.1.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/CHANGELOG.md +13 -0
- package/README.md +1 -1
- package/esm/index.mjs +1561 -0
- package/esm/package.json +65 -0
- package/index.js +1612 -0
- package/package.json +18 -10
- package/src/errors.js +0 -67
- package/src/errors.js.map +0 -1
- package/src/generator.js +0 -381
- package/src/generator.js.map +0 -1
- package/src/index.js +0 -30
- package/src/index.js.map +0 -1
- package/src/parameter-resolver.js +0 -294
- package/src/parameter-resolver.js.map +0 -1
- package/src/response-builder.js +0 -149
- package/src/response-builder.js.map +0 -1
- package/src/schema-builder.js +0 -291
- package/src/schema-builder.js.map +0 -1
- package/src/security-resolver.js +0 -324
- package/src/security-resolver.js.map +0 -1
- package/src/types.js +0 -99
- package/src/types.js.map +0 -1
- package/src/validator.js +0 -213
- package/src/validator.js.map +0 -1
- /package/{src/errors.d.ts → errors.d.ts} +0 -0
- /package/{src/generator.d.ts → generator.d.ts} +0 -0
- /package/{src/index.d.ts → index.d.ts} +0 -0
- /package/{src/parameter-resolver.d.ts → parameter-resolver.d.ts} +0 -0
- /package/{src/response-builder.d.ts → response-builder.d.ts} +0 -0
- /package/{src/schema-builder.d.ts → schema-builder.d.ts} +0 -0
- /package/{src/security-resolver.d.ts → security-resolver.d.ts} +0 -0
- /package/{src/types.d.ts → types.d.ts} +0 -0
- /package/{src/validator.d.ts → validator.d.ts} +0 -0
package/src/schema-builder.js
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaBuilder = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Helper class for building and manipulating JSON schemas
|
|
6
|
-
*/
|
|
7
|
-
class SchemaBuilder {
|
|
8
|
-
/**
|
|
9
|
-
* Merge multiple schemas into one
|
|
10
|
-
*/
|
|
11
|
-
static merge(schemas) {
|
|
12
|
-
if (schemas.length === 0) {
|
|
13
|
-
return { type: 'object' };
|
|
14
|
-
}
|
|
15
|
-
if (schemas.length === 1) {
|
|
16
|
-
return schemas[0];
|
|
17
|
-
}
|
|
18
|
-
const merged = {
|
|
19
|
-
type: 'object',
|
|
20
|
-
properties: {},
|
|
21
|
-
required: [],
|
|
22
|
-
};
|
|
23
|
-
const allRequired = new Set();
|
|
24
|
-
for (const schema of schemas) {
|
|
25
|
-
if (schema.properties) {
|
|
26
|
-
merged.properties = {
|
|
27
|
-
...merged.properties,
|
|
28
|
-
...schema.properties,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
if (schema.required) {
|
|
32
|
-
schema.required.forEach((field) => allRequired.add(field));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (allRequired.size > 0) {
|
|
36
|
-
merged.required = Array.from(allRequired);
|
|
37
|
-
}
|
|
38
|
-
return merged;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Create a union schema (oneOf)
|
|
42
|
-
*/
|
|
43
|
-
static union(schemas) {
|
|
44
|
-
if (schemas.length === 0) {
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
if (schemas.length === 1) {
|
|
48
|
-
return schemas[0];
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
oneOf: schemas,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Deep clone a schema
|
|
56
|
-
*/
|
|
57
|
-
static clone(schema) {
|
|
58
|
-
return JSON.parse(JSON.stringify(schema));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Remove $ref from schema (assumes already dereferenced)
|
|
62
|
-
*/
|
|
63
|
-
static removeRefs(schema) {
|
|
64
|
-
const cloned = this.clone(schema);
|
|
65
|
-
this.removeRefsRecursive(cloned);
|
|
66
|
-
return cloned;
|
|
67
|
-
}
|
|
68
|
-
static removeRefsRecursive(obj) {
|
|
69
|
-
if (!obj || typeof obj !== 'object')
|
|
70
|
-
return;
|
|
71
|
-
if (obj.$ref) {
|
|
72
|
-
delete obj.$ref;
|
|
73
|
-
}
|
|
74
|
-
for (const key in obj) {
|
|
75
|
-
if (key in obj) {
|
|
76
|
-
const value = obj[key];
|
|
77
|
-
if (value && typeof value === 'object') {
|
|
78
|
-
this.removeRefsRecursive(value);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Add description to schema
|
|
85
|
-
*/
|
|
86
|
-
static withDescription(schema, description) {
|
|
87
|
-
return {
|
|
88
|
-
...schema,
|
|
89
|
-
description,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Add example to schema
|
|
94
|
-
*/
|
|
95
|
-
static withExample(schema, example) {
|
|
96
|
-
const existingExamples = Array.isArray(schema.examples) ? schema.examples : [];
|
|
97
|
-
return {
|
|
98
|
-
...schema,
|
|
99
|
-
examples: [...existingExamples, example],
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Add default value to schema
|
|
104
|
-
*/
|
|
105
|
-
static withDefault(schema, defaultValue) {
|
|
106
|
-
return {
|
|
107
|
-
...schema,
|
|
108
|
-
default: defaultValue,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Add format to schema
|
|
113
|
-
*/
|
|
114
|
-
static withFormat(schema, format) {
|
|
115
|
-
return {
|
|
116
|
-
...schema,
|
|
117
|
-
format,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Add pattern to schema
|
|
122
|
-
*/
|
|
123
|
-
static withPattern(schema, pattern) {
|
|
124
|
-
return {
|
|
125
|
-
...schema,
|
|
126
|
-
pattern,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Add enum to schema
|
|
131
|
-
*/
|
|
132
|
-
static withEnum(schema, values) {
|
|
133
|
-
return {
|
|
134
|
-
...schema,
|
|
135
|
-
enum: values,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Add minimum/maximum constraints
|
|
140
|
-
*/
|
|
141
|
-
static withRange(schema, min, max, options = {}) {
|
|
142
|
-
const result = { ...schema };
|
|
143
|
-
if (min !== undefined) {
|
|
144
|
-
if (options.exclusive) {
|
|
145
|
-
result.exclusiveMinimum = min;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
result.minimum = min;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
if (max !== undefined) {
|
|
152
|
-
if (options.exclusive) {
|
|
153
|
-
result.exclusiveMaximum = max;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
result.maximum = max;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Add minLength/maxLength constraints
|
|
163
|
-
*/
|
|
164
|
-
static withLength(schema, minLength, maxLength) {
|
|
165
|
-
const result = { ...schema };
|
|
166
|
-
if (minLength !== undefined) {
|
|
167
|
-
result.minLength = minLength;
|
|
168
|
-
}
|
|
169
|
-
if (maxLength !== undefined) {
|
|
170
|
-
result.maxLength = maxLength;
|
|
171
|
-
}
|
|
172
|
-
return result;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Create object schema
|
|
176
|
-
*/
|
|
177
|
-
static object(properties, required) {
|
|
178
|
-
return {
|
|
179
|
-
type: 'object',
|
|
180
|
-
properties,
|
|
181
|
-
...(required && required.length > 0 && { required }),
|
|
182
|
-
additionalProperties: false,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Create array schema
|
|
187
|
-
*/
|
|
188
|
-
static array(items, constraints) {
|
|
189
|
-
return {
|
|
190
|
-
type: 'array',
|
|
191
|
-
items,
|
|
192
|
-
...constraints,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Create string schema
|
|
197
|
-
*/
|
|
198
|
-
static string(constraints) {
|
|
199
|
-
return {
|
|
200
|
-
type: 'string',
|
|
201
|
-
...constraints,
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Create number schema
|
|
206
|
-
*/
|
|
207
|
-
static number(constraints) {
|
|
208
|
-
return {
|
|
209
|
-
type: 'number',
|
|
210
|
-
...constraints,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Create integer schema
|
|
215
|
-
*/
|
|
216
|
-
static integer(constraints) {
|
|
217
|
-
return {
|
|
218
|
-
type: 'integer',
|
|
219
|
-
...constraints,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Create boolean schema
|
|
224
|
-
*/
|
|
225
|
-
static boolean() {
|
|
226
|
-
return {
|
|
227
|
-
type: 'boolean',
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Create null schema
|
|
232
|
-
*/
|
|
233
|
-
static null() {
|
|
234
|
-
return {
|
|
235
|
-
type: 'null',
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Flatten nested oneOf/anyOf/allOf schemas
|
|
240
|
-
*/
|
|
241
|
-
static flatten(schema, maxDepth = 10) {
|
|
242
|
-
if (maxDepth <= 0)
|
|
243
|
-
return schema;
|
|
244
|
-
const cloned = this.clone(schema);
|
|
245
|
-
if (cloned.oneOf) {
|
|
246
|
-
const flattened = cloned.oneOf.flatMap((s) => {
|
|
247
|
-
const sub = this.flatten(s, maxDepth - 1);
|
|
248
|
-
return sub.oneOf ? sub.oneOf : [sub];
|
|
249
|
-
});
|
|
250
|
-
cloned.oneOf = flattened;
|
|
251
|
-
}
|
|
252
|
-
if (cloned.anyOf) {
|
|
253
|
-
const flattened = cloned.anyOf.flatMap((s) => {
|
|
254
|
-
const sub = this.flatten(s, maxDepth - 1);
|
|
255
|
-
return sub.anyOf ? sub.anyOf : [sub];
|
|
256
|
-
});
|
|
257
|
-
cloned.anyOf = flattened;
|
|
258
|
-
}
|
|
259
|
-
if (cloned.allOf) {
|
|
260
|
-
const flattened = cloned.allOf.flatMap((s) => {
|
|
261
|
-
const sub = this.flatten(s, maxDepth - 1);
|
|
262
|
-
return sub.allOf ? sub.allOf : [sub];
|
|
263
|
-
});
|
|
264
|
-
cloned.allOf = flattened;
|
|
265
|
-
}
|
|
266
|
-
return cloned;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Simplify schema by removing unnecessary fields
|
|
270
|
-
*/
|
|
271
|
-
static simplify(schema) {
|
|
272
|
-
const cloned = this.clone(schema);
|
|
273
|
-
// Remove empty arrays/objects
|
|
274
|
-
if (Array.isArray(cloned.required) && cloned.required.length === 0) {
|
|
275
|
-
delete cloned.required;
|
|
276
|
-
}
|
|
277
|
-
if (cloned.properties && Object.keys(cloned.properties).length === 0) {
|
|
278
|
-
delete cloned.properties;
|
|
279
|
-
}
|
|
280
|
-
if (Array.isArray(cloned.examples) && cloned.examples.length === 0) {
|
|
281
|
-
delete cloned.examples;
|
|
282
|
-
}
|
|
283
|
-
// Remove title if it matches description
|
|
284
|
-
if (cloned.title && cloned.description && cloned.title === cloned.description) {
|
|
285
|
-
delete cloned.title;
|
|
286
|
-
}
|
|
287
|
-
return cloned;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
exports.SchemaBuilder = SchemaBuilder;
|
|
291
|
-
//# sourceMappingURL=schema-builder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-builder.js","sourceRoot":"","sources":["../../src/schema-builder.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,MAAa,aAAa;IACxB;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,OAAqB;QAChC,IAAI,OAAO,CAAC,MAAM,KAAK,CA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,GAAG,CAAC,CAAC,CAAC;gBACxD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACvC,CAAC,CAAC,CAAC;YACH,MAAM,CAAC,KAAK,GAAG,SAAyB,CAAC;QAC3C,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAkB;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAElC,8BAA8B;QAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnE,OAAO,MAAM,CAAC,QAAQ,CAAC;QACzB,CAAC;QAED,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrE,OAAO,MAAM,CAAC,UAAU,CAAC;QAC3B,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnE,OAAO,MAAM,CAAC,QAAQ,CAAC;QACzB,CAAC;QAED,yCAAyC;QACzC,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC;YAC9E,OAAO,MAAM,CAAC,KAAK,CAAC;QACtB,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA/VD,sCA+VC","sourcesContent":["import type { JSONSchema } from 'zod/v4/core';\n\n/** JSON Schema type from Zod v4 */\ntype JsonSchema = JSONSchema.JSONSchema;\n\n/**\n * Helper class for building and manipulating JSON schemas\n */\nexport class SchemaBuilder {\n /**\n * Merge multiple schemas into one\n */\n static merge(schemas: JsonSchema[]): JsonSchema {\n if (schemas.length === 0) {\n return { type: 'object' };\n }\n\n if (schemas.length === 1) {\n return schemas[0];\n }\n\n const merged: JsonSchema = {\n type: 'object',\n properties: {},\n required: [],\n };\n\n const allRequired = new Set<string>();\n\n for (const schema of schemas) {\n if (schema.properties) {\n merged.properties = {\n ...merged.properties,\n ...schema.properties,\n };\n }\n\n if (schema.required) {\n schema.required.forEach((field) => allRequired.add(field));\n }\n }\n\n if (allRequired.size > 0) {\n merged.required = Array.from(allRequired);\n }\n\n return merged;\n }\n\n /**\n * Create a union schema (oneOf)\n */\n static union(schemas: JsonSchema[]): JsonSchema {\n if (schemas.length === 0) {\n return {};\n }\n\n if (schemas.length === 1) {\n return schemas[0];\n }\n\n return {\n oneOf: schemas,\n };\n }\n\n /**\n * Deep clone a schema\n */\n static clone(schema: JsonSchema): JsonSchema {\n return JSON.parse(JSON.stringify(schema));\n }\n\n /**\n * Remove $ref from schema (assumes already dereferenced)\n */\n static removeRefs(schema: JsonSchema): JsonSchema {\n const cloned = this.clone(schema);\n this.removeRefsRecursive(cloned);\n return cloned;\n }\n\n private static removeRefsRecursive(obj: any): void {\n if (!obj || typeof obj !== 'object') return;\n\n if (obj.$ref) {\n delete obj.$ref;\n }\n\n for (const key in obj) {\n if (key in obj) {\n const value = obj[key];\n if (value && typeof value === 'object') {\n this.removeRefsRecursive(value);\n }\n }\n }\n }\n\n /**\n * Add description to schema\n */\n static withDescription(schema: JsonSchema, description: string): JsonSchema {\n return {\n ...schema,\n description,\n };\n }\n\n /**\n * Add example to schema\n */\n static withExample(schema: JsonSchema, example: any): JsonSchema {\n const existingExamples = Array.isArray(schema.examples) ? schema.examples : [];\n return {\n ...schema,\n examples: [...existingExamples, example],\n };\n }\n\n /**\n * Add default value to schema\n */\n static withDefault(schema: JsonSchema, defaultValue: any): JsonSchema {\n return {\n ...schema,\n default: defaultValue,\n };\n }\n\n /**\n * Add format to schema\n */\n static withFormat(schema: JsonSchema, format: string): JsonSchema {\n return {\n ...schema,\n format,\n };\n }\n\n /**\n * Add pattern to schema\n */\n static withPattern(schema: JsonSchema, pattern: string): JsonSchema {\n return {\n ...schema,\n pattern,\n };\n }\n\n /**\n * Add enum to schema\n */\n static withEnum(schema: JsonSchema, values: any[]): JsonSchema {\n return {\n ...schema,\n enum: values,\n };\n }\n\n /**\n * Add minimum/maximum constraints\n */\n static withRange(schema: JsonSchema, min?: number, max?: number, options: { exclusive?: boolean } = {}): JsonSchema {\n const result = { ...schema };\n\n if (min !== undefined) {\n if (options.exclusive) {\n result.exclusiveMinimum = min;\n } else {\n result.minimum = min;\n }\n }\n\n if (max !== undefined) {\n if (options.exclusive) {\n result.exclusiveMaximum = max;\n } else {\n result.maximum = max;\n }\n }\n\n return result;\n }\n\n /**\n * Add minLength/maxLength constraints\n */\n static withLength(schema: JsonSchema, minLength?: number, maxLength?: number): JsonSchema {\n const result = { ...schema };\n\n if (minLength !== undefined) {\n result.minLength = minLength;\n }\n\n if (maxLength !== undefined) {\n result.maxLength = maxLength;\n }\n\n return result;\n }\n\n /**\n * Create object schema\n */\n static object(properties: Record<string, JsonSchema>, required?: string[]): JsonSchema {\n return {\n type: 'object',\n properties,\n ...(required && required.length > 0 && { required }),\n additionalProperties: false,\n };\n }\n\n /**\n * Create array schema\n */\n static array(\n items: JsonSchema,\n constraints?: {\n minItems?: number;\n maxItems?: number;\n uniqueItems?: boolean;\n },\n ): JsonSchema {\n return {\n type: 'array',\n items,\n ...constraints,\n };\n }\n\n /**\n * Create string schema\n */\n static string(constraints?: {\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n format?: string;\n enum?: string[];\n }): JsonSchema {\n return {\n type: 'string',\n ...constraints,\n };\n }\n\n /**\n * Create number schema\n */\n static number(constraints?: {\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n multipleOf?: number;\n }): JsonSchema {\n return {\n type: 'number',\n ...constraints,\n };\n }\n\n /**\n * Create integer schema\n */\n static integer(constraints?: {\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number;\n exclusiveMaximum?: number;\n multipleOf?: number;\n }): JsonSchema {\n return {\n type: 'integer',\n ...constraints,\n };\n }\n\n /**\n * Create boolean schema\n */\n static boolean(): JsonSchema {\n return {\n type: 'boolean',\n };\n }\n\n /**\n * Create null schema\n */\n static null(): JsonSchema {\n return {\n type: 'null',\n };\n }\n\n /**\n * Flatten nested oneOf/anyOf/allOf schemas\n */\n static flatten(schema: JsonSchema, maxDepth = 10): JsonSchema {\n if (maxDepth <= 0) return schema;\n\n const cloned = this.clone(schema);\n\n if (cloned.oneOf) {\n const flattened = cloned.oneOf.flatMap((s) => {\n const sub = this.flatten(s as JsonSchema, maxDepth - 1);\n return sub.oneOf ? sub.oneOf : [sub];\n });\n cloned.oneOf = flattened as JsonSchema[];\n }\n\n if (cloned.anyOf) {\n const flattened = cloned.anyOf.flatMap((s) => {\n const sub = this.flatten(s as JsonSchema, maxDepth - 1);\n return sub.anyOf ? sub.anyOf : [sub];\n });\n cloned.anyOf = flattened as JsonSchema[];\n }\n\n if (cloned.allOf) {\n const flattened = cloned.allOf.flatMap((s) => {\n const sub = this.flatten(s as JsonSchema, maxDepth - 1);\n return sub.allOf ? sub.allOf : [sub];\n });\n cloned.allOf = flattened as JsonSchema[];\n }\n\n return cloned;\n }\n\n /**\n * Simplify schema by removing unnecessary fields\n */\n static simplify(schema: JsonSchema): JsonSchema {\n const cloned = this.clone(schema);\n\n // Remove empty arrays/objects\n if (Array.isArray(cloned.required) && cloned.required.length === 0) {\n delete cloned.required;\n }\n\n if (cloned.properties && Object.keys(cloned.properties).length === 0) {\n delete cloned.properties;\n }\n\n if (Array.isArray(cloned.examples) && cloned.examples.length === 0) {\n delete cloned.examples;\n }\n\n // Remove title if it matches description\n if (cloned.title && cloned.description && cloned.title === cloned.description) {\n delete cloned.title;\n }\n\n return cloned;\n }\n}\n"]}
|
package/src/security-resolver.js
DELETED
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SecurityResolver = void 0;
|
|
4
|
-
exports.createSecurityContext = createSecurityContext;
|
|
5
|
-
/**
|
|
6
|
-
* Security resolver that maps OpenAPI security requirements to actual auth values
|
|
7
|
-
*
|
|
8
|
-
* This helper handles security parameters from any OpenAPI spec, regardless of
|
|
9
|
-
* custom naming (BearerAuth, JWT, Authorization, etc.). It uses the mapper's
|
|
10
|
-
* security metadata to determine the auth type and format.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* // In FrontMCP
|
|
15
|
-
* const resolver = new SecurityResolver();
|
|
16
|
-
* const resolved = resolver.resolve(tool.mapper, {
|
|
17
|
-
* jwt: context.authInfo.jwt,
|
|
18
|
-
* apiKey: process.env.API_KEY
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* // Use resolved.headers in HTTP request
|
|
22
|
-
* fetch(url, { headers: { ...resolved.headers, ...otherHeaders } });
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* // Custom resolver for framework-specific auth
|
|
28
|
-
* const resolved = resolver.resolve(tool.mapper, {
|
|
29
|
-
* customResolver: (security) => {
|
|
30
|
-
* if (security.type === 'http' && security.httpScheme === 'bearer') {
|
|
31
|
-
* return myFramework.getAuthToken();
|
|
32
|
-
* }
|
|
33
|
-
* return undefined;
|
|
34
|
-
* }
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
class SecurityResolver {
|
|
39
|
-
/**
|
|
40
|
-
* Resolve security parameters from mapper entries
|
|
41
|
-
*
|
|
42
|
-
* @param mappers - Parameter mappers from the tool definition
|
|
43
|
-
* @param context - Security context with auth values or custom resolver
|
|
44
|
-
* @returns Resolved headers, query params, and cookies with auth applied
|
|
45
|
-
*/
|
|
46
|
-
async resolve(mappers, context) {
|
|
47
|
-
const resolved = {
|
|
48
|
-
headers: {},
|
|
49
|
-
query: {},
|
|
50
|
-
cookies: {},
|
|
51
|
-
};
|
|
52
|
-
// Add client certificate if available (for mTLS)
|
|
53
|
-
if (context.clientCertificate) {
|
|
54
|
-
resolved.clientCertificate = context.clientCertificate;
|
|
55
|
-
}
|
|
56
|
-
// Check if signature-based auth is needed
|
|
57
|
-
let requiresSignature = false;
|
|
58
|
-
let signatureScheme;
|
|
59
|
-
for (const mapper of mappers) {
|
|
60
|
-
// Skip non-security parameters
|
|
61
|
-
if (!mapper.security) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
// Check for signature-based auth
|
|
65
|
-
if (this.isSignatureBasedAuth(mapper.security)) {
|
|
66
|
-
requiresSignature = true;
|
|
67
|
-
signatureScheme = mapper.security.scheme;
|
|
68
|
-
// Signature will be added later by signRequest()
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
// Try to resolve the auth value
|
|
72
|
-
const authValue = await this.resolveAuthValue(mapper.security, context);
|
|
73
|
-
if (!authValue) {
|
|
74
|
-
// Auth value not available - skip this security requirement
|
|
75
|
-
// Framework may want to throw an error or log a warning
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
// Apply to the correct location
|
|
79
|
-
const headerName = mapper.key;
|
|
80
|
-
if (mapper.type === 'header') {
|
|
81
|
-
resolved.headers[headerName] = authValue;
|
|
82
|
-
}
|
|
83
|
-
else if (mapper.type === 'query') {
|
|
84
|
-
resolved.query[headerName] = authValue;
|
|
85
|
-
}
|
|
86
|
-
else if (mapper.type === 'cookie') {
|
|
87
|
-
resolved.cookies[headerName] = authValue;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Add context cookies if available
|
|
91
|
-
if (context.cookies) {
|
|
92
|
-
resolved.cookies = { ...resolved.cookies, ...context.cookies };
|
|
93
|
-
}
|
|
94
|
-
// Add signature metadata if needed
|
|
95
|
-
if (requiresSignature) {
|
|
96
|
-
resolved.requiresSignature = true;
|
|
97
|
-
resolved.signatureInfo = {
|
|
98
|
-
scheme: signatureScheme || 'unknown',
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return resolved;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Check if security scheme requires request signing
|
|
105
|
-
*/
|
|
106
|
-
isSignatureBasedAuth(security) {
|
|
107
|
-
// Check for schemes that typically require signing
|
|
108
|
-
const signatureSchemes = ['aws4', 'hmac', 'signature', 'hawk', 'custom-signature'];
|
|
109
|
-
return signatureSchemes.some(scheme => security.scheme.toLowerCase().includes(scheme));
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Resolve the actual auth value based on security type
|
|
113
|
-
*/
|
|
114
|
-
async resolveAuthValue(security, context) {
|
|
115
|
-
// Try custom resolver first
|
|
116
|
-
if (context.customResolver) {
|
|
117
|
-
const customValue = await context.customResolver(security);
|
|
118
|
-
if (customValue !== undefined) {
|
|
119
|
-
return customValue;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// Handle standard security types
|
|
123
|
-
if (security.type === 'http') {
|
|
124
|
-
return this.resolveHttpAuth(security, context);
|
|
125
|
-
}
|
|
126
|
-
else if (security.type === 'apiKey') {
|
|
127
|
-
return this.resolveApiKey(security, context);
|
|
128
|
-
}
|
|
129
|
-
else if (security.type === 'oauth2' || security.type === 'openIdConnect') {
|
|
130
|
-
return this.resolveOAuth2(security, context);
|
|
131
|
-
}
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Resolve HTTP authentication (bearer, basic, digest, etc.)
|
|
136
|
-
*/
|
|
137
|
-
resolveHttpAuth(security, context) {
|
|
138
|
-
const scheme = security.httpScheme?.toLowerCase() || 'bearer';
|
|
139
|
-
switch (scheme) {
|
|
140
|
-
case 'bearer':
|
|
141
|
-
return this.resolveBearerAuth(context);
|
|
142
|
-
case 'basic':
|
|
143
|
-
return this.resolveBasicAuth(context);
|
|
144
|
-
case 'digest':
|
|
145
|
-
return this.resolveDigestAuth(context);
|
|
146
|
-
case 'hoba':
|
|
147
|
-
case 'mutual':
|
|
148
|
-
case 'negotiate':
|
|
149
|
-
case 'vapid':
|
|
150
|
-
case 'scram':
|
|
151
|
-
// These schemes typically require custom implementation
|
|
152
|
-
// Try custom headers or signature generator
|
|
153
|
-
return this.resolveCustomHttpScheme(scheme, security, context);
|
|
154
|
-
default:
|
|
155
|
-
// Unknown scheme - try custom resolver
|
|
156
|
-
return undefined;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Resolve Bearer token authentication
|
|
161
|
-
*/
|
|
162
|
-
resolveBearerAuth(context) {
|
|
163
|
-
const token = context.jwt;
|
|
164
|
-
if (!token)
|
|
165
|
-
return undefined;
|
|
166
|
-
return `Bearer ${token}`;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Resolve Basic authentication
|
|
170
|
-
*/
|
|
171
|
-
resolveBasicAuth(context) {
|
|
172
|
-
const credentials = context.basic;
|
|
173
|
-
if (!credentials)
|
|
174
|
-
return undefined;
|
|
175
|
-
return `Basic ${credentials}`;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Resolve Digest authentication
|
|
179
|
-
*/
|
|
180
|
-
resolveDigestAuth(context) {
|
|
181
|
-
const digest = context.digest;
|
|
182
|
-
if (!digest)
|
|
183
|
-
return undefined;
|
|
184
|
-
// Build digest auth header
|
|
185
|
-
const parts = [
|
|
186
|
-
`username="${digest.username}"`,
|
|
187
|
-
digest.realm ? `realm="${digest.realm}"` : '',
|
|
188
|
-
digest.nonce ? `nonce="${digest.nonce}"` : '',
|
|
189
|
-
digest.uri ? `uri="${digest.uri}"` : '',
|
|
190
|
-
digest.response ? `response="${digest.response}"` : '',
|
|
191
|
-
digest.opaque ? `opaque="${digest.opaque}"` : '',
|
|
192
|
-
digest.qop ? `qop=${digest.qop}` : '',
|
|
193
|
-
digest.nc ? `nc=${digest.nc}` : '',
|
|
194
|
-
digest.cnonce ? `cnonce="${digest.cnonce}"` : '',
|
|
195
|
-
].filter(Boolean);
|
|
196
|
-
return `Digest ${parts.join(', ')}`;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Resolve custom HTTP authentication schemes
|
|
200
|
-
*/
|
|
201
|
-
resolveCustomHttpScheme(scheme, security, context) {
|
|
202
|
-
// Try custom headers first
|
|
203
|
-
const headerKey = security.apiKeyName || `X-${scheme.toUpperCase()}`;
|
|
204
|
-
if (context.customHeaders?.[headerKey]) {
|
|
205
|
-
return context.customHeaders[headerKey];
|
|
206
|
-
}
|
|
207
|
-
// Unknown scheme
|
|
208
|
-
return undefined;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Resolve API key authentication
|
|
212
|
-
*/
|
|
213
|
-
resolveApiKey(security, context) {
|
|
214
|
-
// Try named API keys first (for multiple keys)
|
|
215
|
-
if (context.apiKeys && security.apiKeyName) {
|
|
216
|
-
const key = context.apiKeys[security.apiKeyName];
|
|
217
|
-
if (key)
|
|
218
|
-
return key;
|
|
219
|
-
}
|
|
220
|
-
// Try custom headers (for proprietary auth headers like X-Custom-Auth)
|
|
221
|
-
if (context.customHeaders && security.apiKeyName) {
|
|
222
|
-
const header = context.customHeaders[security.apiKeyName];
|
|
223
|
-
if (header)
|
|
224
|
-
return header;
|
|
225
|
-
}
|
|
226
|
-
// Fall back to single apiKey (backward compatibility)
|
|
227
|
-
return context.apiKey;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Resolve OAuth2/OpenID Connect authentication
|
|
231
|
-
*/
|
|
232
|
-
resolveOAuth2(security, context) {
|
|
233
|
-
const token = context.oauth2Token;
|
|
234
|
-
if (!token)
|
|
235
|
-
return undefined;
|
|
236
|
-
// OAuth2 tokens are typically formatted as "Bearer {token}"
|
|
237
|
-
return `Bearer ${token}`;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Check if any security requirements are missing from context
|
|
241
|
-
*
|
|
242
|
-
* @param mappers - Parameter mappers from the tool definition
|
|
243
|
-
* @param context - Security context with auth values
|
|
244
|
-
* @returns Array of missing security scheme names
|
|
245
|
-
*/
|
|
246
|
-
async checkMissingSecurity(mappers, context) {
|
|
247
|
-
const missing = [];
|
|
248
|
-
for (const mapper of mappers) {
|
|
249
|
-
if (!mapper.security)
|
|
250
|
-
continue;
|
|
251
|
-
const authValue = await this.resolveAuthValue(mapper.security, context);
|
|
252
|
-
if (!authValue) {
|
|
253
|
-
missing.push(mapper.security.scheme);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return missing;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Sign a request for signature-based authentication
|
|
260
|
-
*
|
|
261
|
-
* Use this when resolved.requiresSignature is true.
|
|
262
|
-
* This method will call the signatureGenerator from context to sign the request.
|
|
263
|
-
*
|
|
264
|
-
* @param mappers - Parameter mappers from the tool definition
|
|
265
|
-
* @param signatureData - Request data to sign
|
|
266
|
-
* @param context - Security context with signature generator
|
|
267
|
-
* @returns Headers with signature added
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```typescript
|
|
271
|
-
* const resolved = resolver.resolve(tool.mapper, context);
|
|
272
|
-
* if (resolved.requiresSignature) {
|
|
273
|
-
* const signedHeaders = await resolver.signRequest(
|
|
274
|
-
* tool.mapper,
|
|
275
|
-
* { method: 'GET', url: 'https://api.example.com/data', headers: resolved.headers },
|
|
276
|
-
* context
|
|
277
|
-
* );
|
|
278
|
-
* // Use signedHeaders in request
|
|
279
|
-
* }
|
|
280
|
-
* ```
|
|
281
|
-
*/
|
|
282
|
-
async signRequest(mappers, signatureData, context) {
|
|
283
|
-
const headers = { ...signatureData.headers };
|
|
284
|
-
if (!context.signatureGenerator) {
|
|
285
|
-
throw new Error('Signature-based auth required but no signatureGenerator provided');
|
|
286
|
-
}
|
|
287
|
-
for (const mapper of mappers) {
|
|
288
|
-
if (!mapper.security || !this.isSignatureBasedAuth(mapper.security)) {
|
|
289
|
-
continue;
|
|
290
|
-
}
|
|
291
|
-
// Call signature generator
|
|
292
|
-
const signature = await context.signatureGenerator(signatureData, mapper.security);
|
|
293
|
-
// Add signature to appropriate location
|
|
294
|
-
if (mapper.type === 'header') {
|
|
295
|
-
headers[mapper.key] = signature;
|
|
296
|
-
}
|
|
297
|
-
// Note: Query/cookie signatures would be handled differently
|
|
298
|
-
}
|
|
299
|
-
return headers;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
exports.SecurityResolver = SecurityResolver;
|
|
303
|
-
/**
|
|
304
|
-
* Create a basic security context from common auth sources
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* ```typescript
|
|
308
|
-
* const context = createSecurityContext({
|
|
309
|
-
* jwt: process.env.JWT_TOKEN,
|
|
310
|
-
* apiKey: process.env.API_KEY
|
|
311
|
-
* });
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
function createSecurityContext(auth) {
|
|
315
|
-
return {
|
|
316
|
-
...auth,
|
|
317
|
-
jwt: auth.jwt,
|
|
318
|
-
basic: auth.basic,
|
|
319
|
-
apiKey: auth.apiKey,
|
|
320
|
-
oauth2Token: auth.oauth2Token,
|
|
321
|
-
customResolver: auth.customResolver,
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
//# sourceMappingURL=security-resolver.js.map
|