@ttoss/http-server-mcp-openapi 0.1.3 → 0.2.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/index.cjs +33 -18
- package/dist/index.d.cts +21 -3
- package/dist/index.d.mts +21 -3
- package/dist/index.mjs +33 -18
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -184,6 +184,34 @@ var getJsonSchemaType = schemaType => {
|
|
|
184
184
|
var sanitizeDescription = description => {
|
|
185
185
|
return (description || "").replace(/'/g, "\\'").replace(/\n/g, " ").trim();
|
|
186
186
|
};
|
|
187
|
+
/**
|
|
188
|
+
* Builds a single body/query property's `JsonSchemaProperty`. Split out of
|
|
189
|
+
* {@link buildInputSchema} to keep that function's size and branching down.
|
|
190
|
+
*/
|
|
191
|
+
var buildTypedProperty = param => {
|
|
192
|
+
const description = sanitizeDescription(param.description);
|
|
193
|
+
if (param.oneOf && param.oneOf.length > 0) return {
|
|
194
|
+
oneOf: param.oneOf,
|
|
195
|
+
description
|
|
196
|
+
};
|
|
197
|
+
if (param.anyOf && param.anyOf.length > 0) return {
|
|
198
|
+
anyOf: param.anyOf,
|
|
199
|
+
description
|
|
200
|
+
};
|
|
201
|
+
const jsonType = getJsonSchemaType(param.type);
|
|
202
|
+
const finalType = param.nullable === true ? [jsonType, "null"] : jsonType;
|
|
203
|
+
if (param.type === "array") return {
|
|
204
|
+
type: finalType,
|
|
205
|
+
items: param.items ? param.items : {
|
|
206
|
+
type: "string"
|
|
207
|
+
},
|
|
208
|
+
description
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
type: finalType,
|
|
212
|
+
description
|
|
213
|
+
};
|
|
214
|
+
};
|
|
187
215
|
var buildInputSchema = (pathParams, queryParams, bodyProps) => {
|
|
188
216
|
const allParams = [...pathParams, ...queryParams, ...bodyProps];
|
|
189
217
|
if (allParams.length === 0) return {
|
|
@@ -201,23 +229,7 @@ var buildInputSchema = (pathParams, queryParams, bodyProps) => {
|
|
|
201
229
|
return p.camelName;
|
|
202
230
|
})];
|
|
203
231
|
const properties = {};
|
|
204
|
-
for (const param of allParams)
|
|
205
|
-
const jsonType = getJsonSchemaType(param.type);
|
|
206
|
-
const description = sanitizeDescription(param.description);
|
|
207
|
-
if (param.type === "array") {
|
|
208
|
-
const itemsSchema = "items" in param && param.items ? param.items : {
|
|
209
|
-
type: "string"
|
|
210
|
-
};
|
|
211
|
-
properties[param.camelName] = {
|
|
212
|
-
type: "array",
|
|
213
|
-
items: itemsSchema,
|
|
214
|
-
description
|
|
215
|
-
};
|
|
216
|
-
} else properties[param.camelName] = {
|
|
217
|
-
type: jsonType,
|
|
218
|
-
description
|
|
219
|
-
};
|
|
220
|
-
} else properties[param.camelName] = {
|
|
232
|
+
for (const param of allParams) properties[param.camelName] = "type" in param ? buildTypedProperty(param) : {
|
|
221
233
|
type: "string",
|
|
222
234
|
description: ""
|
|
223
235
|
};
|
|
@@ -289,7 +301,10 @@ var extractBodyProps = args => {
|
|
|
289
301
|
description: typeof val.description === "string" ? val.description : "",
|
|
290
302
|
required: (bodySchema.required || []).includes(key),
|
|
291
303
|
type: typeof val.type === "string" ? val.type : "string",
|
|
292
|
-
items: val.items
|
|
304
|
+
items: val.items,
|
|
305
|
+
nullable: val.nullable === true,
|
|
306
|
+
oneOf: Array.isArray(val.oneOf) ? val.oneOf : void 0,
|
|
307
|
+
anyOf: Array.isArray(val.anyOf) ? val.anyOf : void 0
|
|
293
308
|
};
|
|
294
309
|
});
|
|
295
310
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -2,16 +2,28 @@
|
|
|
2
2
|
import { JsonObjectSchema, McpServer } from "@ttoss/http-server-mcp";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
|
+
/** The JSON Schema primitive types this generator can derive from an OpenAPI `type`. */
|
|
6
|
+
type JsonSchemaPrimitiveType = 'string' | 'number' | 'boolean' | 'array' | 'integer' | 'object' | 'null';
|
|
5
7
|
/**
|
|
6
8
|
* A single JSON Schema property descriptor as emitted for a tool's
|
|
7
9
|
* `inputSchema`. Only the subset of JSON Schema the generator produces is
|
|
8
10
|
* modelled here; the value is forwarded verbatim over the MCP wire protocol.
|
|
11
|
+
*
|
|
12
|
+
* A property with OpenAPI `oneOf`/`anyOf` is forwarded as-is (no `type`) so a
|
|
13
|
+
* client-side validator enforces the same alternatives the REST API does,
|
|
14
|
+
* rather than collapsing to a single guessed primitive. `type` may be an
|
|
15
|
+
* array of two entries (e.g. `['string', 'null']`) to represent an OpenAPI
|
|
16
|
+
* `nullable: true` property without losing its declared type.
|
|
9
17
|
*/
|
|
10
|
-
|
|
11
|
-
type:
|
|
18
|
+
type JsonSchemaProperty = {
|
|
19
|
+
type: JsonSchemaPrimitiveType | JsonSchemaPrimitiveType[];
|
|
12
20
|
description?: string;
|
|
13
21
|
items?: unknown;
|
|
14
|
-
}
|
|
22
|
+
} | {
|
|
23
|
+
oneOf?: unknown[];
|
|
24
|
+
anyOf?: unknown[];
|
|
25
|
+
description?: string;
|
|
26
|
+
};
|
|
15
27
|
/**
|
|
16
28
|
* A REST-backed MCP tool derived from a single OpenAPI operation.
|
|
17
29
|
*
|
|
@@ -256,6 +268,9 @@ declare const buildInputSchema: (pathParams: Array<{
|
|
|
256
268
|
required: boolean;
|
|
257
269
|
type: string;
|
|
258
270
|
items?: unknown;
|
|
271
|
+
nullable?: boolean;
|
|
272
|
+
oneOf?: unknown[];
|
|
273
|
+
anyOf?: unknown[];
|
|
259
274
|
}>) => JsonObjectSchema;
|
|
260
275
|
declare const extractPathParams: (args: {
|
|
261
276
|
parameters?: Array<{
|
|
@@ -301,6 +316,9 @@ declare const extractBodyProps: (args: {
|
|
|
301
316
|
required: boolean;
|
|
302
317
|
type: string;
|
|
303
318
|
items?: unknown;
|
|
319
|
+
nullable: boolean;
|
|
320
|
+
oneOf?: unknown[];
|
|
321
|
+
anyOf?: unknown[];
|
|
304
322
|
}>;
|
|
305
323
|
declare const processOperation: (args: {
|
|
306
324
|
pathTemplate: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -2,16 +2,28 @@
|
|
|
2
2
|
import { JsonObjectSchema, McpServer } from "@ttoss/http-server-mcp";
|
|
3
3
|
|
|
4
4
|
//#region src/types.d.ts
|
|
5
|
+
/** The JSON Schema primitive types this generator can derive from an OpenAPI `type`. */
|
|
6
|
+
type JsonSchemaPrimitiveType = 'string' | 'number' | 'boolean' | 'array' | 'integer' | 'object' | 'null';
|
|
5
7
|
/**
|
|
6
8
|
* A single JSON Schema property descriptor as emitted for a tool's
|
|
7
9
|
* `inputSchema`. Only the subset of JSON Schema the generator produces is
|
|
8
10
|
* modelled here; the value is forwarded verbatim over the MCP wire protocol.
|
|
11
|
+
*
|
|
12
|
+
* A property with OpenAPI `oneOf`/`anyOf` is forwarded as-is (no `type`) so a
|
|
13
|
+
* client-side validator enforces the same alternatives the REST API does,
|
|
14
|
+
* rather than collapsing to a single guessed primitive. `type` may be an
|
|
15
|
+
* array of two entries (e.g. `['string', 'null']`) to represent an OpenAPI
|
|
16
|
+
* `nullable: true` property without losing its declared type.
|
|
9
17
|
*/
|
|
10
|
-
|
|
11
|
-
type:
|
|
18
|
+
type JsonSchemaProperty = {
|
|
19
|
+
type: JsonSchemaPrimitiveType | JsonSchemaPrimitiveType[];
|
|
12
20
|
description?: string;
|
|
13
21
|
items?: unknown;
|
|
14
|
-
}
|
|
22
|
+
} | {
|
|
23
|
+
oneOf?: unknown[];
|
|
24
|
+
anyOf?: unknown[];
|
|
25
|
+
description?: string;
|
|
26
|
+
};
|
|
15
27
|
/**
|
|
16
28
|
* A REST-backed MCP tool derived from a single OpenAPI operation.
|
|
17
29
|
*
|
|
@@ -256,6 +268,9 @@ declare const buildInputSchema: (pathParams: Array<{
|
|
|
256
268
|
required: boolean;
|
|
257
269
|
type: string;
|
|
258
270
|
items?: unknown;
|
|
271
|
+
nullable?: boolean;
|
|
272
|
+
oneOf?: unknown[];
|
|
273
|
+
anyOf?: unknown[];
|
|
259
274
|
}>) => JsonObjectSchema;
|
|
260
275
|
declare const extractPathParams: (args: {
|
|
261
276
|
parameters?: Array<{
|
|
@@ -301,6 +316,9 @@ declare const extractBodyProps: (args: {
|
|
|
301
316
|
required: boolean;
|
|
302
317
|
type: string;
|
|
303
318
|
items?: unknown;
|
|
319
|
+
nullable: boolean;
|
|
320
|
+
oneOf?: unknown[];
|
|
321
|
+
anyOf?: unknown[];
|
|
304
322
|
}>;
|
|
305
323
|
declare const processOperation: (args: {
|
|
306
324
|
pathTemplate: string;
|
package/dist/index.mjs
CHANGED
|
@@ -181,6 +181,34 @@ var getJsonSchemaType = schemaType => {
|
|
|
181
181
|
var sanitizeDescription = description => {
|
|
182
182
|
return (description || "").replace(/'/g, "\\'").replace(/\n/g, " ").trim();
|
|
183
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* Builds a single body/query property's `JsonSchemaProperty`. Split out of
|
|
186
|
+
* {@link buildInputSchema} to keep that function's size and branching down.
|
|
187
|
+
*/
|
|
188
|
+
var buildTypedProperty = param => {
|
|
189
|
+
const description = sanitizeDescription(param.description);
|
|
190
|
+
if (param.oneOf && param.oneOf.length > 0) return {
|
|
191
|
+
oneOf: param.oneOf,
|
|
192
|
+
description
|
|
193
|
+
};
|
|
194
|
+
if (param.anyOf && param.anyOf.length > 0) return {
|
|
195
|
+
anyOf: param.anyOf,
|
|
196
|
+
description
|
|
197
|
+
};
|
|
198
|
+
const jsonType = getJsonSchemaType(param.type);
|
|
199
|
+
const finalType = param.nullable === true ? [jsonType, "null"] : jsonType;
|
|
200
|
+
if (param.type === "array") return {
|
|
201
|
+
type: finalType,
|
|
202
|
+
items: param.items ? param.items : {
|
|
203
|
+
type: "string"
|
|
204
|
+
},
|
|
205
|
+
description
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
type: finalType,
|
|
209
|
+
description
|
|
210
|
+
};
|
|
211
|
+
};
|
|
184
212
|
var buildInputSchema = (pathParams, queryParams, bodyProps) => {
|
|
185
213
|
const allParams = [...pathParams, ...queryParams, ...bodyProps];
|
|
186
214
|
if (allParams.length === 0) return {
|
|
@@ -198,23 +226,7 @@ var buildInputSchema = (pathParams, queryParams, bodyProps) => {
|
|
|
198
226
|
return p.camelName;
|
|
199
227
|
})];
|
|
200
228
|
const properties = {};
|
|
201
|
-
for (const param of allParams)
|
|
202
|
-
const jsonType = getJsonSchemaType(param.type);
|
|
203
|
-
const description = sanitizeDescription(param.description);
|
|
204
|
-
if (param.type === "array") {
|
|
205
|
-
const itemsSchema = "items" in param && param.items ? param.items : {
|
|
206
|
-
type: "string"
|
|
207
|
-
};
|
|
208
|
-
properties[param.camelName] = {
|
|
209
|
-
type: "array",
|
|
210
|
-
items: itemsSchema,
|
|
211
|
-
description
|
|
212
|
-
};
|
|
213
|
-
} else properties[param.camelName] = {
|
|
214
|
-
type: jsonType,
|
|
215
|
-
description
|
|
216
|
-
};
|
|
217
|
-
} else properties[param.camelName] = {
|
|
229
|
+
for (const param of allParams) properties[param.camelName] = "type" in param ? buildTypedProperty(param) : {
|
|
218
230
|
type: "string",
|
|
219
231
|
description: ""
|
|
220
232
|
};
|
|
@@ -286,7 +298,10 @@ var extractBodyProps = args => {
|
|
|
286
298
|
description: typeof val.description === "string" ? val.description : "",
|
|
287
299
|
required: (bodySchema.required || []).includes(key),
|
|
288
300
|
type: typeof val.type === "string" ? val.type : "string",
|
|
289
|
-
items: val.items
|
|
301
|
+
items: val.items,
|
|
302
|
+
nullable: val.nullable === true,
|
|
303
|
+
oneOf: Array.isArray(val.oneOf) ? val.oneOf : void 0,
|
|
304
|
+
anyOf: Array.isArray(val.anyOf) ? val.anyOf : void 0
|
|
290
305
|
};
|
|
291
306
|
});
|
|
292
307
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/http-server-mcp-openapi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Generate Model Context Protocol (MCP) tools from an OpenAPI specification for @ttoss/http-server-mcp",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ttoss/http-server-mcp": "^0.
|
|
38
|
+
"@ttoss/http-server-mcp": "^0.24.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"jest": "^30.4.2",
|
|
42
42
|
"supertest": "^7.2.2",
|
|
43
43
|
"tsdown": "^0.22.2",
|
|
44
|
-
"@ttoss/
|
|
45
|
-
"@ttoss/
|
|
44
|
+
"@ttoss/config": "^1.37.17",
|
|
45
|
+
"@ttoss/http-server": "^0.7.1"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public",
|